diff options
| author | yyamashita <yyamashita@hetzner.yyamashita.com> | 2026-05-17 11:09:01 +0900 |
|---|---|---|
| committer | yyamashita <yyamashita@hetzner.yyamashita.com> | 2026-05-17 11:09:01 +0900 |
| commit | cc62d128021ed393f190560297ffaa4a2c259290 (patch) | |
| tree | bbfc4bab499db0770b0b37fdad39031dcd7ab75c /scripts | |
| parent | b836174d5ad5e4ea36a5f456061a00862317375f (diff) | |
Manage all server-side git hooks in this repository
Add server-hooks/<repo>/post-receive for all repos and
scripts/install-hooks.sh to deploy them manually on the server.
Hooks are not auto-installed on git push for security.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/install-hooks.sh | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/scripts/install-hooks.sh b/scripts/install-hooks.sh new file mode 100755 index 0000000..c502496 --- /dev/null +++ b/scripts/install-hooks.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash +# サーバー上で root として手動実行する +# server-hooks/ の内容を /var/git/*/hooks/ に展開する +set -euo pipefail + +APP_DIR="$(cd "$(dirname "$0")/.." && pwd)" +HOOKS_SRC="$APP_DIR/server-hooks" + +if [[ "$(id -u)" -ne 0 ]]; then + echo "ERROR: root として実行してください" >&2 + exit 1 +fi + +for repo_src in "$HOOKS_SRC"/*/; do + repo_name="$(basename "$repo_src")" + git_hooks_dir="/var/git/${repo_name}.git/hooks" + + if [[ ! -d "$git_hooks_dir" ]]; then + echo "SKIP: $git_hooks_dir が存在しません ($repo_name)" + continue + fi + + for hook_file in "$repo_src"*; do + hook_name="$(basename "$hook_file")" + dst="$git_hooks_dir/$hook_name" + if diff -q "$hook_file" "$dst" >/dev/null 2>&1; then + echo " unchanged: $repo_name/$hook_name" + else + cp "$hook_file" "$dst" + chmod +x "$dst" + echo " installed: $repo_name/$hook_name" + fi + done +done + +echo "Done." |
