From b6efad84b51c6df5f595683d66b855c75bddabc4 Mon Sep 17 00:00:00 2001 From: yyamashita Date: Sun, 17 May 2026 11:18:12 +0900 Subject: Centralize repo and hook management: add repos.txt and install.sh All bare repo creation is now driven by repos.txt in this repo. install.sh replaces install-hooks.sh and handles both repo creation and hook deployment. Other repos' server-setup.sh no longer manage bare repos or hooks. Co-Authored-By: Claude Sonnet 4.6 --- scripts/install.sh | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100755 scripts/install.sh (limited to 'scripts/install.sh') diff --git a/scripts/install.sh b/scripts/install.sh new file mode 100755 index 0000000..9f06489 --- /dev/null +++ b/scripts/install.sh @@ -0,0 +1,62 @@ +#!/usr/bin/env bash +# サーバー上で root として手動実行する +# repos.txt に基づいてベアリポジトリとワークツリーを作成し、 +# server-hooks/ のフックを /var/git/*/hooks/ に展開する +set -euo pipefail + +APP_DIR="$(cd "$(dirname "$0")/.." && pwd)" +REPOS_FILE="$APP_DIR/repos.txt" +HOOKS_SRC="$APP_DIR/server-hooks" + +if [[ "$(id -u)" -ne 0 ]]; then + echo "ERROR: root として実行してください" >&2 + exit 1 +fi + +# ベアリポジトリ・ワークツリー作成 +echo "=== Repositories ===" +while IFS=: read -r repo_name work_tree; do + [[ "$repo_name" =~ ^#.*$ || -z "$repo_name" ]] && continue + bare_repo="/var/git/${repo_name}.git" + + if [[ ! -d "$bare_repo" ]]; then + echo " create: $bare_repo" + mkdir -p "$bare_repo" + git init --bare "$bare_repo" + else + echo " exists: $bare_repo" + fi + + if [[ ! -d "$work_tree" ]]; then + echo " mkdir: $work_tree" + mkdir -p "$work_tree" + fi +done < "$REPOS_FILE" + +# フック展開 +echo "" +echo "=== Hooks ===" +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 not found ($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 "" +echo "Done." -- cgit v1.2.3