Repository navigation
Expand file tree
/
Copy pathinstall-host.sh
More file actions
executable file
·240 lines (214 loc) · 9.74 KB
/
Copy pathinstall-host.sh
File metadata and controls
executable file
·240 lines (214 loc) · 9.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
#!/usr/bin/env bash
set -euo pipefail
set -E
_CURRENT_STEP="(startup)"
trap '_rc=$?; printf "INSTALL FAILED step=%s line=%s\n" "$_CURRENT_STEP" "$LINENO" >&2; exit "$_rc"' ERR
# ============================================================================
# AI Coding Base Setup — Host Installer (core only, no sudo)
# Thin-client profile for bare hosts: Claude Code + MCPs + managed dotfiles,
# without the container-only tooling (tmux build, codex/cursor, ssh-agent
# watch, playwright, infra audit, templates). See install.sh for the
# container/devbox profile.
# ============================================================================
# Microsoft's devcontainer universal images ship `/etc/profile` sourcing
# `/usr/local/nvs/nvs.sh` (and `/etc/bash.bashrc` sourcing `nvm.sh`), which
# `export -f` multi-line `nvs`/`nvsudo`/`nvm` bash functions. Some layer in
# the devpod/docker-exec/su chain truncates multi-line BASH_FUNC env values
# to one line — known issue, see VSCode #3928 and vscode-remote-release
# #9457. Every child bash that inherits the truncated env then errors with
# `syntax error: unexpected end of file` on import.
#
# Failed-import env vars can't be removed from inside bash:
# - `unset -f nvs` is a no-op because the function was never defined
# - `unset 'BASH_FUNC_nvs%%'` silently fails because `%%` is not a valid
# identifier, so bash refuses to unset it
# Only `env -u` at the process boundary actually strips them. Self-reexec.
if [[ "${_AICODINGSETUP_NVS_STRIPPED:-}" != 1 ]]; then
exec env -u 'BASH_FUNC_nvs%%' -u 'BASH_FUNC_nvsudo%%' -u 'BASH_FUNC_nvm%%' \
_AICODINGSETUP_NVS_STRIPPED=1 bash "$0" "$@"
fi
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
: "${AICODING_BLUEPRINT_CLONE:=$SCRIPT_DIR}"
export AICODING_BLUEPRINT_CLONE
# Host day-2 commands must not point into the throwaway tracking clone used by
# aicoding-install/aicoding-sync. Refresh a complete, durable runtime first,
# then re-exec this installer from it so every SCRIPT_DIR-derived CLI symlink
# survives /tmp cleanup and reboot. A tar stream preserves executable modes
# and includes dirty/untracked local-blueprint work exactly as supplied.
_install_host_durable_runtime() {
local source=$SCRIPT_DIR
local durable=${AICODING_HOST_BLUEPRINT_DIR:-$HOME/.local/share/aicoding/blueprint}
local source_real durable_real parent base stage backup exclude=()
source_real=$(realpath -m "$source") || return 1
durable_real=$(realpath -m "$durable") || return 1
[ "$source_real" != "$durable_real" ] || return 0
parent=$(dirname "$durable_real"); base=$(basename "$durable_real")
mkdir -p "$parent" || return 1
stage=$(mktemp -d "$parent/.${base}.stage.XXXXXX") || return 1
backup=$(mktemp -d "$parent/.${base}.old.XXXXXX") || { rm -rf -- "$stage"; return 1; }
rmdir -- "$backup" || { rm -rf -- "$stage"; return 1; }
case "$stage" in
"$parent"/."$base".stage.*) ;;
*) rmdir -- "$stage" 2>/dev/null || true; return 1 ;;
esac
case "$backup" in
"$parent"/."$base".old.*) ;;
*) rm -rf -- "$stage"; return 1 ;;
esac
# A deliberately broad source checkout can contain the durable destination
# (for example source=$HOME). Exclude it from the snapshot to prevent the
# old runtime or our staging directory recursively copying into itself.
# --anchored + the ./ prefix pin each pattern to the archive root: tar
# patterns are unanchored by default, and a bare --exclude=$rel would also
# silently drop every DEEPER path ending in the same suffix (a legitimate
# project/.runtime/blueprint elsewhere in the tree).
local nested rel
for nested in "$durable_real" "$stage" "$backup"; do
case "$nested/" in
"$source_real"/*)
rel=${nested#"$source_real"/}
exclude+=(--anchored "--exclude=./$rel")
;;
esac
done
if ! tar -C "$source_real" "${exclude[@]}" -cf - . | tar -C "$stage" -xf -; then
rm -rf -- "$stage"
return 1
fi
if [ -e "$durable_real" ] || [ -L "$durable_real" ]; then
mv -- "$durable_real" "$backup" || { rm -rf -- "$stage"; return 1; }
fi
if ! mv -- "$stage" "$durable_real"; then
{ [ -e "$backup" ] || [ -L "$backup" ]; } && mv -- "$backup" "$durable_real"
rm -rf -- "$stage"
return 1
fi
if [ -e "$backup" ] || [ -L "$backup" ]; then rm -rf -- "$backup"; fi
AICODING_HOST_BLUEPRINT_DIR=$durable_real
export AICODING_HOST_BLUEPRINT_DIR
}
# Sourcing install-host.sh is the library/test contract and stays side-effect
# free. Executing it always finishes from the durable runtime.
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
_install_host_durable_runtime
durable_runtime=${AICODING_HOST_BLUEPRINT_DIR:-$HOME/.local/share/aicoding/blueprint}
if [[ "$(realpath -m "$SCRIPT_DIR")" != "$(realpath -m "$durable_runtime")" ]]; then
exec env AICODING_BLUEPRINT_CLONE="$durable_runtime" \
AICODING_HOST_BLUEPRINT_DIR="$durable_runtime" \
bash "$durable_runtime/install-host.sh" "$@"
fi
fi
# Shared deployment library — used by both install.sh and aicoding-sync.
. "$SCRIPT_DIR/lib/blueprint-deploy.sh"
# Auth plumbing helpers (seed_github_known_host, credential helpers, …).
. "$SCRIPT_DIR/lib/sync.sh"
CLAUDE_DIR="$HOME/.claude"
SECRETS_DIR="$HOME/.aicodingsetup"
SECRETS_FILE="$SECRETS_DIR/.secrets.env"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
info() { echo -e "${BLUE}INFO:${NC} $*"; }
ok() { echo -e "${GREEN} OK:${NC} $*"; }
warn() { echo -e "${YELLOW}WARN:${NC} $*"; }
err() { echo -e "${RED}ERROR:${NC} $*"; }
header(){
_CURRENT_STEP="$*"
echo -e "\n${GREEN}=== $* ===${NC}"
}
# Host profile: inventories and day-2 sync branch on this. Exported before
# any lib call so the very first classify/deploy pass is host-shaped.
export AICODING_PROFILE=host
. "$SCRIPT_DIR/lib/provision.sh"
. "$SCRIPT_DIR/lib/provision-system.sh"
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then check_prerequisites_host; fi
. "$SCRIPT_DIR/lib/provision-secrets.sh"
. "$SCRIPT_DIR/lib/provision-managed-files.sh"
. "$SCRIPT_DIR/lib/provision-integrations.sh"
main() {
local persistent_provision_failed=0
local _AICODING_INITIAL_CONFIG_DEFERRED=0 _AICODING_PREPARATION_DEFERRED=0
local _AICODING_GUARDED_PROVISION_DEFERRED=0
local _AICODING_INSTALL_SHARED_LOCKS_READY=1
header "AI Coding Base Setup — host profile (core only)"
seed_github_known_host
aicoding_migrate_legacy_state
aicoding_stamp_write profile host
load_or_prompt_secrets
# Register the HTTPS credential helpers NOW, not just at sync time
# (_sync_plumbing): the wiki clone below and the first boot-sync both
# need them, and on a bare host nothing else has ever registered them
# (2026-08-12 Mint field failure: clone prompted for a username).
ensure_gh_credential_helper
ensure_gh_stored_auth
ensure_git_credential_file_fallback
_provision_recover_scheduler_locks
if ! aicoding_shared_locks_acquire_managed_roots; then
_AICODING_INSTALL_SHARED_LOCKS_READY=0
fi
ensure_claude_code
report_unmanaged
install_mcp_packages \
|| { warn "MCP package preparation failed"; persistent_provision_failed=1; }
if [[ "${AICODING_PERSISTENT_ENROLLMENT:-0}" == 1 ]]; then
aicoding_prepare_installed_config_tools </dev/null \
|| { warn "Tool update failed; dependent config will remain unchanged"; persistent_provision_failed=1; }
aicoding_prepare_exact_mcps --register-claude </dev/null \
|| { warn "Exact MCP preparation failed; dependent config will remain unchanged"; persistent_provision_failed=1; }
export AICODING_REQUIRE_UPDATE_RECEIPT=1
fi
install_claude_mcps \
|| { warn "Claude MCP provisioning failed"; persistent_provision_failed=1; }
ensure_claude_onboarding_state
install_claude_plugins \
|| { warn "Claude plugin provisioning failed"; persistent_provision_failed=1; }
install_aicoding_sync_symlink
install_aicoding_install_symlink
install_update_status_symlink
install_aicoding_auto_update_symlink
install_kanban_work_symlink
install_redact_transcript_symlink
install_redact_sessions_symlinks
install_aicoding_root_install_symlink
remove_deprecated_shims
install_managed_config \
|| { warn "Managed config could not be fully written"; persistent_provision_failed=1; }
ensure_codex_managed_hooks
install_bubblewrap \
|| { warn "bw-AICode provisioning failed"; persistent_provision_failed=1; }
ensure_homelab_wiki
ensure_aicoding_auto_update
if [[ "$persistent_provision_failed" == 1 ]]; then
command -v aicoding_result_record >/dev/null 2>&1 \
&& aicoding_result_record provision failed "$(_aicoding_managed_source_version "$SCRIPT_DIR")" partial_provision_failure || true
header "Incomplete"
warn "Required provisioning is incomplete; a scheduled pass will retry"
return 1
elif [[ "${_AICODING_INITIAL_CONFIG_DEFERRED:-0}" == 1 \
|| "${_AICODING_GUARDED_PROVISION_DEFERRED:-0}" == 1 \
|| ( "${AICODING_PERSISTENT_ENROLLMENT:-0}" == 1 \
&& "${_AICODING_PREPARATION_DEFERRED:-0}" == 1 ) ]]; then
command -v aicoding_result_record >/dev/null 2>&1 \
&& aicoding_result_record provision blocked "$(_aicoding_managed_source_version "$SCRIPT_DIR")" preparation_deferred || true
if [[ "${AICODING_PERSISTENT_ENROLLMENT:-0}" == 1 ]]; then
header "Enrolled with deferrals"
info "Runtime enrollment succeeded; some tool or configuration changes were deferred"
else
header "Completed with deferrals"
info "Some tool or configuration changes were deferred"
fi
_print_install_summary DEFERRED
return 0
else
aicoding_stamp_write provision_commit "$(_aicoding_managed_source_version "$SCRIPT_DIR")"
fi
header "Done!"
info "Profile: host"
info "Secrets: $SECRETS_FILE"
info "Claude Code: $CLAUDE_DIR"
_print_install_summary
}
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then main "$@"; fi