-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·410 lines (346 loc) · 11.3 KB
/
install.sh
File metadata and controls
executable file
·410 lines (346 loc) · 11.3 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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
#!/usr/bin/env bash
set -euo pipefail
declare -rx SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
declare -rx SCRIPTS_DIR="$SCRIPT_DIR/scripts"
declare -rx LANG_DIR="$SCRIPT_DIR/lang"
# Colors (used before gum is available)
readonly YELLOW='\033[1;33m'
readonly GREEN='\033[0;32m'
readonly RESET='\033[0m'
# Theme (matches starship.toml palette)
readonly C_PINK="#ff7edb"
readonly C_LILAC="#b893ce"
readonly C_MINT="#72f1b8"
readonly C_YELLOW="#fede5d"
readonly C_CYAN="#03edf9"
readonly C_RED="#ff5555"
readonly C_DIM="#666666"
INSTALL_RESULTS=()
INSTALL_VERSIONS=()
INSTALL_ORDER=()
LANG_OVERRIDE=""
parse_args() {
while [[ $# -gt 0 ]]; do
case "$1" in
--lang) LANG_OVERRIDE="$2"; shift 2 ;;
--lang=*) LANG_OVERRIDE="${1#--lang=}"; shift ;;
*) shift ;;
esac
done
}
load_language() {
local lang_code="${LANG_OVERRIDE:-${LANG%%_*}}"
local lang_file="$LANG_DIR/${lang_code}.sh"
set -a
if [[ -f "$lang_file" ]]; then
# shellcheck source=/dev/null
source "$lang_file"
else
# shellcheck source=lang/en.sh
source "$LANG_DIR/en.sh"
fi
set +a
}
bootstrap_gum() {
command -v gum &>/dev/null && return
printf "${YELLOW}%s${RESET}\n" "$MSG_INSTALLING_GUM"
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://repo.charm.sh/apt/gpg.key \
| sudo gpg --dearmor -o /etc/apt/keyrings/charm.gpg 2>/dev/null
echo "deb [signed-by=/etc/apt/keyrings/charm.gpg] https://repo.charm.sh/apt/ * *" \
| sudo tee /etc/apt/sources.list.d/charm.list > /dev/null
sudo apt-get update -qq
sudo apt-get install -y gum
printf "${GREEN}%s${RESET}\n" "$MSG_GUM_INSTALLED"
}
show_logo() {
clear
printf '\033[38;2;255;255;255m'
cat << 'EOF'
██████████ █████████ █████
░░███░░░░███ ███░░░░░███ ░░███
░███ ░░███ ██████ █████ █████ ███ ░░░ ██████ ░███████ ██████ █████
░███ ░███ ███░░███░░███ ░░███ ░███ ███░░███ ░███░░███ ███░░███ ███░░
░███ ░███░███████ ░███ ░███ ░███ ░███ ░███ ░███ ░███░███ ░███░░█████
░███ ███ ░███░░░ ░░███ ███ ░░███ ███░███ ░███ ░███ ░███░███ ░███ ░░░░███
██████████ ░░██████ ░░█████ ░░█████████ ░░██████ ████████ ░░██████ ██████
░░░░░░░░░░ ░░░░░░ ░░░░░ ░░░░░░░░░ ░░░░░░ ░░░░░░░░ ░░░░░░ ░░░░░░
EOF
printf '\033[0m\n'
gum style \
--foreground "$C_LILAC" \
--align center --width 80 \
--margin "1 0" \
--border-foreground "$C_LILAC" \
--border double \
"$MSG_INSTALLER_SUBTITLE"
}
# Format: "id|Name|Description"
init_tools() {
TOOLS=(
"git|Git|$MSG_TOOL_GIT_DESC"
"zsh|Zsh + Starship|$MSG_TOOL_ZSH_DESC"
"node|Node.js (fnm)|$MSG_TOOL_NODE_DESC"
"docker|Docker|$MSG_TOOL_DOCKER_DESC"
"make|Make|$MSG_TOOL_MAKE_DESC"
"aws|AWS CLI|$MSG_TOOL_AWS_DESC"
"terraform|Terraform|$MSG_TOOL_TERRAFORM_DESC"
)
}
tool_id() { echo "${1}" | cut -d'|' -f1; }
tool_name() { echo "${1}" | cut -d'|' -f2; }
tool_desc() { echo "${1}" | cut -d'|' -f3; }
# Collect inputs in main shell to guarantee TTY access
collect_inputs_git() {
GIT_NAME=$(gum input \
--placeholder "$MSG_GIT_NAME_PLACEHOLDER" \
--prompt "$MSG_GIT_NAME_PROMPT" \
--prompt.foreground "$C_CYAN" \
--cursor.foreground "$C_LILAC" \
--width 50 \
--value "$(git config --global user.name 2>/dev/null || true)")
GIT_EMAIL=$(gum input \
--placeholder "$MSG_GIT_EMAIL_PLACEHOLDER" \
--prompt "$MSG_GIT_EMAIL_PROMPT" \
--prompt.foreground "$C_CYAN" \
--cursor.foreground "$C_LILAC" \
--width 50 \
--value "$(git config --global user.email 2>/dev/null || true)")
gum style --foreground "$C_DIM" " $GIT_NAME · $GIT_EMAIL"
export GIT_NAME GIT_EMAIL
}
collect_inputs_node() {
NODE_VERSION=$(gum choose \
--header "$MSG_NODE_VERSION_SELECT" \
--header.foreground "$C_CYAN" \
--cursor "→ " \
--cursor.foreground "$C_LILAC" \
--selected.foreground "$C_PINK" \
--item.foreground "$C_DIM" \
"24" "22" "20" "none")
if [[ "$NODE_VERSION" != "none" ]]; then
NODE_PKG_MANAGER=$(gum choose \
--header "$MSG_NODE_PKG_SELECT" \
--header.foreground "$C_CYAN" \
--cursor "→ " \
--cursor.foreground "$C_LILAC" \
--selected.foreground "$C_PINK" \
--item.foreground "$C_DIM" \
"npm" "pnpm" "yarn")
gum style --foreground "$C_DIM" " Node $NODE_VERSION · $NODE_PKG_MANAGER"
else
gum style --foreground "$C_DIM" " skip node installation"
fi
export NODE_VERSION NODE_PKG_MANAGER
}
collect_inputs_docker() {
if gum confirm \
--affirmative "$MSG_DOCKER_CONFIRM_YES" \
--negative "$MSG_DOCKER_CONFIRM_NO" \
--default=no \
" $MSG_DOCKER_EXPOSE_TCP"; then
DOCKER_EXPOSE_TCP="true"
else
DOCKER_EXPOSE_TCP="false"
fi
if [[ "$DOCKER_EXPOSE_TCP" == "true" ]]; then
gum style --foreground "$C_DIM" " TCP ports will be exposed to the host"
fi
export DOCKER_EXPOSE_TCP
}
collect_inputs() {
local fn="collect_inputs_${1}"
if declare -f "$fn" > /dev/null; then "$fn"; fi
}
extract_version() {
local id="$1" log_file="$2"
[[ -f "$log_file" ]] || { echo "--"; return; }
local ver
case "$id" in
git) ver=$(grep -oP 'git version \K[\d.]+' "$log_file" | tail -1) ;;
zsh) ver=$(grep -oP 'zsh \K[\d.]+' "$log_file" | tail -1) ;;
node) ver=$(grep -oP 'node v\K[\d.]+' "$log_file" | tail -1) ;;
docker) ver=$(grep -oP 'Docker version \K[\d.]+' "$log_file" | tail -1) ;;
make) ver=$(grep -oP 'GNU Make \K[\d.]+' "$log_file" | tail -1) ;;
aws) ver=$(grep -oP 'aws-cli/\K[\d.]+' "$log_file" | tail -1) ;;
terraform) ver=$(grep -oP 'Terraform v\K[\d.]+' "$log_file" | tail -1) ;;
*) ver="" ;;
esac
echo "${ver:---}"
}
run_install() {
local id="$1"
local name="$2"
local script="$SCRIPTS_DIR/${id}.sh"
if [[ ! -f "$script" ]]; then
gum style --foreground "$C_RED" " $MSG_SCRIPT_NOT_FOUND $script"
return 1
fi
echo ""
gum style --foreground "$C_PINK" --bold "▶ $name"
collect_inputs "$id"
local log_file="/tmp/devcobos_install_${id}.log"
if gum spin \
--spinner dot \
--spinner.foreground "$C_CYAN" \
--title " $MSG_INSTALLING $name..." \
--title.foreground "$C_LILAC" \
-- bash -c 'bash "$1" > "$2" 2>&1' _ "$script" "$log_file"; then
local version
version=$(extract_version "$id" "$log_file")
INSTALL_RESULTS+=("$name:success")
INSTALL_VERSIONS+=("$name:$version")
INSTALL_ORDER+=("$name")
gum style --foreground "$C_MINT" " ✓ $name $MSG_DONE"
else
INSTALL_RESULTS+=("$name:failed")
INSTALL_VERSIONS+=("$name:--")
INSTALL_ORDER+=("$name")
gum style --foreground "$C_RED" " ✗ $name $MSG_FAILED"
if [[ -f "$log_file" ]]; then
if gum confirm --default=no "$MSG_VIEW_FULL_LOG"; then
gum pager --border-foreground "$C_PINK" < "$log_file"
else
tail -3 "$log_file" | while IFS= read -r line; do
gum style --foreground "$C_DIM" " $line"
done
fi
fi
fi
rm -f "$log_file"
}
select_tools() {
local options=()
for tool in "${TOOLS[@]}"; do
options+=("$(tool_name "$tool") — $(tool_desc "$tool")")
done
gum choose --no-limit \
--header "$MSG_SELECT_HEADER" \
--header.foreground "$C_CYAN" \
--cursor "→ " \
--cursor.foreground "$C_LILAC" \
--selected.foreground "$C_PINK" \
--item.foreground "$C_DIM" \
--selected-prefix "◉ " \
--unselected-prefix "◯ " \
--height 11 \
"${options[@]}"
}
install_selected() {
local selected=("$@")
# Iterate TOOLS order to guarantee install sequence (e.g. zsh before node)
for tool in "${TOOLS[@]}"; do
local name
name="$(tool_name "$tool")"
for line in "${selected[@]}"; do
if [[ "${line%% —*}" == "$name" ]]; then
run_install "$(tool_id "$tool")" "$name"
break
fi
done
done
}
install_all() {
for tool in "${TOOLS[@]}"; do
run_install "$(tool_id "$tool")" "$(tool_name "$tool")"
done
}
main_menu() {
local opt_select="$MSG_MENU_SELECT"
local opt_all="$MSG_MENU_INSTALL_ALL"
local opt_exit="$MSG_MENU_EXIT"
while true; do
local choice
choice=$(gum choose \
--header "$MSG_MENU_HEADER"$'\n' \
--header.foreground "$C_CYAN" \
--cursor "→ " \
--cursor.foreground "$C_LILAC" \
--selected.foreground "$C_PINK" \
--item.foreground "$C_DIM" \
--height 6 \
"$opt_select" \
"$opt_all" \
"$opt_exit")
case "$choice" in
"$opt_select")
local selected
mapfile -t selected < <(select_tools)
if [[ ${#selected[@]} -eq 0 ]]; then
gum style --foreground "$C_YELLOW" " $MSG_NOTHING_SELECTED"
sleep 1
show_logo
continue
fi
install_selected "${selected[@]}"
break
;;
"$opt_all")
if gum confirm \
--affirmative "$MSG_DOCKER_CONFIRM_YES" \
--negative "$MSG_DOCKER_CONFIRM_NO" \
--default=yes \
" $MSG_CONFIRM_INSTALL_ALL"; then
install_all
break
else
show_logo
continue
fi
;;
"$opt_exit"|"")
echo ""
gum style --foreground "$C_PINK" " $MSG_BYE"
exit 0
;;
esac
done
}
show_summary() {
[[ ${#INSTALL_ORDER[@]} -eq 0 ]] && return
show_logo
local header
header=$(printf " %-2s %-20s %s" "" "$MSG_SUMMARY_TOOL" "$MSG_SUMMARY_VERSION")
local separator=" $(printf '%.0s─' {1..40})"
local lines=()
lines+=("$header")
lines+=("$separator")
for entry in "${INSTALL_ORDER[@]}"; do
local status="?" version="--"
for r in "${INSTALL_RESULTS[@]}"; do
if [[ "$r" == "$entry:success" ]]; then status="✓"; break
elif [[ "$r" == "$entry:failed" ]]; then status="✗"; break; fi
done
for v in "${INSTALL_VERSIONS[@]}"; do
[[ "$v" == "$entry:"* ]] && { version="${v#*:}"; break; }
done
lines+=("$(printf " %s %-20s %s" "$status" "$entry" "$version")")
done
local body
body=$(printf '%s\n' "${lines[@]}")
gum style \
--foreground "$C_MINT" \
--border-foreground "$C_PINK" \
--border rounded \
--align center \
--width 50 \
--padding "1 2" \
"$MSG_SUMMARY"
gum style \
--foreground "$C_MINT" \
--border-foreground "$C_PINK" \
--border rounded \
--width 50 \
--padding "1 2" \
"$body"
echo ""
}
parse_args "$@"
load_language
init_tools
bootstrap_gum
sudo apt-get update -qq
export APT_UPDATED=1
show_logo
main_menu
show_summary