-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·148 lines (119 loc) · 4.53 KB
/
setup.sh
File metadata and controls
executable file
·148 lines (119 loc) · 4.53 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
#!/bin/bash
# ==============================================================================
# macOS Developer Setup Script
# Uses 'gum' for an interactive, glamorous CLI experience.
# ==============================================================================
# --- UI Helpers ---
print_header() {
if command -v gum &> /dev/null; then
gum style --foreground 212 --border-foreground 212 --border double --align center --width 50 "Setup Wizard"
else
echo "=================================================="
echo " Setup Wizard "
echo "=================================================="
fi
}
print_step() {
if command -v gum &> /dev/null; then
gum style --foreground 86 "➜ $1"
else
echo "➜ $1"
fi
}
# --- Bootstrapping ---
# Ensure Homebrew is installed
if ! command -v brew &> /dev/null; then
print_step "Homebrew not found. Installing..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Add brew to path for the rest of the script if it's the first install
eval "$(/opt/homebrew/bin/brew shellenv)"
fi
# Ensure Gum is installed
if ! command -v gum &> /dev/null; then
print_step "Installing 'gum' for interactive UI..."
brew install gum
fi
# --- Configuration ---
CONFIG_FILE="apps.conf"
# Helper to extract group names from apps.conf
get_groups() {
grep "^\[.*\]$" "$CONFIG_FILE" | sed 's/\[//;s/\]//'
}
# Helper to extract items for a specific group
get_items_for_group() {
local group="$1"
# Extracts lines between [group] and the next [section] or EOF, skipping empty lines
awk -v group="[$group]" '
$0 == group {flag=1; next}
/^\[.*\]$/ {flag=0}
flag && NF {print $0}
' "$CONFIG_FILE"
}
# --- Core Logic ---
install_group() {
local group_label="$1"
shift
local options=("$@")
# Check if options are empty
if [ ${#options[@]} -eq 0 ]; then return; fi
print_step "Setup $group_label"
# Prepare display names for gum
local display_names=()
for opt in "${options[@]}"; do
# Handle pipe-delimited format: "Display Name | id | type"
local dname=$(echo "$opt" | cut -d'|' -f1 | xargs)
display_names+=("$dname")
done
# User Selection using gum
local selections=$(printf "%s\n" "${display_names[@]}" | gum choose --no-limit --header "Select $group_label (Space: pick, Enter: confirm)")
if [ -z "$selections" ]; then
echo " (Skipped $group_label)"
return
fi
echo "Installing selections for $group_label..."
# Iterate through each user-selected display name using a dedicated file descriptor
while IFS= read -r selection <&3; do
if [ -z "$selection" ]; then continue; fi
# Match selection back to the original options to find brew ID and type
for opt in "${options[@]}"; do
local dname=$(echo "$opt" | cut -d'|' -f1 | xargs)
if [ "$selection" == "$dname" ]; then
local b_id=$(echo "$opt" | cut -d'|' -f2 | xargs)
local b_type=$(echo "$opt" | cut -d'|' -f3 | xargs)
# Check if already installed
if brew list --$b_type "$b_id" &>/dev/null; then
echo " ⠿ $selection is already installed."
break
fi
# Install using brew
gum spin --spinner dot --title "Installing $selection ($b_id)..." -- \
brew install $( [ "$b_type" == "cask" ] && echo "--cask" ) "$b_id" < /dev/null
if [ $? -eq 0 ]; then
echo " ✅ $selection installed."
else
echo " ❌ Failed to install $selection."
fi
break
fi
done
done 3<<< "$selections"
}
# --- Main Flow ---
clear
print_header
if [ ! -f "$CONFIG_FILE" ]; then
echo "Error: $CONFIG_FILE not found!"
exit 1
fi
# Dynamically load and run each group
while read -r group; do
[ -z "$group" ] && continue
# Load items for this group into an array
items=()
while read -r item; do
items+=("$item")
done < <(get_items_for_group "$group")
install_group "$group" "${items[@]}"
done < <(get_groups)
echo ""
gum style --foreground 212 --bold "✨ All done! Enjoy your new setup. ✨"