-
Notifications
You must be signed in to change notification settings - Fork 1
/
wizard.sh
969 lines (811 loc) · 32.1 KB
/
wizard.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
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
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
#!/bin/bash
PATH="/bin:/usr/bin:/sbin:/usr/sbin"
echo
##--------------------------------------------------------------------------
# @author : aetherinox
# @script : Proteus Install Wizard
# @when : 2023-10-14 08:10:25
# @url : https://github.com/Aetherinox/proteus-app-manager
#
# requires chmod +x proteus_wizard.sh
#
##--------------------------------------------------------------------------
##--------------------------------------------------------------------------
# vars > colors
#
# tput setab [1-7] – Set a background color using ANSI escape
# tput setb [1-7] – Set a background color
# tput setaf [1-7] – Set a foreground color using ANSI escape
# tput setf [1-7] – Set a foreground color
##--------------------------------------------------------------------------
BLACK=$(tput setaf 0)
RED=$(tput setaf 1)
GREEN=$(tput setaf 2)
YELLOW=$(tput setaf 3)
LIME_YELLOW=$(tput setaf 190)
POWDER_BLUE=$(tput setaf 153)
BLUE=$(tput setaf 4)
MAGENTA=$(tput setaf 5)
CYAN=$(tput setaf 6)
WHITE=$(tput setaf 7)
GREYL=$(tput setaf 242)
DEV=$(tput setaf 157)
DEVGREY=$(tput setaf 243)
FUCHSIA=$(tput setaf 198)
PINK=$(tput setaf 200)
BRIGHT=$(tput bold)
NORMAL=$(tput sgr0)
BLINK=$(tput blink)
REVERSE=$(tput smso)
UNDERLINE=$(tput smul)
##--------------------------------------------------------------------------
# vars > colors for whiptail
##--------------------------------------------------------------------------
export NEWT_COLORS='
root=,black
window=,lightgray
shadow=,
title=color8,
checkbox=,magenta
entry=,color8
label=blue,
actlistbox=,magenta
actsellistbox=,magenta
helpline=,magenta
roottext=,magenta
emptyscale=magenta
disabledentry=magenta,
'
##--------------------------------------------------------------------------
# vars > status messages
##--------------------------------------------------------------------------
STATUS_SKIP="${BOLD}${GREYL} SKIP ${NORMAL}"
STATUS_OK="${BOLD}${GREEN} OK ${NORMAL}"
STATUS_FAIL="${BOLD}${RED} FAIL ${NORMAL}"
##--------------------------------------------------------------------------
# vars > app
##--------------------------------------------------------------------------
apt_dir_home="$HOME/bin"
app_file_this=$(basename "$0")
app_file_proteus="${apt_dir_home}/proteus"
app_repo_dev="Aetherinox"
app_repo="proteus-app-manager"
app_repo_branch="main"
app_repo_apt="proteus-apt-repo"
app_repo_apt_pkg="aetherinox-${app_repo_apt}-archive"
app_title="Proteus Wizard"
app_repo_url="https://github.com/${app_repo_dev}/${app_repo}"
app_mnfst="https://raw.githubusercontent.com/${app_repo_dev}/${app_repo}/${app_repo_branch}/manifest/proteus-app/manifest.json"
app_script="https://raw.githubusercontent.com/${app_repo_dev}/${app_repo}/BRANCH/setup.sh"
app_ver=("1" "0" "0" "7")
app_dir=$PWD
app_pid_spin=0
app_pid=$BASHPID
##--------------------------------------------------------------------------
# vars > general
##--------------------------------------------------------------------------
gui_about="Install & update wizard for Proteus App manager."
##--------------------------------------------------------------------------
# distro
#
# returns distro information.
##--------------------------------------------------------------------------
# freedesktop.org and systemd
if [ -f /etc/os-release ]; then
. /etc/os-release
OS=$NAME
OS_VER=$VERSION_ID
# linuxbase.org
elif type lsb_release >/dev/null 2>&1; then
OS=$(lsb_release -si)
OS_VER=$(lsb_release -sr)
# versions of Debian/Ubuntu without lsb_release cmd
elif [ -f /etc/lsb-release ]; then
. /etc/lsb-release
OS=$DISTRIB_ID
OS_VER=$DISTRIB_RELEASE
# older Debian/Ubuntu/etc distros
elif [ -f /etc/debian_version ]; then
OS=Debian
OS_VER=$(cat /etc/debian_version)
# fallback: uname, e.g. "Linux <version>", also works for BSD
else
OS=$(uname -s)
OS_VER=$(uname -r)
fi
##--------------------------------------------------------------------------
# func > get version
#
# returns current version of app
# converts to human string.
# e.g. "1" "2" "4" "0"
# 1.2.4.0
##--------------------------------------------------------------------------
function get_version()
{
ver_join=${app_ver[*]}
ver_str=${ver_join// /.}
echo ${ver_str}
}
##--------------------------------------------------------------------------
# func > version > compare greater than
#
# this function compares two versions and determines if an update may
# be available. or the user is running a lesser version of a program.
##--------------------------------------------------------------------------
function get_version_compare_gt()
{
test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1";
}
##--------------------------------------------------------------------------
# options
#
# -d developer mode
# -h help menu
# -n developer: null run
# -s silent mode | logging disabled
# -t theme
##--------------------------------------------------------------------------
function opt_usage()
{
echo
printf " ${BLUE}${app_title}${NORMAL}\n" 1>&2
printf " ${GRAY}${gui_about}${NORMAL}\n" 1>&2
echo
printf ' %-5s %-40s\n' "Usage:" "" 1>&2
printf ' %-5s %-40s\n' " " "${0} [${GREYL}options${NORMAL}]" 1>&2
printf ' %-5s %-40s\n\n' " " "${0} [${GREYL}-h${NORMAL}] [${GREYL}-d${NORMAL}] [${GREYL}-n${NORMAL}] [${GREYL}-s${NORMAL}] [${GREYL}-t THEME${NORMAL}] [${GREYL}-v${NORMAL}]" 1>&2
printf ' %-5s %-40s\n' "Options:" "" 1>&2
printf ' %-5s %-18s %-40s\n' " " "-d, --dev" "dev mode" 1>&2
printf ' %-5s %-18s %-40s\n' " " "-h, --help" "show help menu" 1>&2
printf ' %-5s %-18s %-40s\n' " " "-n, --nullrun" "dev: null run" 1>&2
printf ' %-5s %-18s %-40s\n' " " "" "simulate app installs (no changes)" 1>&2
printf ' %-5s %-18s %-40s\n' " " "-u, --update" "update ${app_file_proteus} executable" 1>&2
printf ' %-5s %-18s %-40s\n' " " " --branch" "branch to update from" 1>&2
printf ' %-5s %-18s %-40s\n' " " "-v, --version" "current version of app manager" 1>&2
echo
echo
exit 1
}
while [ $# -gt 0 ]; do
case "$1" in
-d|--dev)
OPT_DEV_ENABLE=true
echo -e " ${FUCHSIA}${BLINK}Devmode Enabled${NORMAL}"
;;
-h*|--help*)
opt_usage
;;
-b*|--branch*)
if [[ "$1" != *=* ]]; then shift; fi
OPT_BRANCH="${1#*=}"
if [ -z "${OPT_BRANCH}" ]; then
echo -e " ${NORMAL}Must specify a valid branch"
echo -e " ${NORMAL} Default: ${YELLOW}${app_repo_branch}${NORMAL}"
exit 1
fi
;;
-n|--nullrun)
OPT_DEV_NULLRUN=true
echo -e " ${FUCHSIA}${BLINK}Devnull Enabled${NORMAL}"
;;
-u|--update)
OPT_UPDATE=true
;;
-v|--version)
echo
echo -e " ${GREEN}${BOLD}${app_title}${NORMAL} - v$(get_version)${NORMAL}"
echo -e " ${LGRAY}${BOLD}${app_repo_url}${NORMAL}"
echo -e " ${LGRAY}${BOLD}${OS} | ${OS_VER}${NORMAL}"
echo
exit 1
;;
*)
opt_usage
;;
esac
shift
done
##--------------------------------------------------------------------------
# vars > active repo branch
##--------------------------------------------------------------------------
app_repo_branch_sel=$( [[ -n "$OPT_BRANCH" ]] && echo "$OPT_BRANCH" || echo "$app_repo_branch" )
##--------------------------------------------------------------------------
# Cache Sudo Password
#
# require normal user sudo authentication for certain actions
##--------------------------------------------------------------------------
if [[ $EUID -ne 0 ]]; then
sudo -k # make sure to ask for password on next sudo
if sudo true && [ -n "${USER}" ]; then
printf " ${NORMAL}Welcome, ${USER}${NORMAL}\n" 1>&2
else
printf " ${NORMAL}Sudoer Error: Wrong password x3{NORMAL}\n" 1>&2
exit 1
fi
fi
##--------------------------------------------------------------------------
# func > spinner animation
##--------------------------------------------------------------------------
spin()
{
spinner="-\\|/-\\|/"
while :
do
for i in $(seq 0 7)
do
echo -n "${spinner:$i:1}"
echo -en "\010"
sleep 0.4
done
done
}
##--------------------------------------------------------------------------
# func > cli question
#
# used for command-line to prompt the user with a question
##--------------------------------------------------------------------------
cli_question( )
{
local syntax def response
while true; do
# end argument determines type of syntax
if [ "${2:-}" = "Y" ]; then
syntax="Y / n"
def=Y
elif [ "${2:-}" = "N" ]; then
syntax="y / N"
def=N
else
syntax="Y / N"
def=
fi
#printf '%-60s %13s %-5s' " $1 " "${YELLOW}[$syntax]${NORMAL}" ""
echo -n "$1 [$syntax] "
read -r response </dev/tty
# NULL response uses default
if [ -z "$response" ]; then
response=$def
fi
# validate response
case "$response" in
Y|y|yes|YES)
return 0
;;
N|n|no|NO)
return 1
;;
esac
done
}
##--------------------------------------------------------------------------
# func > open url
#
# opening urls in bash can be wonky as hell. just doing it the manual
# way to ensure a browser gets opened.
##--------------------------------------------------------------------------
function open_url()
{
local URL="$1"
xdg-open $URL || firefox $URL || sensible-browser $URL || x-www-browser $URL || gnome-open $URL
}
##--------------------------------------------------------------------------
# func > cmd title
##--------------------------------------------------------------------------
function title()
{
printf '%-57s %-5s' " ${1}" ""
sleep 0.3
}
##--------------------------------------------------------------------------
# func > begin action
##--------------------------------------------------------------------------
function begin()
{
spin &
app_pid_spin=$!
trap "kill -9 $app_pid_spin 2> /dev/null" $(seq 0 15)
sleep 0.3
}
##--------------------------------------------------------------------------
# func > finish action
#
# this func supports opening a url at the end of the installation
# however the command needs to have
# finish "${1}"
##--------------------------------------------------------------------------
function finish()
{
if ps -p $app_pid_spin > /dev/null
then
kill -9 $app_pid_spin 2> /dev/null
fi
}
##--------------------------------------------------------------------------
# func > exit action
##--------------------------------------------------------------------------
function exit()
{
finish
clear
}
##--------------------------------------------------------------------------
# func > env path (add)
#
# creates a new file inside /etc/profile.d/ which includes the new
# proteus bin folder.
##--------------------------------------------------------------------------
function envpath_add()
{
local file_env=/etc/profile.d/proteus.sh
if [ "$2" = "force" ] || ! echo $PATH | $(which egrep) -q "(^|:)$1($|:)" ; then
if [ "$2" = "after" ] ; then
echo 'export PATH="$PATH:'$1'"' | sudo tee $file_env > /dev/null
else
echo 'export PATH="'$1':$PATH"' | sudo tee $file_env > /dev/null
fi
fi
}
##--------------------------------------------------------------------------
# func > app update
#
# updates the /home/USER/bin/proteus file which allows proteus to be
# ran from anywhere.
##--------------------------------------------------------------------------
app_update()
{
{
local progress=0
local bUpdated=false
local cachedVer=$(get_version)
local repo_branch=$([ "${1}" ] && echo "${1}" || echo "${app_repo_branch}" )
local repo_branch_uri="${app_script/BRANCH/"$repo_branch"}"
local repo_strip="https://raw.githubusercontent.com/"
local repo_url=${repo_branch_uri//$repo_strip/}
for i in {1..4}
do
progress=$(( $progress + $(( $RANDOM % 5 + 1 )) ))
echo -e "XXX\n${progress}\nFetching Update Server\nXXX"
sleep 0.$(( 100 + RANDOM % 800 ))
done
local REPO_CONN=$( curl -s "$app_mnfst" )
local REPO_NAME=$( jq -r '.name' <<< "${REPO_CONN}" )
local REPO_VER=$( jq -r '.version' <<< "${REPO_CONN}" )
local REPO_URL=$( jq -r '.url' <<< "${REPO_CONN}" )
# To return true, second var needs to be lower
if get_version_compare_gt $REPO_VER $(get_version); then
for i in {1..4}
do
progress=$(( $progress + $(( $RANDOM % 5 + 1 )) ))
echo -e "XXX\n${progress}\nUpdate Found! Updating to v${REPO_VER}\nXXX"
sleep 0.$(( 100 + RANDOM % 800 ))
done
for i in {1..4}
do
progress=$(( $progress + $(( $RANDOM % 5 + 1 )) ))
echo -e "XXX\n${progress}\nDownloading ${repo_url}\nXXX"
sleep 0.$(( 100 + RANDOM % 800 ))
done
if [ -z "${OPT_DEV_NULLRUN}" ]; then
sudo wget -O "${app_file_proteus}" -q "$repo_branch_uri" >/dev/null
fi
for i in {1..4}
do
progress=$(( $progress + $(( $RANDOM % 5 + 1 )) ))
echo -e "XXX\n${progress}\nSetting owner of ${app_file_proteus} for user ${USER}\nXXX"
sleep 0.$(( 100 + RANDOM % 800 ))
done
if [ -z "${OPT_DEV_NULLRUN}" ]; then
sudo chgrp ${USER} ${app_file_proteus} >/dev/null
sudo chown ${USER} ${app_file_proteus} >/dev/null
fi
for i in {1..4}
do
progress=$(( $progress + $(( $RANDOM % 5 + 1 )) ))
echo -e "XXX\n${progress}\nGranting u+w on ${app_file_proteus} for user ${USER}\nXXX"
sleep 0.$(( 100 + RANDOM % 800 ))
done
if [ -z "${OPT_DEV_NULLRUN}" ]; then
sudo chmod u+x ${app_file_proteus} >/dev/null
fi
bUpdated=${REPO_VER}
fi
if [ "$bUpdated" == false ]; then
sleep 2
progress=55
echo -e "XXX\n${progress}\nNo update found\nXXX"
sleep 2
fi
for i in {1..4}
do
progress=$(( $progress + $(( $RANDOM % 5 + 1 )) ))
echo -e "XXX\n${progress}\nConfirming ${app_file_proteus} exists\nXXX"
sleep 0.$(( 100 + RANDOM % 800 ))
done
if [ -f ${app_file_proteus} ]; then
progress=$(( $progress + $(( $RANDOM % 5 + 1 )) ))
echo -e "XXX\n${progress}\nFound ${app_file_proteus}\nXXX"
sleep 2
for i in {1..4}
do
progress=$(( $progress + $(( $RANDOM % 5 + 1 )) ))
echo -e "XXX\n${progress}\nValidating permissions\nXXX"
sleep 0.$(( 100 + RANDOM % 800 ))
done
owner=$(stat -c '%U' ${app_file_proteus})
if [ "$owner" == "$USER" ]; then
progress=$(( $progress + $(( $RANDOM % 5 + 1 )) ))
echo -e "XXX\n${progress}\nPermissions OK for owner $owner\nXXX"
sleep 2
else
progress=$(( $progress + $(( $RANDOM % 5 + 1 )) ))
echo -e "XXX\n${progress}\nPermissions FAILED. Fixing ...\nXXX"
sleep 2
for i in {1..4}
do
progress=$(( $progress + $(( $RANDOM % 3 + 1 )) ))
echo -e "XXX\n${progress}\nSetting owner of ${app_file_proteus} for user ${USER}\nXXX"
sleep 0.$(( 100 + RANDOM % 800 ))
done
if [ -z "${OPT_DEV_NULLRUN}" ]; then
sudo chgrp ${USER} ${app_file_proteus} >/dev/null
sudo chown ${USER} ${app_file_proteus} >/dev/null
fi
for i in {1..4}
do
progress=$(( $progress + $(( $RANDOM % 3 + 1 )) ))
echo -e "XXX\n${progress}\nGranting u+w on ${app_file_proteus} for user ${USER}\nXXX"
sleep 0.$(( 100 + RANDOM % 800 ))
done
if [ -z "${OPT_DEV_NULLRUN}" ]; then
sudo chmod u+x ${app_file_proteus} >/dev/null
fi
fi
for i in {1..4}
do
progress=$(( $progress + $(( $RANDOM % 2 + 1 )) ))
echo -e "XXX\n${progress}\nCleaning up\nXXX"
sleep 0.$(( 100 + RANDOM % 800 ))
done
else
progress=95
echo -e "XXX\n${progress}\n${app_file_proteus} not found. Finishing.\nXXX"
sleep 2
fi
echo -e "XXX\n100\nUpdater Complete!\nXXX"
if [ "$bUpdated" != false ]; then
result="Update Complete!\nv${cachedVer} => v${REPO_VER}\n\nBinary located at: ${app_file_proteus}"
echo $result > result
else
result="No update found.\nYou are running the latest version v${cachedVer}\n\nBinary located at: ${app_file_proteus}"
echo $result > result
fi
} | whiptail --gauge "Starting Updater ..." 6 110 0
}
##--------------------------------------------------------------------------
# func > first time setup
#
# this is the default func executed when script is launched to make sure
# end-user has all the required libraries.
#
# since we're working on other distros, add curl and wget into the mix
# since some distros don't include these.
#
# [ GPG KEY / APT REPO ]
#
# NOTE: can be removed via:
# sudo rm -rf /etc/apt/sources.list.d/aetherinox*list
#
# gpg ksy stored in:
# /usr/share/keyrings/aetherinox-proteus-apt-repo-archive.gpg
# sudo rm -rf /usr/share/keyrings/aetherinox*gpg
#
# as of 1.0.0.3-alpha, deprecated apt-key method removed for adding
# gpg key. view readme for new instructions. registered repo now
# contains two files
# - trusted gpg key: aetherinox-proteus-apt-repo-archive.gpg
# - source .list: /etc/apt/sources.list.d/aetherinox*list
#
# ${1} ReqTitle
# contains a string if exists
# triggers is function called from another function to check for
# a prerequisite
##--------------------------------------------------------------------------
function app_setup
{
{
local progress=0
local repo_branch=$([ "${1}" ] && echo "${1}" || echo "${app_repo_branch}" )
local repo_branch_uri="${app_script/BRANCH/"$repo_branch"}"
local repo_strip="https://raw.githubusercontent.com/"
local repo_url=${repo_branch_uri//$repo_strip/}
local REPO_CONN=$(curl -s "$app_mnfst")
local REPO_NAME=$( jq -r '.name' <<< "${REPO_CONN}" )
local REPO_VER=$( jq -r '.version' <<< "${REPO_CONN}" )
local REPO_URL=$( jq -r '.url' <<< "${REPO_CONN}" )
local bMissingWhip=false
local bMissingJq=false
local bMissingCurl=false
local bMissingWget=false
local bMissingNotify=false
local bMissingYad=false
local bMissingGPG=false
local bMissingRepo=false
for i in {1..4}
do
progress=$(( $progress + $(( $RANDOM % 2 + 1 )) ))
echo -e "XXX\n${progress}\nInitializing Dependencies\nXXX"
sleep 0.$(( 100 + RANDOM % 800 ))
done
# require whiptail
if ! [ -x "$(command -v whiptail)" ]; then
bMissingWhip=true
fi
# require jq (read json)
if ! [ -x "$(command -v jq)" ]; then
bMissingJq=true
fi
# require curl
if ! [ -x "$(command -v curl)" ]; then
bMissingCurl=true
fi
# require wget
if ! [ -x "$(command -v wget)" ]; then
bMissingWget=true
fi
# require notify-send
if ! [ -x "$(command -v notify-send)" ]; then
bMissingNotify=true
fi
# require yad
if ! [ -x "$(command -v yad)" ]; then
bMissingYad=true
fi
##--------------------------------------------------------------------------
# Missing proteus-apt-repo gpg key
#
# NOTE: apt-key has been deprecated
# sudo add-apt-repository -y "deb [arch=amd64] https://raw.githubusercontent.com/${app_repo_dev}/${app_repo_apt}/master focal main" >/dev/null
##--------------------------------------------------------------------------
if ! [ -f "/usr/share/keyrings/${app_repo_apt_pkg}.gpg" ]; then
bMissingGPG=true
fi
##--------------------------------------------------------------------------
# Missing proteus-apt-repo .list
##--------------------------------------------------------------------------
if ! [ -f "/etc/apt/sources.list.d/${app_repo_apt_pkg}.list" ]; then
bMissingRepo=true
fi
# Check if contains title
# If so, called from another function
if [ "$bMissingWhip" = true ] || [ "$bMissingJq" = true ] || [ "$bMissingCurl" = true ] || [ "$bMissingWget" = true ] || [ "$bMissingNotify" = true ] || [ "$bMissingYad" = true ] || [ "$bMissingGPG" = true ] || [ "$bMissingRepo" = true ] || [ -n "${OPT_DEV_NULLRUN}" ]; then
for i in {1..4}
do
progress=$(( $progress + $(( $RANDOM % 2 + 1 )) ))
echo -e "XXX\n${progress}\nDependencies Missing\nXXX"
sleep 0.$(( 100 + RANDOM % 800 ))
done
fi
##--------------------------------------------------------------------------
# missing whiptail
##--------------------------------------------------------------------------
if [ "$bMissingWhip" = true ] || [ -n "${OPT_DEV_NULLRUN}" ]; then
for i in {1..4}
do
progress=$(( $progress + $(( $RANDOM % 3 + 1 )) ))
echo -e "XXX\n${progress}\nInstalling Package: Whiptail\nXXX"
sleep 0.$(( 100 + RANDOM % 800 ))
done
if [ -z "${OPT_DEV_NULLRUN}" ]; then
sudo apt-get update -y -q >> /dev/null 2>&1
sudo apt-get install whiptail -y -qq >> /dev/null 2>&1
fi
fi
##--------------------------------------------------------------------------
# missing curl
##--------------------------------------------------------------------------
if [ "$bMissingCurl" = true ] || [ -n "${OPT_DEV_NULLRUN}" ]; then
for i in {1..4}
do
progress=$(( $progress + $(( $RANDOM % 3 + 1 )) ))
echo -e "XXX\n${progress}\nInstalling Package: Curl\nXXX"
sleep 0.$(( 100 + RANDOM % 800 ))
done
if [ -z "${OPT_DEV_NULLRUN}" ]; then
sudo apt-get update -y -q >> /dev/null 2>&1
sudo apt-get install curl -y -qq >> /dev/null 2>&1
fi
fi
##--------------------------------------------------------------------------
# missing jq
##--------------------------------------------------------------------------
if [ "$bMissingJq" = true ] || [ -n "${OPT_DEV_NULLRUN}" ]; then
for i in {1..4}
do
progress=$(( $progress + $(( $RANDOM % 3 + 1 )) ))
echo -e "XXX\n${progress}\nInstalling Package: jq\nXXX"
sleep 0.$(( 100 + RANDOM % 800 ))
done
if [ -z "${OPT_DEV_NULLRUN}" ]; then
sudo apt-get update -y -q >> /dev/null 2>&1
sudo apt-get install jq -y -qq >> /dev/null 2>&1
fi
fi
##--------------------------------------------------------------------------
# missing wget
##--------------------------------------------------------------------------
if [ "$bMissingWget" = true ] || [ -n "${OPT_DEV_NULLRUN}" ]; then
for i in {1..7}
do
progress=$(( $progress + $(( $RANDOM % 3 + 1 )) ))
echo -e "XXX\n${progress}\nInstalling Package: wget\nXXX"
sleep 0.$(( 100 + RANDOM % 800 ))
done
if [ -z "${OPT_DEV_NULLRUN}" ]; then
sudo apt-get update -y -q >> /dev/null 2>&1
sudo apt-get install wget -y -qq >> /dev/null 2>&1
fi
fi
##--------------------------------------------------------------------------
# missing notify
##--------------------------------------------------------------------------
if [ "$bMissingNotify" = true ] || [ -n "${OPT_DEV_NULLRUN}" ]; then
for i in {1..6}
do
progress=$(( $progress + $(( $RANDOM % 3 + 1 )) ))
echo -e "XXX\n${progress}\nInstalling Package: notify-send\nXXX"
sleep 0.$(( 100 + RANDOM % 800 ))
done
if [ -z "${OPT_DEV_NULLRUN}" ]; then
sudo apt-get update -y -q >> /dev/null 2>&1
sudo apt-get install libnotify-bin notify-osd -y -qq >> /dev/null 2>&1
fi
fi
##--------------------------------------------------------------------------
# missing yad
##--------------------------------------------------------------------------
if [ "$bMissingYad" = true ] || [ -n "${OPT_DEV_NULLRUN}" ]; then
for i in {1..5}
do
progress=$(( $progress + $(( $RANDOM % 2 + 1 )) ))
echo -e "XXX\n${progress}\nInstalling Package: yad\nXXX"
sleep 0.$(( 100 + RANDOM % 800 ))
done
if [ -z "${OPT_DEV_NULLRUN}" ]; then
sudo apt-get update -y -q >> /dev/null 2>&1
sudo apt-get install yad -y -qq >> /dev/null 2>&1
fi
fi
##--------------------------------------------------------------------------
# missing gpg
##--------------------------------------------------------------------------
if [ "$bMissingGPG" = true ] || [ -n "${OPT_DEV_NULLRUN}" ]; then
for i in {1..4}
do
progress=$(( $progress + $(( $RANDOM % 2 + 1 )) ))
echo -e "XXX\n${progress}\nAdding github.com/${app_repo_dev}.gpg\nXXX"
sleep 0.$(( 100 + RANDOM % 800 ))
done
if [ -z "${OPT_DEV_NULLRUN}" ]; then
sudo wget -qO - "https://github.com/${app_repo_dev}.gpg" | sudo gpg --batch --yes --dearmor -o "/usr/share/keyrings/${app_repo_apt_pkg}.gpg" >/dev/null
fi
fi
##--------------------------------------------------------------------------
# missing proteus apt repo
##--------------------------------------------------------------------------
if [ "$bMissingRepo" = true ] || [ -n "${OPT_DEV_NULLRUN}" ]; then
for i in {1..4}
do
progress=$(( $progress + $(( $RANDOM % 2 + 1 )) ))
echo -e "XXX\n${progress}\nRegistering ${app_repo_apt}\nXXX"
sleep 0.$(( 100 + RANDOM % 800 ))
done
if [ -z "${OPT_DEV_NULLRUN}" ]; then
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/${app_repo_apt_pkg}.gpg] https://raw.githubusercontent.com/${app_repo_dev}/${app_repo_apt}/master $(lsb_release -cs) ${app_repo_branch}" | sudo tee /etc/apt/sources.list.d/${app_repo_apt_pkg}.list >/dev/null
fi
for i in {1..4}
do
progress=$(( $progress + $(( $RANDOM % 2 + 1 )) ))
echo -e "XXX\n${progress}\nUpdating repo list\nXXX"
sleep 0.$(( 100 + RANDOM % 800 ))
done
if [ -z "${OPT_DEV_NULLRUN}" ]; then
sudo apt-get update -y -q >/dev/null
fi
fi
##--------------------------------------------------------------------------
# install app manager proteus file in /HOME/USER/bin/proteus
##--------------------------------------------------------------------------
if ! [ -f "$app_file_proteus" ] || [ -n "${OPT_DEV_NULLRUN}" ]; then
for i in {1..4}
do
progress=$(( $progress + $(( $RANDOM % 2 + 1 )) ))
echo -e "XXX\n${progress}\nInstalling Proteus: ${repo_url}\nXXX"
sleep 0.$(( 100 + RANDOM % 800 ))
done
if [ -z "${OPT_DEV_NULLRUN}" ]; then
sudo wget -O "${app_file_proteus}" -q "$repo_branch_uri" >/dev/null
sudo chgrp ${USER} ${app_file_proteus} >/dev/null
sudo chown ${USER} ${app_file_proteus} >/dev/null
sudo chmod u+x ${app_file_proteus} >/dev/null
fi
fi
##--------------------------------------------------------------------------
# add env path /HOME/USER/bin/
##--------------------------------------------------------------------------
envpath_add $HOME/bin
for i in {1..4}
do
progress=$(( $progress + $(( $RANDOM % 2 + 1 )) ))
echo -e "XXX\n${progress}\nRegistering ENV var: ${HOME}/bin\nXXX"
sleep 0.$(( 100 + RANDOM % 800 ))
done
echo -e "XXX\n100\nSetup Complete!\nXXX"
sleep 0.5
result="Proteus App Manager v${REPO_VER} has been installed\n\nBinary located at: ${app_file_proteus}"
echo $result > result
} | whiptail --gauge "Starting Wizard ..." 6 110 0
}
##--------------------------------------------------------------------------
# header
##--------------------------------------------------------------------------
function show_header()
{
clear
sleep 0.3
echo -e " ${BLUE}-------------------------------------------------------------------------${NORMAL}"
echo -e " ${GREEN}${BOLD} ${app_title} - v$(get_version)${NORMAL}${MAGENTA}"
echo
echo -e " This wizard will allow you to install Proteus or add the Proteus Apt"
echo -e " Repo to your system."
echo
printf '%-35s %-40s\n' " ${BOLD}${DEVGREY}PID ${NORMAL}" "${BOLD}${FUCHSIA} $$ ${NORMAL}"
printf '%-35s %-40s\n' " ${BOLD}${DEVGREY}USER ${NORMAL}" "${BOLD}${FUCHSIA} ${USER} ${NORMAL}"
echo -e " ${BLUE}-------------------------------------------------------------------------${NORMAL}"
echo
sleep 0.3
echo
}
##--------------------------------------------------------------------------
# show header
##--------------------------------------------------------------------------
show_header
sleep 1
##--------------------------------------------------------------------------
# selection menu
##--------------------------------------------------------------------------
while true; do
CHOICE=$( whiptail \
--title "Selection Menu" \
--backtitle "${app_title} v$(get_version)" \
--menu "\nMake a selection from the menu options below. To switch between SELECT and EXIT, press <TAB>.\n\nUse the arrow keys to move between options.\n\n" 22 66 3 \
--ok-button Select \
--cancel-button Exit \
"1" " Install Proteus" \
"2" " Update Proteus & Verify" \
"Q" " Quit" 3>&2 2>&1 1>&3 )
case $CHOICE in
"1")
app_setup
read -r result < result
whiptail --msgbox "$result" 13 80
;;
"2")
app_update
read -r result < result
whiptail --msgbox "$result" 13 80
;;
"Q")
exit
break 2
exit
;;
esac
status=$?
# exit
# choice returns blank
if [ -z ${CHOICE} ]; then
break 2
exit
fi
done