feat: deploy-to --run-setup flag to bootstrap directory structure on remote

This commit is contained in:
Kenji Morishige
2026-02-23 17:27:00 -06:00
parent 16cbadd016
commit 3860c8a33d

View File

@@ -883,12 +883,14 @@ cmd_remote_bootstrap() {
# COMMAND: deploy-to (push dotfiles to a server that can't reach Gitea) # COMMAND: deploy-to (push dotfiles to a server that can't reach Gitea)
# ----------------------------------------------------------------------- # -----------------------------------------------------------------------
cmd_deploy_to() { cmd_deploy_to() {
[ $# -ge 1 ] || die "Usage: deploy-to <user@host> [--scripts-only] [--include-ssh] [--no-backup] [--dry-run]" [ $# -ge 1 ] || die "Usage: deploy-to <user@host> [--scripts-only] [--include-ssh] [--no-backup] [--run-setup] [--profile work|personal] [--dry-run]"
local target="$1"; shift local target="$1"; shift
local scripts_only=false local scripts_only=false
local skip_ssh=true # default: skip .ssh/ — avoid pushing keys/config to servers local skip_ssh=true # default: skip .ssh/ — avoid pushing keys/config to servers
local no_backup=false local no_backup=false
local run_setup=false
local setup_profile="work" # default profile for servers
local dry_run=false local dry_run=false
while [[ $# -gt 0 ]]; do while [[ $# -gt 0 ]]; do
@@ -896,6 +898,8 @@ cmd_deploy_to() {
--scripts-only) scripts_only=true; shift ;; --scripts-only) scripts_only=true; shift ;;
--include-ssh) skip_ssh=false; shift ;; --include-ssh) skip_ssh=false; shift ;;
--no-backup) no_backup=true; shift ;; --no-backup) no_backup=true; shift ;;
--run-setup) run_setup=true; shift ;;
--profile) setup_profile="${2:-work}"; shift 2 ;;
--dry-run) dry_run=true; shift ;; --dry-run) dry_run=true; shift ;;
*) die "Unknown option: $1" ;; *) die "Unknown option: $1" ;;
esac esac
@@ -1076,6 +1080,26 @@ cmd_deploy_to() {
info "Create one to manage ~/.bashrc.local centrally: dotfiles/hosts/${remote_short}.bashrc.local" info "Create one to manage ~/.bashrc.local centrally: dotfiles/hosts/${remote_short}.bashrc.local"
fi fi
# ---- 6. Optionally run setup on the remote ----
if ! $dry_run; then
local do_setup=$run_setup
if ! $run_setup; then
echo
read -r -p "Run setup_enterprise_ai_bash.sh on $target now? Creates dirs, writes shell config. (y/n): " _ans
[[ "$_ans" == [yY] ]] && do_setup=true
fi
if $do_setup; then
echo
info "Running setup on $target (profile=$setup_profile)..."
info "This will create the directory structure and write shell config."
echo
ssh -t "$target" \
"MACHINE_PROFILE=${setup_profile} DOTFILES_REMOTE=${DOTFILES_REMOTE} bash ~/scripts/setup_enterprise_ai_bash.sh"
success "Setup complete on $target."
fi
fi
echo echo
if $dry_run; then if $dry_run; then
info "Dry run complete. Re-run without --dry-run to transfer files." info "Dry run complete. Re-run without --dry-run to transfer files."
@@ -1083,6 +1107,7 @@ cmd_deploy_to() {
bold "Deploy complete: $deployed file(s) deployed, $skipped skipped." bold "Deploy complete: $deployed file(s) deployed, $skipped skipped."
info "Files were copied directly (no symlinks). Re-run deploy-to to push updates." info "Files were copied directly (no symlinks). Re-run deploy-to to push updates."
$skip_ssh && info "~/.ssh/ was skipped. Use --include-ssh to also deploy ~/.ssh/config." $skip_ssh && info "~/.ssh/ was skipped. Use --include-ssh to also deploy ~/.ssh/config."
! $run_setup && info "Tip: add --run-setup to also create directories and shell config on the remote."
fi fi
} }
@@ -1114,13 +1139,16 @@ ${BOLD}COMMANDS — SSH & Keys${RESET}
${BOLD}COMMANDS — Multi-machine${RESET} ${BOLD}COMMANDS — Multi-machine${RESET}
remote-bootstrap <user@host> [--profile work|personal] remote-bootstrap <user@host> [--profile work|personal]
Upload scripts and run full setup on a remote machine Upload scripts and run full setup on a remote machine
deploy-to <user@host> [--scripts-only] [--include-ssh] [--no-backup] [--dry-run] deploy-to <user@host> [--scripts-only] [--include-ssh] [--no-backup] [--run-setup] [--profile work|personal] [--dry-run]
SCP tracked dotfiles + scripts directly to a server. SCP tracked dotfiles + scripts directly to a server.
Use when the server can't reach the Gitea repo. Use when the server can't reach the Gitea repo.
Backs up existing remote files locally before overwriting. Backs up existing remote files locally before overwriting.
--scripts-only Only push ~/scripts/, skip dotfiles --scripts-only Only push ~/scripts/, skip dotfiles
--include-ssh Also deploy ~/.ssh/config (skipped by default) --include-ssh Also deploy ~/.ssh/config (skipped by default)
--no-backup Skip the pre-deploy remote backup --no-backup Skip the pre-deploy remote backup
--run-setup Run setup_enterprise_ai_bash.sh on the remote
after deploy (creates dirs, shell config)
--profile work|personal Profile to pass to setup (default: work)
--dry-run Preview what would be transferred --dry-run Preview what would be transferred
${BOLD}QUICK START — this machine (work)${RESET} ${BOLD}QUICK START — this machine (work)${RESET}