-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·219 lines (183 loc) · 6.66 KB
/
install.sh
File metadata and controls
executable file
·219 lines (183 loc) · 6.66 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
#!/bin/bash
sudo -v
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/scripts/utils.sh" "$@"
PACMAN_PACKAGES=()
YAY_PACKAGES=()
MISE_PACKAGES=()
BUN_PACKAGES=()
VSCODE_EXTENSIONS=()
PRE_INSTALL_SCRIPTS=()
POST_INSTALL_SCRIPTS=()
for script in "$SCRIPT_DIR"/installs/*.sh; do
debug "Sourcing script: $script"
source "$script"
if declare -F pre_install > /dev/null; then
PRE_INSTALL_SCRIPTS+=("$script")
fi
if declare -F post_install > /dev/null; then
POST_INSTALL_SCRIPTS+=("$script")
fi
# Avoid conflict in the next iteration
unset -f pre_install 2>/dev/null || true
unset -f post_install 2>/dev/null || true
done
if [ "${#PRE_INSTALL_SCRIPTS[@]}" -gt 0 ]; then
log "Running pre-install scripts..."
for script in "${PRE_INSTALL_SCRIPTS[@]}"; do
log "Executing pre_install from $script"
source "$script"
execute pre_install >>"$LOG_FILE" 2>&1 || log "pre_install in $script failed."
unset -f pre_install 2>/dev/null || true
done
else
debug "No pre-install scripts to run."
fi
PACMAN_PACKAGES=($(printf "%s\n" "${PACMAN_PACKAGES[@]}" | sort -u))
PACMAN_PACKAGES_NOT_INSTALLED=()
for pkg in "${PACMAN_PACKAGES[@]}"; do
if [ "$UPDATE_MODE" = true ]; then
PACMAN_PACKAGES_NOT_INSTALLED+=("$pkg")
elif ! pacman -Q "$pkg" &>/dev/null; then
PACMAN_PACKAGES_NOT_INSTALLED+=("$pkg")
else
debug "Package '$pkg' is already installed. Skipping."
fi
done
if [ "${#PACMAN_PACKAGES_NOT_INSTALLED[@]}" -gt 0 ]; then
log "Installing Pacman packages: ${PACMAN_PACKAGES_NOT_INSTALLED[*]}"
execute sudo pacman -Sy --noconfirm --needed "${PACMAN_PACKAGES_NOT_INSTALLED[@]}" >>"$LOG_FILE" 2>&1 || log "Pacman installation failed."
else
log "No Pacman packages to install."
fi
YAY_PACKAGES=($(printf "%s\n" "${YAY_PACKAGES[@]}" | sort -u))
YAY_PACKAGES_NOT_INSTALLED=()
for pkg in "${YAY_PACKAGES[@]}"; do
if [ "$UPDATE_MODE" = true ]; then
YAY_PACKAGES_NOT_INSTALLED+=("$pkg")
elif ! yay -Q "$pkg" &>/dev/null; then
YAY_PACKAGES_NOT_INSTALLED+=("$pkg")
else
debug "Yay package '$pkg' is already installed. Skipping."
fi
done
if [ "${#YAY_PACKAGES_NOT_INSTALLED[@]}" -gt 0 ]; then
log "Installing Yay packages: ${YAY_PACKAGES_NOT_INSTALLED[*]}"
execute yay -Sy --noconfirm --needed "${YAY_PACKAGES_NOT_INSTALLED[@]}" >>"$LOG_FILE" 2>&1 || log "Yay installation failed."
else
log "No Yay packages to install."
fi
MISE_PACKAGES=($(printf "%s\n" "${MISE_PACKAGES[@]}" | sort -u))
MISE_PACKAGES_NOT_INSTALLED=()
for pkg in "${MISE_PACKAGES[@]}"; do
tool="${pkg%%@*}"
version="${pkg#*@}"
if [ "$UPDATE_MODE" = true ]; then
MISE_PACKAGES_NOT_INSTALLED+=("$pkg")
elif mise ls --json | jq -e --arg tool "$tool" --arg version "$version" '
.[$tool] // [] |
map(select(.requested_version == $version and .active == true)) |
length > 0
' &>/dev/null; then
debug "Package '$pkg' is already installed and active. Skipping."
else
MISE_PACKAGES_NOT_INSTALLED+=("$pkg")
fi
done
if [ "${#MISE_PACKAGES_NOT_INSTALLED[@]}" -gt 0 ]; then
log "Installing Mise packages: ${MISE_PACKAGES_NOT_INSTALLED[*]}"
execute mise use --global "${MISE_PACKAGES_NOT_INSTALLED[@]}" >>"$LOG_FILE" 2>&1 || log "Mise installation failed."
else
log "No Mise packages to install."
fi
GO_PACKAGES=($(printf "%s\n" "${GO_PACKAGES[@]}" | sort -u))
GO_PACKAGES_NOT_INSTALLED=()
for pkg in "${GO_PACKAGES[@]}"; do
# Extract the binary name from the package path. Ex: golang.org/x/tools/gopls -> gopls
binary_name="${pkg##*/}"
binary_name="${binary_name%%@*}"
if ! command -v go >/dev/null 2>&1; then
eval "$(mise activate bash)"
fi
# Check if the binary exists in GOPATH/bin or GOBIN
go_bin="${GOBIN:-$(go env GOPATH)/bin}"
if [ "$UPDATE_MODE" = true ]; then
GO_PACKAGES_NOT_INSTALLED+=("$pkg")
elif [ -f "$go_bin/$binary_name" ]; then
debug "Go tool '$binary_name' is already installed. Skipping."
else
GO_PACKAGES_NOT_INSTALLED+=("$pkg")
fi
done
if [ "${#GO_PACKAGES_NOT_INSTALLED[@]}" -gt 0 ]; then
log "Installing Go packages: ${GO_PACKAGES_NOT_INSTALLED[*]}"
for pkg in "${GO_PACKAGES_NOT_INSTALLED[@]}"; do
execute go install "$pkg" >>"$LOG_FILE" 2>&1 || log "Failed to install $pkg"
done
else
log "No Go packages to install."
fi
BUN_PACKAGES=($(printf "%s\n" "${BUN_PACKAGES[@]}" | sort -u))
BUN_PACKAGES_NOT_INSTALLED=()
for pkg in "${BUN_PACKAGES[@]}"; do
if [[ "$pkg" == @*/* ]]; then
# Scoped package: strip version after the second @
pkg_name="${pkg%@*}"
# If no version was specified, pkg_name equals pkg, which is fine
[[ "$pkg_name" == *"/"* ]] || pkg_name="$pkg"
else
pkg_name="${pkg%%@*}"
fi
if ! command -v bun >/dev/null 2>&1; then
eval "$(mise activate bash)"
fi
if [ "$UPDATE_MODE" = true ]; then
BUN_PACKAGES_NOT_INSTALLED+=("$pkg")
elif bun pm ls -g 2>/dev/null | grep -q "$pkg_name"; then
debug "Bun package '$pkg_name' is already installed. Skipping."
else
BUN_PACKAGES_NOT_INSTALLED+=("$pkg")
fi
done
if [ "${#BUN_PACKAGES_NOT_INSTALLED[@]}" -gt 0 ]; then
log "Installing Bun packages: ${BUN_PACKAGES_NOT_INSTALLED[*]}"
execute bun install --global "${BUN_PACKAGES_NOT_INSTALLED[@]}" >>"$LOG_FILE" 2>&1 || log "Bun installation failed."
else
log "No Bun packages to install."
fi
if command -v code &>/dev/null && [ "${#VSCODE_EXTENSIONS[@]}" -gt 0 ]; then
VSCODE_EXTENSIONS=($(printf "%s\n" "${VSCODE_EXTENSIONS[@]}" | sort -u))
INSTALLED_EXTENSIONS=$(code --list-extensions 2>/dev/null)
VSCODE_EXTENSIONS_NOT_INSTALLED=()
for ext in "${VSCODE_EXTENSIONS[@]}"; do
if [ "$UPDATE_MODE" = true ]; then
VSCODE_EXTENSIONS_NOT_INSTALLED+=("$ext")
elif echo "$INSTALLED_EXTENSIONS" | grep -qi "^${ext}$"; then
debug "VS Code extension '$ext' is already installed. Skipping."
else
VSCODE_EXTENSIONS_NOT_INSTALLED+=("$ext")
fi
done
if [ "${#VSCODE_EXTENSIONS_NOT_INSTALLED[@]}" -gt 0 ]; then
log "Installing VS Code extensions: ${VSCODE_EXTENSIONS_NOT_INSTALLED[*]}"
for ext in "${VSCODE_EXTENSIONS_NOT_INSTALLED[@]}"; do
execute code --install-extension "$ext" >>"$LOG_FILE" 2>&1 || log "Failed to install VS Code extension: $ext"
done
else
log "No VS Code extensions to install."
fi
else
debug "VS Code not found or no extensions to install. Skipping."
fi
if [ "${#POST_INSTALL_SCRIPTS[@]}" -gt 0 ]; then
log "Running post-install scripts..."
for script in "${POST_INSTALL_SCRIPTS[@]}"; do
log "Executing post_install from $script"
source "$script"
execute post_install >>"$LOG_FILE" 2>&1 || log "post_install in $script failed."
unset -f post_install 2>/dev/null || true
done
else
debug "No post-install scripts to run."
fi
log "Installation completed."