#!/usr/bin/env bash # Install tloto-deploy into /opt/tloto/bin and wire CI deploy SSH key. set -euo pipefail APP_DIR="${TLOTO_APP_DIR:-/home/deploy/games_app}" SRC="$APP_DIR/deploy/release/tloto-deploy.sh" sudo mkdir -p /opt/tloto/bin /var/lib/tloto/releases /var/lib/tloto/backups sudo cp "$SRC" /opt/tloto/bin/tloto-deploy sudo chmod 755 /opt/tloto/bin/tloto-deploy sudo chown deploy:deploy /opt/tloto/bin/tloto-deploy sudo chown -R deploy:deploy /var/lib/tloto # Restricted CI deploy key (Actions → SSH → tloto-deploy only) KEY_DIR="/home/deploy/gitea-deploy-ssh" mkdir -p "$KEY_DIR" chmod 700 "$KEY_DIR" if [[ ! -f "$KEY_DIR/id_ed25519" ]]; then ssh-keygen -t ed25519 -N "" -f "$KEY_DIR/id_ed25519" -C "gitea-actions-deploy" fi chmod 600 "$KEY_DIR/id_ed25519" AUTH="/home/deploy/.ssh/authorized_keys" mkdir -p /home/deploy/.ssh chmod 700 /home/deploy/.ssh MARKER="gitea-actions-deploy" if ! grep -q "$MARKER" "$AUTH" 2>/dev/null; then # ForceCommand limits this key to tloto-deploy (args passed after --) PUB="$(cat "$KEY_DIR/id_ed25519.pub")" echo "command=\"/opt/tloto/bin/tloto-deploy-ssh-wrapper\",no-port-forwarding,no-agent-forwarding,no-X11-forwarding,no-pty $PUB" >> "$AUTH" fi chmod 600 "$AUTH" sudo tee /opt/tloto/bin/tloto-deploy-ssh-wrapper >/dev/null <<'WRAP' #!/usr/bin/env bash set -euo pipefail # SSH forced command: only allow tloto-deploy with safe args from SSH_ORIGINAL_COMMAND cmd="${SSH_ORIGINAL_COMMAND:-}" if [[ -z "$cmd" ]]; then echo "tloto-deploy-ssh-wrapper: missing SSH_ORIGINAL_COMMAND" >&2 exit 1 fi # Must start with absolute path to tloto-deploy if [[ ! "$cmd" =~ ^/opt/tloto/bin/tloto-deploy([[:space:]]|$) ]]; then echo "refusing command: $cmd" >&2 exit 1 fi # Disallow shell metacharacters if [[ "$cmd" =~ [\;\&\|\<\>\`\$\(\)] ]]; then echo "refusing unsafe characters" >&2 exit 1 fi exec bash -lc "$cmd" WRAP sudo chmod 755 /opt/tloto/bin/tloto-deploy-ssh-wrapper # Convenience symlink for interactive deploy user sessions sudo ln -sfn /opt/tloto/bin/tloto-deploy /usr/local/bin/tloto-deploy echo "Installed /opt/tloto/bin/tloto-deploy" echo "CI private key: $KEY_DIR/id_ed25519 (add as Gitea secret DEPLOY_SSH_KEY)" echo "Suggested DEPLOY_SSH_HOST=172.16.0.1 (docker0) or 127.0.0.1 from host-network jobs"