diff options
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/claude-daemon-setup.sh | 63 | ||||
| -rwxr-xr-x | scripts/install.sh | 62 | ||||
| -rw-r--r-- | scripts/server-setup.sh | 42 | ||||
| -rwxr-xr-x | scripts/sync-claude-services.sh | 70 |
4 files changed, 0 insertions, 237 deletions
diff --git a/scripts/claude-daemon-setup.sh b/scripts/claude-daemon-setup.sh deleted file mode 100644 index 0652e27..0000000 --- a/scripts/claude-daemon-setup.sh +++ /dev/null @@ -1,63 +0,0 @@ -#!/bin/bash -# Set up Claude Code remote-control daemons for each app repo (run as root on Hetzner VPS). -set -e - -# Install Claude Code if not present -if ! command -v claude &>/dev/null; then - npm install -g @anthropic-ai/claude-code -fi - -# Create non-root user for claude sessions (root is blocked by claude security policy) -if ! id claude-agent &>/dev/null; then - useradd -r -m -s /bin/bash claude-agent -fi -usermod -aG docker claude-agent -chown -R claude-agent:claude-agent /app - -# Copy credentials from root to claude-agent -cp /root/.claude.json /home/claude-agent/.claude.json -chown claude-agent:claude-agent /home/claude-agent/.claude.json - -declare -A REPOS=( - ["infra"]="/app/infra" - ["tokyo"]="/app" - ["whoisband"]="/app/whois-band" -) - -for NAME in "${!REPOS[@]}"; do - DIR="${REPOS[$NAME]}" - SERVICE="claude-${NAME}.service" - - cat > "/etc/systemd/system/${SERVICE}" << EOF -[Unit] -Description=Claude Code Remote Session - ${NAME} -After=network.target - -[Service] -Type=simple -User=claude-agent -WorkingDirectory=${DIR} -ExecStart=/usr/bin/script -q -c "claude --remote-control ${NAME}" /dev/null -Restart=always -RestartSec=15 -StandardOutput=journal -StandardError=journal - -[Install] -WantedBy=multi-user.target -EOF - - systemctl daemon-reload - systemctl enable "${SERVICE}" - systemctl restart "${SERVICE}" - echo "Started: ${SERVICE} (WorkingDirectory: ${DIR})" -done - -echo "" -echo "All Claude Code daemons running. Connect via https://claude.ai/code" -echo "" -echo "Useful commands:" -echo " systemctl status claude-infra" -echo " systemctl status claude-tokyo" -echo " systemctl status claude-whoisband" -echo " journalctl -u claude-tokyo -f" diff --git a/scripts/install.sh b/scripts/install.sh deleted file mode 100755 index 9f06489..0000000 --- a/scripts/install.sh +++ /dev/null @@ -1,62 +0,0 @@ -#!/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." diff --git a/scripts/server-setup.sh b/scripts/server-setup.sh deleted file mode 100644 index ca9a3f9..0000000 --- a/scripts/server-setup.sh +++ /dev/null @@ -1,42 +0,0 @@ -#!/bin/bash -# Run once on a fresh Hetzner VPS (as root). -# hetzner-infra のみブートストラップとして作成する。 -# 他のリポジトリは最初の push 後に install.sh が作成する。 -set -e - -REPO_DIR=/var/git/hetzner-infra.git -APP_DIR=/app/infra - -# Install Docker -curl -fsSL https://get.docker.com | sh - -# Create shared Docker network -docker network create web || true - -# hetzner-infra bare repo をブートストラップ -mkdir -p "$REPO_DIR" "$APP_DIR" -git init --bare "$REPO_DIR" - -# 最初の push を受け取るための最小限のフック(install.sh 実行後に上書きされる) -cat > "$REPO_DIR/hooks/post-receive" << 'HOOK' -#!/bin/bash -set -e -APP_DIR=/app/infra -GIT_WORK_TREE=$APP_DIR git checkout -f -cd $APP_DIR -docker network create web 2>/dev/null || true -docker compose up -d -docker compose exec -T caddy caddy reload --config /etc/caddy/Caddyfile 2>/dev/null || true -echo "Deploy complete: hetzner-infra" -if [ -f "$APP_DIR/scripts/sync-claude-services.sh" ]; then - bash "$APP_DIR/scripts/sync-claude-services.sh" -fi -HOOK -chmod +x "$REPO_DIR/hooks/post-receive" - -echo "" -echo "Next steps:" -echo " 1. git remote add origin root@<server-ip>:$REPO_DIR" -echo " 2. git push origin master" -echo " 3. ssh root@<server-ip> 'bash $APP_DIR/scripts/install.sh'" -echo " (他のリポジトリ作成 + 全フックの正式インストール)" diff --git a/scripts/sync-claude-services.sh b/scripts/sync-claude-services.sh deleted file mode 100755 index a9a76fb..0000000 --- a/scripts/sync-claude-services.sh +++ /dev/null @@ -1,70 +0,0 @@ -#!/usr/bin/env bash -# サーバー側で root として実行し、各ユーザーの Claude Code systemd user service を同期する -set -euo pipefail - -APP_DIR="$(cd "$(dirname "$0")/.." && pwd)" -TEMPLATE_SRC="$APP_DIR/systemd/user/claude-code@.service" -SESSIONS_FILE="$APP_DIR/claude-code-sessions.txt" - -# sessions.txt をパースして user -> repos のマップを構築 -declare -A user_repos - -while IFS= read -r line; do - [[ "$line" =~ ^#.*$ || -z "$line" ]] && continue - user="${line%%:*}" - repo="${line#*:}" - user_repos["$user"]+=" $repo" -done < "$SESSIONS_FILE" - -for user in "${!user_repos[@]}"; do - uid=$(id -u "$user" 2>/dev/null) || { echo "WARNING: user $user not found, skipping"; continue; } - runtime_dir="/run/user/$uid" - systemd_dir="/home/$user/.config/systemd/user" - - mkdir -p "$systemd_dir" - chown "$user:$user" "$systemd_dir" - - # テンプレートを更新(差分があれば) - if ! diff -q "$TEMPLATE_SRC" "$systemd_dir/claude-code@.service" >/dev/null 2>&1; then - echo "[$user] Updating claude-code@.service template" - cp "$TEMPLATE_SRC" "$systemd_dir/claude-code@.service" - chown "$user:$user" "$systemd_dir/claude-code@.service" - runuser -u "$user" -- env XDG_RUNTIME_DIR="$runtime_dir" DBUS_SESSION_BUS_ADDRESS="unix:path=$runtime_dir/bus" \ - systemctl --user daemon-reload - fi - - # sessions.txt で指定されたリポジトリを enable & start - desired=() - for repo in ${user_repos[$user]}; do - [[ -z "$repo" ]] && continue - desired+=("$repo") - repo_path="/home/$user/workspaces/repos/$repo" - if [[ ! -d "$repo_path" ]]; then - echo "[$user] WARNING: $repo_path not found, skipping $repo" - continue - fi - runuser -u "$user" -- env XDG_RUNTIME_DIR="$runtime_dir" DBUS_SESSION_BUS_ADDRESS="unix:path=$runtime_dir/bus" \ - systemctl --user enable "claude-code@${repo}.service" 2>/dev/null || true - if ! runuser -u "$user" -- env XDG_RUNTIME_DIR="$runtime_dir" DBUS_SESSION_BUS_ADDRESS="unix:path=$runtime_dir/bus" \ - systemctl --user is-active "claude-code@${repo}.service" >/dev/null 2>&1; then - echo "[$user] Starting claude-code@${repo}.service" - runuser -u "$user" -- env XDG_RUNTIME_DIR="$runtime_dir" DBUS_SESSION_BUS_ADDRESS="unix:path=$runtime_dir/bus" \ - systemctl --user start "claude-code@${repo}.service" || true - fi - done - - # sessions.txt にないが enabled になっているインスタンスを無効化 - while IFS= read -r unit; do - instance="${unit#claude-code@}" - instance="${instance%.service}" - if ! printf '%s\n' "${desired[@]}" | grep -qx "$instance"; then - echo "[$user] Disabling claude-code@${instance}.service (not in sessions.txt)" - runuser -u "$user" -- env XDG_RUNTIME_DIR="$runtime_dir" DBUS_SESSION_BUS_ADDRESS="unix:path=$runtime_dir/bus" \ - systemctl --user disable --now "claude-code@${instance}.service" || true - fi - done < <(runuser -u "$user" -- env XDG_RUNTIME_DIR="$runtime_dir" DBUS_SESSION_BUS_ADDRESS="unix:path=$runtime_dir/bus" \ - systemctl --user list-unit-files --plain --no-legend 'claude-code@*.service' 2>/dev/null \ - | awk '$2 == "enabled" {print $1}') -done - -echo "Claude Code session sync complete." |
