summaryrefslogtreecommitdiff
path: root/scripts/install-hooks.sh
blob: c50249600964204ca60ceaf5288b2bb71362b8ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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."