-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup.sh
310 lines (261 loc) · 9.78 KB
/
setup.sh
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
#!/bin/bash
#
# Setup script for GitHub development environment
# Installs and configures VS Code, VS Code Insiders, and GitHub tooling
#
# -----------------------------
# Constants and Variables
# -----------------------------
# Colors
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Emojis
CHECK="✅"
WARN="⚠️"
INFO="ℹ️"
ERROR="❌"
CONFIG_FILE="/workspaces/machine-setup/config.json"
# Load configuration from JSON file
VSCODE_THEME=$(jq -r '.vscode_theme' "$CONFIG_FILE")
vs_code_extensions=($(jq -r '.vs_code_extensions[]' "$CONFIG_FILE"))
gh_cli_extensions=($(jq -r '.gh_cli_extensions[]' "$CONFIG_FILE"))
# Update PWA sites loading to handle objects with name and url
mapfile -t PWA_NAMES < <(jq -r '.pwa_sites[].name' "$CONFIG_FILE")
mapfile -t PWA_URLS < <(jq -r '.pwa_sites[].url' "$CONFIG_FILE")
DEMO_SITES=($(jq -r '.demo_sites[]' "$CONFIG_FILE"))
VLC_SETTINGS=$(jq -r '.vlc_settings' "$CONFIG_FILE")
# -----------------------------
# Function Definitions
# -----------------------------
# Checks if Visual Studio Code is installed by verifying the application directory exists
check_vscode() {
if [ -d "/Applications/Visual Studio Code.app" ]; then
echo -e "${GREEN}${CHECK} VS Code is already installed${NC}"
return 0
else
return 1
fi
}
# Checks if Visual Studio Code Insiders is installed by verifying the application directory exists
check_vscode_insiders() {
if [ -d "/Applications/Visual Studio Code - Insiders.app" ]; then
echo -e "${GREEN}${CHECK} VS Code Insiders is already installed${NC}"
return 0
else
return 1
fi
}
# Configures VLC settings to hide filename display and enable loop by default
configure_vlc_settings() {
echo -e "${BLUE}${INFO} Configuring VLC settings...${NC}"
PREF_FILE="$HOME/Library/Preferences/org.videolan.vlc/vlcrc"
mkdir -p "$(dirname "$PREF_FILE")"
# Check if we've already configured settings
if grep -q "# Setup-script-configured=true" "$PREF_FILE" 2>/dev/null; then
echo -e "${BLUE}${INFO} VLC settings already configured, skipping...${NC}"
return
fi
# Kill VLC if running
killall VLC 2>/dev/null || true
# Add our sentinel and settings
{
echo "# Setup-script-configured=true"
echo "$VLC_SETTINGS"
} >> "$PREF_FILE"
echo -e "${GREEN}${CHECK} VLC settings configured - please restart VLC${NC}"
}
# Installs Homebrew if not present and updates it if already installed
install_brew() {
if ! command -v brew &> /dev/null; then
echo -e "${BLUE}${INFO} Installing Homebrew...${NC}"
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
else
echo -e "${GREEN}${CHECK} Homebrew is already installed${NC}"
fi
echo -e "${BLUE}${INFO} Updating Homebrew...${NC}"
brew update
}
# Installs GitHub CLI (gh) using Homebrew if not already installed
install_gh() {
if ! command -v gh &> /dev/null; then
echo -e "${BLUE}${INFO} Installing GitHub CLI...${NC}"
brew install gh
return 0
else
echo -e "${GREEN}${CHECK} GitHub CLI is already installed${NC}"
return 1
fi
}
# Installs a suite of GitHub CLI extensions for enhanced functionality
install_gh_extensions() {
echo -e "${BLUE}${INFO} Installing GitHub CLI extensions...${NC}"
for ext in "${gh_cli_extensions[@]}"
do
gh extension install "$ext"
done
}
# Installs VLC media player using Homebrew
install_vlc() {
echo -e "${BLUE}${INFO} Installing VLC media player...${NC}"
brew install --cask vlc
}
# Installs Visual Studio Code using Homebrew if not already present
install_vscode() {
if ! check_vscode; then
echo -e "${BLUE}${INFO} Installing VS Code...${NC}"
brew install --cask visual-studio-code
return 0
fi
return 1
}
# Installs predefined VS Code extensions using the VS Code CLI
install_vscode_extensions() {
echo -e "${BLUE}${INFO} Installing VS Code extensions...${NC}"
if ! "/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code" --version &> /dev/null; then
echo -e "${RED}${ERROR} Error: VS Code binary not found${NC}"
return 1
fi
for ext in "${vs_code_extensions[@]}"
do
"/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code" --install-extension "$ext"
done
}
# Installs Visual Studio Code Insiders using Homebrew if not already present
install_vscode_insiders() {
if ! check_vscode_insiders; then
echo -e "${BLUE}${INFO} Installing VS Code Insiders...${NC}"
brew install --cask visual-studio-code-insiders
return 0
fi
return 1
}
# Installs predefined VS Code extensions for VS Code Insiders
install_vscode_insiders_extensions() {
echo -e "${BLUE}${INFO} Installing VS Code Insiders extensions...${NC}"
if ! "/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/bin/code" --version &> /dev/null; then
echo -e "${RED}${ERROR} Error: VS Code Insiders binary not found${NC}"
return 1
fi
for ext in "${vs_code_extensions[@]}"
do
"/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/bin/code" --install-extension "$ext"
done
}
# Ensures user is authenticated with GitHub CLI and installs extensions if authenticated
setup_gh_auth() {
if command -v gh &> /dev/null; then
if ! gh auth status &> /dev/null; then
echo -e "${BLUE}${INFO} Please login to GitHub CLI first...${NC}"
gh auth login
fi
if gh auth status &> /dev/null; then
# install_gh_extensions
echo -e "${GREEN}${CHECK} GitHub CLI extensions installed${NC}"
else
echo -e "${WARN} GitHub CLI login required for installing extensions. Please run 'gh auth login' manually.${NC}"
fi
fi
}
# Guides user through GitHub web authentication process using Safari
setup_github_web_auth() {
echo -e "${BLUE}${INFO} Opening GitHub.com in Safari...${NC}"
open -a Safari https://github.com
echo -e "${BLUE}${INFO} Please log in to GitHub.com in Safari with the demo account${NC}"
echo -e "${BLUE}${INFO} Press Enter once you have logged in...${NC}"
read -r
echo -e "${GREEN}${CHECK} GitHub web authentication confirmed${NC}"
}
# Assists user in setting up Progressive Web Apps (PWAs) for GitHub tools
setup_safari_and_pwas() {
echo -e "${BLUE}${INFO} Opening required websites in Safari...${NC}"
for i in "${!PWA_URLS[@]}"; do
open -a Safari "${PWA_URLS[$i]}"
echo -e "${BLUE}${INFO} Please manually add ${PWA_NAMES[$i]} (${PWA_URLS[$i]}) as a PWA by:${NC}"
echo -e "${BLUE}${INFO} 1. Click Share button in Safari${NC}"
echo -e "${BLUE}${INFO} 2. Select 'Add to Dock'${NC}"
echo -e "${BLUE}${INFO} Press Enter when done...${NC}"
read -r
done
}
# Sets the VS Code theme to the predefined value
set_vscode_theme() {
echo -e "${BLUE}${INFO} Setting VS Code theme...${NC}"
VSCODE_SETTINGS="$HOME/Library/Application Support/Code/User/settings.json"
mkdir -p "$(dirname "$VSCODE_SETTINGS")"
if [ ! -f "$VSCODE_SETTINGS" ]; then
echo "{\"workbench.colorTheme\": \"$VSCODE_THEME\"}" > "$VSCODE_SETTINGS"
else
TMP_FILE=$(mktemp)
jq ". + {\"workbench.colorTheme\": \"$VSCODE_THEME\"}" "$VSCODE_SETTINGS" > "$TMP_FILE"
mv "$TMP_FILE" "$VSCODE_SETTINGS"
fi
}
# Sets the VS Code Insiders theme to the predefined value
set_vscode_insiders_theme() {
echo -e "${BLUE}${INFO} Setting VS Code Insiders theme...${NC}"
VSCODE_SETTINGS="$HOME/Library/Application Support/Code - Insiders/User/settings.json"
mkdir -p "$(dirname "$VSCODE_SETTINGS")"
if [ ! -f "$VSCODE_SETTINGS" ]; then
echo "{\"workbench.colorTheme\": \"$VSCODE_THEME\"}" > "$VSCODE_SETTINGS"
else
TMP_FILE=$(mktemp)
jq ". + {\"workbench.colorTheme\": \"$VSCODE_THEME\"}" "$VSCODE_SETTINGS" > "$TMP_FILE"
mv "$TMP_FILE" "$VSCODE_SETTINGS"
fi
}
# Creates a demo loader script to launch all required applications and sites
create_demo_loader() {
echo -e "${BLUE}${INFO} Creating demo loader script...${NC}"
DEMO_SCRIPT="$HOME/Desktop/load-demos.sh"
# Create the script header
cat > "$DEMO_SCRIPT" << 'EOF'
#!/bin/bash
EOF
# Add the sites dynamically
echo "# Open all required sites in Safari" >> "$DEMO_SCRIPT"
printf 'open -a Safari %s\n\n' "$(printf '"%s" ' "${DEMO_SITES[@]}")" >> "$DEMO_SCRIPT"
# Add the remaining standard content
cat >> "$DEMO_SCRIPT" << 'EOF'
# Open VS Code and VS Code Insiders
open -a "Visual Studio Code"
open -a "Visual Studio Code - Insiders"
# Open VLC pointing to Videos folder
open -a VLC "$HOME/Videos"
EOF
chmod +x "$DEMO_SCRIPT"
echo -e "${GREEN}${CHECK} Created demo loader script at $DEMO_SCRIPT${NC}"
}
# -----------------------------
# Main Execution
# -----------------------------
# Initial web authentication
setup_github_web_auth
# Install core tools
install_brew
install_vscode
install_vscode_insiders
install_gh
install_vlc
configure_vlc_settings
# Setup environments
setup_gh_auth
setup_safari_and_pwas
# Install extensions and configure themes
install_vscode_extensions
install_vscode_insiders_extensions
set_vscode_theme
set_vscode_insiders_theme
# Create demo loader script
create_demo_loader
# Verify installation
if [ -d "/Applications/Visual Studio Code.app" ] &&
[ -d "/Applications/Visual Studio Code - Insiders.app" ] &&
[ -d "/Applications/VLC.app" ] &&
command -v gh &> /dev/null; then
echo -e "${GREEN}${CHECK} Script completed successfully${NC}"
else
echo -e "${YELLOW}${WARN} There was an issue with the installation. Please check the error messages above.${NC}"
fi