Repository navigation
Expand file tree
/
Copy pathmain.bash
More file actions
executable file
·496 lines (406 loc) · 13.3 KB
/
Copy pathmain.bash
File metadata and controls
executable file
·496 lines (406 loc) · 13.3 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
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
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
#!/bin/bash -i
## bashsupport disable=BP2001
# Colours
#Black 0;30 Dark Gray 1;30
#Red 0;31 Light Red 1;31
#Green 0;32 Light Green 1;32
#Brown/Orange 0;33 Yellow 1;33
#Blue 0;34 Light Blue 1;34
#Purple 0;35 Light Purple 1;35
#Cyan 0;36 Light Cyan 1;36
#Light Gray 0;37 White 1;37
RED='\033[0;31m' # ${RED}
GREEN='\033[0;32m' # ${GREEN}
YELLOW='\033[0;33m' # ${YELLOW}
BLUE='\033[0;34m' # ${BLUE}
NC='\033[0m' # No Color ${NC}
#echo -e "${RED}red text ${NC} normal color"
# Default APT Values
bAptUpdate=true
bAptUpgrade=false
bDnfUpdate=true
bDnfUpgrade=false
bFlatPak=false
bAutoYesPrompts=false
bDownloadFilesOnly=false
selectedListsToInstall="Desktop, Server, Flatpak Desktop, Flatpak Server"
# Brave browser installer script from https://brave.com/linux/
cmdBrave="curl -fsS https://dl.brave.com/install.sh | sh"
bAptExists=false
bDnfExists=false
# Default package lists
defaultDesktop="https://raw.githubusercontent.com/VinterSolen/squidInstaller/refs/heads/main/packagefiles/install-desktop.txt"
defaultServer="https://raw.githubusercontent.com/VinterSolen/squidInstaller/refs/heads/main/packagefiles/install-server.txt"
defaultFlatpakDesktop="https://raw.githubusercontent.com/VinterSolen/squidInstaller/refs/heads/main/packagefiles/install-flatpak-desktop.txt"
defaultFlatpakServer="https://raw.githubusercontent.com/VinterSolen/squidInstaller/refs/heads/main/packagefiles/install-flatpak-server.txt"
#Enable/Disable lists for installation
bDefaultDesktop=false
bDefaultServer=false
bDefaultFlatpakDesktop=false
bDefaultFlatpakServer=false
specialInstall="(none)"
bSpecialBrave=false
# The main menu of the installer
# Enables user to make changes before running installer
mainMenu() {
aptUpdate="APT Update: $(yesNoValue "$bAptUpdate") "
aptUpgrade="APT Upgrade: $(yesNoValue "$bAptUpgrade") "
dnfUpdate="DNF Update: $(yesNoValue "$bDnfUpdate") "
dnfUpgrade="DNF Upgrade: $(yesNoValue "$bDnfUpgrade") "
flatPak="FlatPak: $(yesNoValue "$bFlatPak")"
#Set output to empty before re-building it
OUTPUT=""
clear
updateInstallListString
updateSpecialInstallListString
echo -e "################################################################################"
# Root check
if [ "$USER" != "root" ]; then
echo -e "${RED}This script might need to be run as root to install packages${NC}"
fi
# Put in values of update/upgrades to reflect toggleable values
if [ "$bAptExists" = "true" ]; then
# APT
OUTPUT="${OUTPUT}(1) $aptUpdate \t (2) $aptUpgrade \n"
elif [ "$bDnfExists" = "true" ]; then
# DNF
OUTPUT="${OUTPUT}(1) $dnfUpdate \t (2) $dnfUpgrade \n"
fi
OUTPUT="${OUTPUT}(3) $flatPak \t (4) Show lists \n"
# Last Rows
OUTPUT="${OUTPUT}(r) Run installer \t (a) Automatic yes to prompts: $(yesNoValue "$bAutoYesPrompts")\n"
OUTPUT="${OUTPUT}\t (d) Download files only: $(yesNoValue "$bDownloadFilesOnly")\n"
OUTPUT="${OUTPUT}(s) Special installs:\t $specialInstall\n"
OUTPUT="${OUTPUT}(e) Lists to install:\t $selectedListsToInstall \n"
OUTPUT="${OUTPUT}(p) Print Menu \t (q) Exit \n"
# Print the menu and format the columns a bit nicer to view
echo -e "$OUTPUT" | column -ts $'\t' -o " "
echo -e "################################################################################"
# Read input for options, p to reprint the menu as the default value
read -rp "Enter value [p]: " readValue
readValue=${readValue:-p}
# When a user has entered something, do something here
case $readValue in
"q") # Exit script
exit 0
;;
"p") # Print MainMenu
mainMenu
;;
"1") # Toggle to run repository updates before installing
if [ "$bAptExists" = "true" ]; then
# APT
bAptUpdate=$([ "$bAptUpdate" = true ] && echo false || echo true)
elif [ "$bDnfExists" = "true" ]; then
# DNF
bDnfUpdate=$([ "$bDnfUpdate" = true ] && echo false || echo true)
fi
mainMenu
;;
"2") # Toggle to run system upgrade before install
# bAptUpgrade=$([ "$bAptUpgrade" = true ] && echo false || echo true)
if [ "$bAptExists" = "true" ]; then
# APT
bAptUpgrade=$([ "$bAptUpgrade" = true ] && echo false || echo true)
elif [ "$bDnfExists" = "true" ]; then
# DNF
bDnfUpgrade=$([ "$bDnfUpgrade" = true ] && echo false || echo true)
fi
mainMenu
;;
"3") # Toggle to install flatpak and enable flatpak lists
bFlatPak=$([ "$bFlatPak" = true ] && echo false || echo true)
mainMenu
;;
"4")
defaultListMenu
;;
"a") # Answer yes to all prompts
bAutoYesPrompts=$([ "$bAutoYesPrompts" = true ] && echo false || echo true)
mainMenu
;;
"d") # Only download the files without installing
bDownloadFilesOnly=$([ "$bDownloadFilesOnly" = true ] && echo false || echo true)
mainMenu
;;
"s") # Special installs, like Brave browser
specialInstallMenu
;;
"e") # Change what lists to be installed
changeInstallLists
;;
*) # If no other value matches
mainMenu
;;
esac
}
changeInstallLists() {
OUTPUT=""
clear
echo -e "################################################################################"
OUTPUT="${OUTPUT}(1) Server list \t $(yesNoValue "$bDefaultServer") \n"
OUTPUT="${OUTPUT}(2) Desktop list \t $(yesNoValue "$bDefaultDesktop") \n"
OUTPUT="${OUTPUT}(3) Flatpak list (Server) \t $(yesNoValue "$bDefaultFlatpakServer") \n"
OUTPUT="${OUTPUT}(4) Flatpak list (Desktop) \t $(yesNoValue "$bDefaultFlatpakDesktop") \n"
OUTPUT="${OUTPUT}(d) Display lists content \t \n"
# Last Rows
OUTPUT="${OUTPUT}(m) Main menu \t\n"
OUTPUT="${OUTPUT}(p) Print Menu \t (q) Exit \n"
# Print the menu and format the columns a bit nicer to view
echo -e "$OUTPUT" | column -ts $'\t' -o " "
echo -e "################################################################################"
# Read input for options, p to reprint the menu as the default value
read -rp "Enter value [p]: " readValue
readValue=${readValue:-p}
# When the user has entered something, do something here
case $readValue in
"q")
exit 0
;;
"p")
changeInstallLists
;;
"1")
bDefaultServer=$([ "$bDefaultServer" = true ] && echo false || echo true)
changeInstallLists
;;
"2")
bDefaultDesktop=$([ "$bDefaultDesktop" = true ] && echo false || echo true)
changeInstallLists
;;
"3")
bDefaultFlatpakServer=$([ "$bDefaultFlatpakServer" = true ] && echo false || echo true)
changeInstallLists
;;
"4")
bDefaultFlatpakDesktop=$([ "$bDefaultFlatpakDesktop" = true ] && echo false || echo true)
changeInstallLists
;;
"d")
displayListContent
changeInstallLists
;;
"m")
updateInstallListString
mainMenu
;;
*) # If no other value matches
changeInstallLists
;;
esac
}
# Function to displays and enables changing the default lists
defaultListMenu() {
#Set output to empty before re-building it
OUTPUT=""
clear
echo -e "################################################################################"
# Put in values of update/upgrades to reflect toggleable values
OUTPUT="${OUTPUT}(1) Server list \t $defaultServer \n"
OUTPUT="${OUTPUT}(2) Desktop list \t $defaultDesktop \n"
OUTPUT="${OUTPUT}(3) Flatpak list (Server) \t $defaultFlatpakServer \n"
OUTPUT="${OUTPUT}(4) Flatpak list (Desktop) \t $defaultFlatpakDesktop \n"
OUTPUT="${OUTPUT}(d) Display lists content \t \n"
# Last Rows
OUTPUT="${OUTPUT}(m) Main menu \t\n"
OUTPUT="${OUTPUT}(p) Print Menu \t (q) Exit \n"
# Print the menu and format the columns a bit nicer to view
echo -e "$OUTPUT" | column -ts $'\t' -o " "
echo -e "################################################################################"
# Read input for options, p to reprint the menu as the default value
read -rp "Enter value [p]: " readValue
readValue=${readValue:-p}
# When a user has entered something, do something here
case $readValue in
"q")
exit 0
;;
"p")
defaultListMenu
;;
"1")
#bAptUpdate=$([ "$bAptUpdate" = true ] && echo false || echo true)
defaultListMenu
;;
"2")
#bAptUpgrade=$([ "$bAptUpgrade" = true ] && echo false || echo true)
defaultListMenu
;;
"3")
#bFlatPak=$([ "$bFlatPak" = true ] && echo false || echo true)
defaultListMenu
;;
"4")
defaultListMenu
;;
"d")
displayListContent
defaultListMenu
;;
"m")
mainMenu
;;
*) # If no other value matches
defaultListMenu
;;
esac
}
# Fetches the lists and displays them for the user
displayListContent() {
echo "Fetching lists.."
#$defaultServer
contentDefaultServer=$(wget $defaultServer -q -O -)
contentDefaultDesktop=$(wget $defaultDesktop -q -O -)
contentDefaultFlatpakDesktop=$(wget $defaultFlatpakDesktop -q -O -)
contentDefaultFlatpakServer=$(wget $defaultFlatpakServer -q -O -)
echo -e "#############################\n"
echo -e "${BLUE}Candidates for Server:${NC}"
echo -e "${YELLOW}$contentDefaultServer${NC}\n"
#echo -e "#############################\n"
echo -e "${BLUE}Candidates for Desktop:${NC}"
echo -e "${YELLOW}$contentDefaultDesktop${NC}\n"
#echo -e "#############################\n"
echo -e "${BLUE}Candidates for Flatpak Server:${NC}"
echo -e "${YELLOW}$contentDefaultFlatpakServer${NC}\n"
#echo -e "#############################\n"
echo -e "${BLUE}Candidates for Flatpak Desktop:${NC}"
echo -e "${YELLOW}$contentDefaultFlatpakDesktop${NC}\n"
echo "#############################"
# Script continues after the user presses Enter
pause_for_user
}
# Pauses script execution until user presses Enter
# Optional prompt message can be provided as argument
pause_for_user() {
read -n 1 -s -r -p "Press any key to continue"
}
# Function that converts truthy/falsy values to "yes" or "no"
# Usage: yesNoValue <input>
# Returns "yes" if input is 1 or true, "no" if input is 0 or false
yesNoValue() {
local input=$1
if [ "$input" = "1" ] || [ "$input" = "true" ]; then
echo "Yes"
elif [ "$input" = "0" ] || [ "$input" = "false" ]; then
echo "No"
else
# Optional: handle invalid input - you can change this behavior
echo "invalid input"
fi
}
updateInstallListString() {
selectedListsToInstall=""
local bFirst=true
# Server
if [ "$bDefaultServer" = "true" ]; then
if [ "$bFirst" = "true" ]; then
selectedListsToInstall="${GREEN}Server${NC}"
bFirst=false
else
selectedListsToInstall="$selectedListsToInstall, ${GREEN}Server${NC}"
fi
fi
# Desktop
if [ "$bDefaultDesktop" = "true" ]; then
if [ "$bFirst" = "true" ]; then
selectedListsToInstall="${GREEN}Desktop${NC}"
bFirst=false
else
selectedListsToInstall="$selectedListsToInstall, ${GREEN}Desktop${NC}"
fi
fi
# Server, Flatpak
if [ "$bDefaultFlatpakServer" = "true" ] && [ "$bFlatPak" = "true" ]; then
if [ "$bFirst" = "true" ]; then
selectedListsToInstall="${GREEN}Server Flatpak${NC}"
bFirst=false
else
selectedListsToInstall="$selectedListsToInstall, ${GREEN}Server Flatpak${NC}"
fi
fi
# Desktop, Flatpak
if [ "$bDefaultFlatpakDesktop" = "true" ] && [ "$bFlatPak" = "true" ]; then
if [ "$bFirst" = "true" ]; then
selectedListsToInstall="${GREEN}Desktop Flatpak${NC}"
bFirst=false
else
selectedListsToInstall="$selectedListsToInstall, ${GREEN}Desktop Flatpak${NC}"
fi
fi
if [ "$selectedListsToInstall" = "" ]; then
selectedListsToInstall="${RED}(none)${NC}"
fi
}
checkDNForAPT() {
if available apt-get; then
bAptExists=true
else
bAptExists=false
fi
if available dnf; then
bDnfExists=true
else
bDnfExists=false
fi
}
specialInstallMenu() {
#bSpecialBrave
#Set output to empty before re-building it
OUTPUT=""
clear
echo -e "################################################################################"
# Put in values of update/upgrades to reflect toggleable values
OUTPUT="${OUTPUT}(1) Brave Browser \t $(yesNoValue "$bSpecialBrave") \n"
# Last Rows
OUTPUT="${OUTPUT}(m) Main menu \t\n"
OUTPUT="${OUTPUT}(p) Print Menu \t (q) Exit \n"
# Print the menu and format the columns a bit nicer to view
echo -e "$OUTPUT" | column -ts $'\t' -o " "
echo -e "################################################################################"
# Read input for options, p to reprint the menu as the default value
read -rp "Enter value [p]: " readValue
readValue=${readValue:-p}
# When a user has entered something, do something here
case $readValue in
"q")
exit 0
;;
"p")
specialInstallMenu
;;
"1")
bSpecialBrave=$([ "$bSpecialBrave" = true ] && echo false || echo true)
specialInstallMenu
;;
"m")
updateSpecialInstallListString
mainMenu
;;
*) # If no other value matches
specialInstallMenu
;;
esac
}
updateSpecialInstallListString() {
specialInstall=""
local bFirst=true
# Server
if [ "$bSpecialBrave" = "true" ]; then
if [ "$bFirst" = "true" ]; then
specialInstall="${GREEN}Brave${NC}"
bFirst=false
else
specialInstall="$specialInstall, ${GREEN}Brave${NC}"
fi
else
specialInstall="(none)"
fi
}
# Helpers
available() { command -v "${1:?}" >/dev/null; }
# Check if DNF or APT exists on the system
checkDNForAPT
updateInstallListString
updateSpecialInstallListString
# Calls the mainMenu function to start off the script
mainMenu