-
Notifications
You must be signed in to change notification settings - Fork 9
/
appimage.sh
executable file
·395 lines (346 loc) · 12.2 KB
/
appimage.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
#!/bin/bash
# LICENSE:
# Done by: https://github.com/Muko-Tabi
# Twilight support added by: https://github.com/LeMoonStar
# This script is licensed under the MIT License.
set -euo pipefail
function log() {
local RED='\033[0;31m'
local YELLOW='\033[1;33m'
local GREEN='\033[0;32m'
local YELLOW_BG='\033[43m'
local BLACK_FG='\033[30m'
NC='\033[0m'
if [[ "${1}" == "info" ]]; then
printf "${GREEN}[i] ${2}${NC}\n"
elif [[ "${1}" == "warn" ]]; then
printf "${YELLOW}[w] ${2}${NC}\n"
elif [[ "${1}" == "err" ]]; then
printf "${RED}[e] ${2}${NC}\n"
elif [[ "${1}" == "highlight" ]]; then
printf "${YELLOW_BG}[h] ${BLACK_FG}${2}${NC}\n"
else
echo "WRONG SEVERITY : $1"
exit 1
fi
}
function log_info() { log "info" "$1"; }
function log_warn() { log "warn" "$1"; }
function log_err() { log "err" "$1"; }
function log_highlight() { log "highlight" "$1"; }
# Download URL globals
# Zen Stable
ZEN_STABLE_GENERIC="https://github.com/zen-browser/desktop/releases/latest/download/zen-generic.AppImage"
ZEN_STABLE_SPECIFIC="https://github.com/zen-browser/desktop/releases/latest/download/zen-specific.AppImage"
# Zen Twilight
ZEN_TWILIGHT_GENERIC="https://github.com/zen-browser/desktop/releases/download/twilight/zen-generic.AppImage"
ZEN_TWILIGHT_SPECIFIC="https://github.com/zen-browser/desktop/releases/download/twilight/zen-specific.AppImage"
# Filename base globals
ZEN_STABLE_NAME_BASE="ZenBrowser"
ZEN_TWILIGHT_NAME_BASE="ZenTwilight"
# Function to check if AVX2 is supported
check_avx2_support() {
if grep -q avx2 /proc/cpuinfo; then
return 0 # AVX2 supported
else
return 1 # AVX2 not supported
fi
}
# Function to check if Zen Browser is installed
check_installation_status() {
local app_name="$1"
if [ -f ~/.local/share/AppImage/$app_name.AppImage ]; then
return 0 # Zen Browser installed
else
return 1 # Zen Browser not installed
fi
}
# Function to check if zsync is installed
check_zsync_installed() {
if command -v zsync &> /dev/null; then
return 0 # zsync is installed
else
return 1 # zsync is not installed
fi
}
# Kawaii ASCII Art for the script
kawaii_art() {
local is_twilight="$1"
local file_base
if [[ "$is_twilight" == "1" ]]; then
file_base="$ZEN_TWILIGHT_NAME_BASE"
else
file_base="$ZEN_STABLE_NAME_BASE"
fi
log_info "╔════════════════════════════════════════════════════╗"
log_info "║ ║"
log_info "║ (ノ◕ヮ◕)ノ*:・゚✧ Zen Browser Installer ║"
log_info "║ ║"
if check_avx2_support; then
log_info "║ CPU: AVX2 Supported (Optimized Version) ║"
else
log_info "║ CPU: AVX2 Not Supported (Generic Version) ║"
fi
if check_installation_status "$file_base"; then
log_info "║ Status: Zen Browser Installed ║"
else
log_info "║ Status: Zen Browser Not Installed ║"
fi
if check_zsync_installed; then
log_info "║ zsync: Installed (Needed for Updates) ║"
else
log_info "║ zsync: Not Installed (Needed for Updates) ║"
fi
log_info "║ ║"
log_info "╚════════════════════════════════════════════════════╝"
log_info ""
}
# Function to download a file with unlimited retries
download_until_success() {
local url="$1"
local output_path="$2"
local mode="$3" # New parameter to indicate the mode
while true; do
case "$mode" in
"zsync")
log_info "Checking for Update..."
;;
"update")
log_info "Updating Zen Browser..."
;;
"install")
log_info "Installing Zen Browser..."
;;
esac
if curl -# -L --connect-timeout 30 --max-time 600 "$url" -o "$output_path"; then
case "$mode" in
"zsync")
log_info "Checking for Update successfully!"
;;
"update")
log_info "Update completed successfully!"
;;
"install")
log_info "Install completed successfully!"
;;
esac
break
else
case "$mode" in
"zsync")
log_err "(⌣_⌣” ) Checking for Update failed, retrying..."
;;
"update")
log_err "(⌣_⌣” ) Update failed, retrying..."
;;
"install")
log_err "(⌣_⌣” ) Install failed, retrying..."
;;
esac
sleep 5 # Optional: wait a bit before retrying
fi
done
}
process_appimage() {
local appimage_path="$1"
local app_name="$2"
# Make AppImage executable
chmod +x "${appimage_path}"
# Extract all files from AppImage
"${appimage_path}" --appimage-extract
# Move .desktop file (from /squashfs-root only)
desktop_file=$(find squashfs-root -maxdepth 1 -name "*.desktop" | head -n 1)
mv "${desktop_file}" ~/.local/share/applications/${app_name}.desktop
# Find PNG icon (from /squashfs-root only)
icon_file=$(find squashfs-root -maxdepth 1 -name "*.png" | head -n 1)
# Resolve symlink if the icon is a symlink
if [ -L "${icon_file}" ]; then
icon_file=$(readlink -f "${icon_file}")
fi
# Copy the icon to the icons directory
cp "${icon_file}" ~/.local/share/icons/${app_name}.png
# Move AppImage to final location, only if it's not already there
if [ "${appimage_path}" != "$HOME/.local/share/AppImage/${app_name}.AppImage" ]; then
mv "${appimage_path}" ~/.local/share/AppImage/
fi
# Edit .desktop file to update paths
desktop_file=~/.local/share/applications/${app_name}.desktop
awk -v home="$HOME" -v app_name="$app_name" '
BEGIN { in_action = 0 }
/^\[Desktop Action/ { in_action = 1 }
/^Exec=/ {
if (in_action) {
split($0, parts, "=")
sub(/^[^ ]+/, "", parts[2]) # Remove the first word (original command)
print "Exec=" home "/.local/share/AppImage/" app_name ".AppImage" parts[2]
} else {
print "Exec=" home "/.local/share/AppImage/" app_name ".AppImage %u"
}
next
}
/^Icon=/ { print "Icon=" home "/.local/share/icons/" app_name ".png"; next }
{ print }
' "${desktop_file}" > "${desktop_file}.tmp" && mv "${desktop_file}.tmp" "${desktop_file}"
# Clean up extracted files
rm -rf squashfs-root
}
uninstall_appimage() {
local app_name="$1"
log_info ""
# Remove AppImage
log_warn "Removing Zen Browser AppImage..."
rm -f ~/.local/share/AppImage/${app_name}.AppImage
# Remove .desktop file
log_warn "Removing Zen Browser .desktop file..."
rm -f ~/.local/share/applications/${app_name}.desktop
# Remove icon
log_warn "Removing Zen Browser icon..."
rm -f ~/.local/share/icons/${app_name}.png
log_info ""
log_info "(︶︹︺) Uninstalled ${app_name}"
}
check_for_updates() {
local is_twilight="$1"
local zsync_url
local zsync_file
local appimage_url
local file_base
if [[ "$is_twilight" == 1 ]]; then
file_base="$ZEN_TWILIGHT_NAME_BASE"
else
file_base="$ZEN_STABLE_NAME_BASE"
fi
log_info ""
if check_avx2_support; then
if [[ "$is_twilight" == 1 ]]; then
zsync_url="$ZEN_TWILIGHT_SPECIFIC.zsync"
appimage_url="$ZEN_TWILIGHT_SPECIFIC"
else
zsync_url="$ZEN_STABLE_SPECIFIC.zsync"
appimage_url="$ZEN_STABLE_SPECIFIC"
fi
log_warn "Auto detecting AVX2 support..."
else
if [[ "$is_twilight" == 1 ]]; then
zsync_url="$ZEN_TWILIGHT_GENERIC.zsync"
appimage_url="$ZEN_TWILIGHT_GENERIC"
else
zsync_url="$ZEN_STABLE_GENERIC.zsync"
appimage_url="$ZEN_STABLE_GENERIC"
fi
log_warn "AVX2 not supported. Using generic version..."
fi
zsync_file="${HOME}/Downloads/$file_base.AppImage.zsync"
if check_installation_status "$file_base"; then
log_info "Checking for updates..."
if ! check_zsync_installed; then
log_err "Zsync is not installed. Please install zsync to enable update functionality."
return 1
fi
download_until_success "$zsync_url" "$zsync_file" "zsync"
update_output=$(zsync -i ~/.local/share/AppImage/$file_base.AppImage -o ~/.local/share/AppImage/$file_base.AppImage "$zsync_file" 2>&1)
if echo "$update_output" | grep -q "verifying download...checksum matches OK"; then
log_info "(。♥‿♥。) Congrats! Zen Browser is up-to-date!"
else
echo "Updating Zen Browser..."
download_until_success "$appimage_url" ~/.local/share/AppImage/$file_base.AppImage "update"
process_appimage ~/.local/share/AppImage/$file_base.AppImage $file_base
log_info "(。♥‿♥。) Zen Browser updated to the latest!"
fi
rm -f "$zsync_file"
else
log_err "Zen Browser is not installed!"
main_menu
fi
}
install_zen_browser() {
local is_twilight="$1"
local appimage_url
local file_base
if [[ "$is_twilight" == 1 ]]; then
file_base="$ZEN_TWILIGHT_NAME_BASE"
else
file_base="$ZEN_STABLE_NAME_BASE"
fi
log_info ""
if check_avx2_support; then
if [[ "$is_twilight" == 1 ]]; then
appimage_url="$ZEN_TWILIGHT_SPECIFIC"
else
appimage_url="$ZEN_STABLE_SPECIFIC"
fi
log_warn "Auto detecting AVX2 support..."
else
if [[ "$is_twilight" == 1 ]]; then
appimage_url="$ZEN_TWILIGHT_GENERIC"
else
appimage_url="$ZEN_STABLE_GENERIC"
fi
log_warn "AVX2 not supported. Using generic version..."
fi
log_warn "Downloading Zen from $appimage_url"
log_info ""
temp_file="/tmp/$file_base.AppImage"
download_until_success "$appimage_url" "$temp_file" "install"
process_appimage "$temp_file" $file_base
log_info ""
log_info "(。♥‿♥。) Zen Browser installed successfully!"
rm -f "$temp_file"
}
main_menu() {
# Check if the script is in twilight mode.
local is_twilight
if [[ "$1" == "twilight" ]]; then
is_twilight=1
log_warn "The installer is in Twilight mode!"
else
is_twilight=0
fi
# Show kawaii ASCII art
kawaii_art $is_twilight
log_info "(★^O^★) What would you like to do?"
log_info " 1) Install"
log_info " 2) Uninstall"
if check_zsync_installed; then
log_info " 3) Check for Updates"
fi
log_info " 0) Exit"
read -p "Enter your choice (0-3): " main_choice
case $main_choice in
1)
install_zen_browser $is_twilight
;;
2)
if [[ "$is_twilight" == 1 ]]; then
uninstall_appimage "$ZEN_TWILIGHT_NAME_BASE"
else
uninstall_appimage "$ZEN_STABLE_NAME_BASE"
fi
;;
3)
if check_zsync_installed; then
check_for_updates $is_twilight
else
log_err "(•ˋ _ ˊ•) Invalid choice. Exiting..."
exit 1
fi
;;
0)
log_info "(⌒‿⌒) Exiting..."
exit 0
;;
*)
log_err "(•ˋ _ ˊ•) Invalid choice. Exiting..."
exit 1
;;
esac
}
# Create necessary directories
mkdir -p ~/.local/share/applications
mkdir -p ~/.local/share/icons
mkdir -p ~/.local/share/AppImage
# Execute the main menu
main_menu "${1:-stable}"
# End of script
log_info ""
log_info "Thank you for using Zen Browser Installer!"