summaryrefslogtreecommitdiff
path: root/git/install.sh
diff options
context:
space:
mode:
authoryyamashita <yyamashita@hetzner.yyamashita.com>2026-05-17 11:29:27 +0900
committeryyamashita <yyamashita@hetzner.yyamashita.com>2026-05-17 11:29:27 +0900
commitef6dbdd2ac273dc4a01c70437ee7984cea9f2a3c (patch)
tree4db9e4917a3a2ffb4d96d02fd7927dd7dcaabf39 /git/install.sh
parentfa8880f38783bebbce805f8595c949b9c7f326a0 (diff)
Reorganize repo into caddy/, git/, claude/ directories
- caddy/: Caddyfile, docker-compose.yml, deploy.sh (hook runs this only) - git/: repos.txt, hooks/*/post-receive, install.sh, server-setup.sh - claude/: sessions.txt, systemd/claude-code@.service, sync.sh Post-receive hook is now: checkout + bash caddy/deploy.sh Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'git/install.sh')
-rwxr-xr-xgit/install.sh60
1 files changed, 60 insertions, 0 deletions
diff --git a/git/install.sh b/git/install.sh
new file mode 100755
index 0000000..12f561c
--- /dev/null
+++ b/git/install.sh
@@ -0,0 +1,60 @@
+#!/usr/bin/env bash
+# サーバー上で root として手動実行する
+# repos.txt に基づいてベアリポジトリとワークツリーを作成し、
+# git/hooks/ のフックを /var/git/*/hooks/ に展開する
+set -euo pipefail
+
+APP_DIR="$(cd "$(dirname "$0")/.." && pwd)"
+REPOS_FILE="$APP_DIR/git/repos.txt"
+HOOKS_SRC="$APP_DIR/git/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."