-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinstall.sh
executable file
·455 lines (351 loc) · 12.2 KB
/
install.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
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
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
#!/usr/bin/env bash
#
# carch installation script
# installs, updates, or uninstall.
set -e
CARCH_VERSION="latest"
REPO_OWNER="harilvfs"
REPO_NAME="carch"
GITHUB_RELEASES_URL="https://github.com/${REPO_OWNER}/${REPO_NAME}/releases"
BINARY_NAME="carch"
INSTALL_DIR="/usr/local/bin"
MAN_DIR="/usr/local/share/man/man1"
ICON_DIR="/usr/share/icons/hicolor"
DESKTOP_FILE_PATH="/usr/share/applications/carch.desktop"
BASH_COMPLETION_DIR="/usr/share/bash-completion/completions"
ZSH_COMPLETION_DIR="/usr/share/zsh/site-functions"
FISH_COMPLETION_DIR="/usr/share/fish/vendor_completions.d"
CONFIG_DIR="${HOME}/.config/carch"
BOLD="$(tput bold 2>/dev/null || echo '')"
RED="$(tput setaf 1 2>/dev/null || echo '')"
GREEN="$(tput setaf 2 2>/dev/null || echo '')"
YELLOW="$(tput setaf 3 2>/dev/null || echo '')"
BLUE="$(tput setaf 4 2>/dev/null || echo '')"
RESET="$(tput sgr0 2>/dev/null || echo '')"
error() {
echo "${RED}${BOLD}ERROR:${RESET} $1" >&2
exit 1
}
info() {
echo "${BLUE}${BOLD}INFO:${RESET} $1"
}
success() {
echo "${GREEN}${BOLD}SUCCESS:${RESET} $1"
}
warning() {
echo "${YELLOW}${BOLD}WARNING:${RESET} $1"
}
command_exists() {
command -v "$1" >/dev/null 2>&1
}
check_dependencies() {
info "Checking dependencies..."
local deps=("curl" "grep" "tar" "fzf" "git" "wget" "man" "man-db")
local missing_deps=()
for dep in "${deps[@]}"; do
if ! command_exists "$dep"; then
missing_deps+=("$dep")
fi
done
if [ ${#missing_deps[@]} -gt 0 ]; then
echo "Please wait, installing required dependencies..."
if command_exists "pacman"; then
sudo pacman -Sy --noconfirm "${missing_deps[@]}" > /dev/null 2>&1
elif command_exists "dnf"; then
sudo dnf install -y "${missing_deps[@]}" > /dev/null 2>&1
else
error "Unsupported package manager. Please install the following dependencies manually: ${missing_deps[*]}"
fi
fi
}
detect_platform() {
info "Detecting platform..."
PLATFORM="$(uname -s)"
if [ "$PLATFORM" != "Linux" ]; then
error "Carch only supports Linux platforms. Detected: $PLATFORM"
fi
ARCH="$(uname -m)"
case "$ARCH" in
x86_64|amd64)
ARCH="x86_64"
;;
aarch64|arm64)
ARCH="aarch64"
;;
*)
error "Unsupported architecture: $ARCH"
;;
esac
info "Platform: Linux, Architecture: $ARCH"
}
install_binary() {
info "Installing carch binary..."
TMP_DIR="$(mktemp -d)"
trap 'rm -rf "$TMP_DIR"' EXIT INT TERM
if [ "$CARCH_VERSION" = "latest" ]; then
DOWNLOAD_URL="${GITHUB_RELEASES_URL}/latest/download"
else
DOWNLOAD_URL="${GITHUB_RELEASES_URL}/download/${CARCH_VERSION}"
fi
if [ "$ARCH" = "x86_64" ]; then
BINARY_URL="${DOWNLOAD_URL}/carch"
else
BINARY_URL="${DOWNLOAD_URL}/carch-${ARCH}"
fi
info "Downloading from: $BINARY_URL"
if ! curl -sSL "$BINARY_URL" -o "${TMP_DIR}/${BINARY_NAME}"; then
error "Failed to download carch binary"
fi
chmod +x "${TMP_DIR}/${BINARY_NAME}"
info "Moving binary to $INSTALL_DIR"
sudo mkdir -p "$INSTALL_DIR"
sudo mv "${TMP_DIR}/${BINARY_NAME}" "${INSTALL_DIR}/${BINARY_NAME}"
if [ -f "${INSTALL_DIR}/${BINARY_NAME}" ]; then
success "Carch binary installed successfully to ${INSTALL_DIR}/${BINARY_NAME}"
else
error "Failed to install carch binary"
fi
}
install_completions() {
info "Installing shell completions..."
TMP_DIR="$(mktemp -d)"
trap 'rm -rf "$TMP_DIR"' EXIT INT TERM
info "Installing Bash completion..."
sudo mkdir -p "$BASH_COMPLETION_DIR"
curl -sSL "https://raw.githubusercontent.com/${REPO_OWNER}/${REPO_NAME}/main/completions/bash/carch" -o "${TMP_DIR}/carch"
sudo mv "${TMP_DIR}/carch" "${BASH_COMPLETION_DIR}/carch"
info "Installing Zsh completion..."
sudo mkdir -p "$ZSH_COMPLETION_DIR"
curl -sSL "https://raw.githubusercontent.com/${REPO_OWNER}/${REPO_NAME}/main/completions/zsh/_carch" -o "${TMP_DIR}/_carch"
sudo mv "${TMP_DIR}/_carch" "${ZSH_COMPLETION_DIR}/_carch"
info "Installing Fish completion..."
sudo mkdir -p "$FISH_COMPLETION_DIR"
curl -sSL "https://raw.githubusercontent.com/${REPO_OWNER}/${REPO_NAME}/main/completions/fish/carch.fish" -o "${TMP_DIR}/carch.fish"
sudo mv "${TMP_DIR}/carch.fish" "${FISH_COMPLETION_DIR}/carch.fish"
success "Shell completions installed successfully"
}
install_icons() {
info "Installing icons..."
TMP_DIR="$(mktemp -d)"
trap 'rm -rf "$TMP_DIR"' EXIT INT TERM
for size in 16 24 32 48 64 128 256; do
info "Installing ${size}x${size} icon..."
sudo mkdir -p "${ICON_DIR}/${size}x${size}/apps"
curl -sSL "https://raw.githubusercontent.com/${REPO_OWNER}/${REPO_NAME}/main/assets/icons/product_logo_${size}.png" \
-o "${TMP_DIR}/carch_${size}.png"
sudo mv "${TMP_DIR}/carch_${size}.png" "${ICON_DIR}/${size}x${size}/apps/carch.png"
done
if command_exists "gtk-update-icon-cache"; then
info "Updating icon cache..."
sudo gtk-update-icon-cache -f -t "$ICON_DIR" || warning "Failed to update icon cache"
fi
success "Icons installed successfully"
}
install_man_page() {
info "Installing man page..."
TMP_DIR="$(mktemp -d)"
trap 'rm -rf "$TMP_DIR"' EXIT INT TERM
sudo mkdir -p "$MAN_DIR"
curl -sSL "https://raw.githubusercontent.com/${REPO_OWNER}/${REPO_NAME}/main/man/carch.1" -o "${TMP_DIR}/carch.1"
sudo mv "${TMP_DIR}/carch.1" "${MAN_DIR}/carch.1"
if command_exists "mandb"; then
info "Updating man database..."
sudo mandb -q || warning "Failed to update man database"
fi
success "Man page installed successfully"
}
install_desktop_file() {
info "Installing desktop file..."
TMP_DIR="$(mktemp -d)"
trap 'rm -rf "$TMP_DIR"' EXIT INT TERM
curl -sSL "https://raw.githubusercontent.com/${REPO_OWNER}/${REPO_NAME}/main/carch.desktop" -o "${TMP_DIR}/carch.desktop"
sed -i "s|Exec=.*|Exec=${INSTALL_DIR}/${BINARY_NAME}|g" "${TMP_DIR}/carch.desktop"
sudo mv "${TMP_DIR}/carch.desktop" "$DESKTOP_FILE_PATH"
if command_exists "update-desktop-database"; then
info "Updating desktop database..."
sudo update-desktop-database || warning "Failed to update desktop database"
fi
success "Desktop file installed successfully"
}
uninstall_binary() {
info "Uninstalling carch binary..."
if [ -f "${INSTALL_DIR}/${BINARY_NAME}" ]; then
sudo rm -f "${INSTALL_DIR}/${BINARY_NAME}"
success "Carch binary uninstalled successfully"
else
warning "Carch binary not found at ${INSTALL_DIR}/${BINARY_NAME}"
fi
}
uninstall_completions() {
info "Uninstalling shell completions..."
if [ -f "${BASH_COMPLETION_DIR}/carch" ]; then
sudo rm -f "${BASH_COMPLETION_DIR}/carch"
success "Bash completion removed"
else
warning "Bash completion not found"
fi
if [ -f "${ZSH_COMPLETION_DIR}/_carch" ]; then
sudo rm -f "${ZSH_COMPLETION_DIR}/_carch"
success "Zsh completion removed"
else
warning "Zsh completion not found"
fi
if [ -f "${FISH_COMPLETION_DIR}/carch.fish" ]; then
sudo rm -f "${FISH_COMPLETION_DIR}/carch.fish"
success "Fish completion removed"
else
warning "Fish completion not found"
fi
}
uninstall_icons() {
info "Uninstalling icons..."
for size in 16 24 32 48 64 128 256; do
if [ -f "${ICON_DIR}/${size}x${size}/apps/carch.png" ]; then
sudo rm -f "${ICON_DIR}/${size}x${size}/apps/carch.png"
success "${size}x${size} icon removed"
else
warning "${size}x${size} icon not found"
fi
done
if command_exists "gtk-update-icon-cache"; then
info "Updating icon cache..."
sudo gtk-update-icon-cache -f -t "$ICON_DIR" || warning "Failed to update icon cache"
fi
}
uninstall_man_page() {
info "Uninstalling man page..."
if [ -f "${MAN_DIR}/carch.1" ]; then
sudo rm -f "${MAN_DIR}/carch.1"
success "Man page removed"
if command_exists "mandb"; then
info "Updating man database..."
sudo mandb -q || warning "Failed to update man database"
fi
else
warning "Man page not found"
fi
}
uninstall_desktop_file() {
info "Uninstalling desktop file..."
if [ -f "$DESKTOP_FILE_PATH" ]; then
sudo rm -f "$DESKTOP_FILE_PATH"
success "Desktop file removed"
if command_exists "update-desktop-database"; then
info "Updating desktop database..."
sudo update-desktop-database || warning "Failed to update desktop database"
fi
else
warning "Desktop file not found"
fi
}
uninstall_config() {
info "Removing configuration directory..."
if [ -d "$CONFIG_DIR" ]; then
rm -rf "$CONFIG_DIR"
success "Configuration directory removed"
else
warning "Configuration directory not found"
fi
}
print_install_success_message() {
echo ""
echo "${GREEN}${BOLD} Carch installed successfully!${RESET}"
echo ""
echo "You can now run carch from your terminal by typing: ${BOLD}carch${RESET}"
echo ""
echo "If you need help, run: ${BOLD}carch --help${RESET}"
echo ""
echo "For more information, visit: ${BOLD}https://carch.chalisehari.com.np${RESET}"
echo ""
}
print_update_success_message() {
echo ""
echo "${GREEN}${BOLD} Carch updated successfully!${RESET}"
echo ""
echo "You can now run the updated carch from your terminal by typing: ${BOLD}carch${RESET}"
echo ""
echo "If you need help, run: ${BOLD}carch --help${RESET}"
echo ""
echo "For more information, visit: ${BOLD}https://carch.chalisehari.com.np${RESET}"
echo ""
}
print_uninstall_success_message() {
echo ""
echo "${GREEN}${BOLD} Carch uninstalled successfully!${RESET}"
echo ""
echo "All Carch components have been removed from your system."
echo ""
}
install() {
if [ "$(id -u)" -eq 0 ]; then
warning "This script is running as root. Consider running without sudo and let the script call sudo when needed."
fi
detect_platform
check_dependencies
install_binary
install_completions
install_icons
install_man_page
install_desktop_file
print_install_success_message
}
update() {
info "Updating Carch..."
if [ "$(id -u)" -eq 0 ]; then
warning "This script is running as root. Consider running without sudo and let the script call sudo when needed."
fi
detect_platform
check_dependencies
install_binary
install_completions
install_icons
install_man_page
install_desktop_file
print_update_success_message
}
uninstall() {
info "Uninstalling Carch..."
if [ "$(id -u)" -eq 0 ]; then
warning "This script is running as root. Consider running without sudo and let the script call sudo when needed."
fi
uninstall_binary
uninstall_completions
uninstall_icons
uninstall_man_page
uninstall_desktop_file
uninstall_config
print_uninstall_success_message
}
print_usage() {
echo "Usage: $0 [--install|--update|--uninstall]"
echo ""
echo "Options:"
echo " --install Install Carch (default action)"
echo " --update Update an existing Carch installation"
echo " --uninstall Uninstall Carch completely"
echo ""
}
main() {
if [ $# -eq 0 ]; then
install
else
case "$1" in
--install)
install
;;
--update)
update
;;
--uninstall)
uninstall
;;
--help)
print_usage
;;
*)
error "Unknown option: $1. Use --help to see available options."
;;
esac
fi
}
main "$@"