-
Notifications
You must be signed in to change notification settings - Fork 1
/
proteus.sh
5776 lines (4729 loc) · 184 KB
/
proteus.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
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
PATH="/bin:/usr/bin:/sbin:/usr/sbin"
echo
##--------------------------------------------------------------------------
# @author : aetherinox
# @script : Proteus App Manager
# @when : 2023-10-30 17:03:02
# @url : https://github.com/Aetherinox/proteus-app-manager
#
# requires chmod +x setup.sh
##--------------------------------------------------------------------------
##--------------------------------------------------------------------------
# load secrets file to handle Github rate limiting via a PAF.
# managed via https://github.com/settings/tokens?type=beta
##--------------------------------------------------------------------------
if [ -f secrets.sh ]; then
. ./secrets.sh
fi
##--------------------------------------------------------------------------
# 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)
ORANGE=$(tput setaf 208)
GREEN=$(tput setaf 2)
YELLOW=$(tput setaf 156)
LIME_YELLOW=$(tput setaf 190)
POWDER_BLUE=$(tput setaf 153)
BLUE=$(tput setaf 033)
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)
BOLD=$(tput bold)
NORMAL=$(tput sgr0)
BLINK=$(tput blink)
REVERSE=$(tput smso)
UNDERLINE=$(tput smul)
##--------------------------------------------------------------------------
# vars > status messages
##--------------------------------------------------------------------------
STATUS_MISS="${BOLD}${GREYL} MISS ${NORMAL}"
STATUS_SKIP="${BOLD}${GREYL} SKIP ${NORMAL}"
STATUS_OK="${BOLD}${GREEN} OK ${NORMAL}"
STATUS_FAIL="${BOLD}${RED} FAIL ${NORMAL}"
STATUS_HALT="${BOLD}${YELLOW} HALT ${NORMAL}"
##--------------------------------------------------------------------------
# vars > app
##--------------------------------------------------------------------------
if [ -x "$(command -v gnome-shell)" ]; then
sys_shell_gnome=$( gnome-shell --version | sed 's/[^0-9]*//' )
fi
if [ -x "$(command -v plasmashell)" ]; then
sys_shell_plasma=$( plasmashell --version | sed 's/[^0-9]*//' )
fi
sys_arch=$( dpkg --print-architecture )
sys_code=$( lsb_release -cs )
sys_shell_type=$( echo "$XDG_DATA_DIRS" | grep -Eo 'xfce|kde|gnome' )
app_dir_home="$HOME/bin"
app_dir_dl="$app_dir_home/downloads"
app_dir_hosts="/etc/hosts"
app_dir_swizzin="$app_dir/libraries/swizzin"
apt_dir_deb="/var/cache/apt/archives"
app_file_this=$(basename "$0")
app_file_proteus="${app_dir_home}/proteus"
app_repo_author="Aetherinox"
app_title_short="Proteus"
app_title="${app_title_short} App Manager (${app_repo_author})"
app_ver=("1" "0" "0" "7")
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_repo_url="https://github.com/${app_repo_author}/${app_repo}"
app_mnfst="https://raw.githubusercontent.com/${app_repo_author}/${app_repo}/${app_repo_branch}/manifest.json"
app_script="https://raw.githubusercontent.com/${app_repo_author}/${app_repo}/BRANCH/setup.sh"
app_dir=$PWD
app_nodejs_ver=(16 18 20)
app_php_ver=(php7.3 php7.3-fpm php7.4 php7.4-fpm php8.1 php8.1-fpm php8.2 php8.2-fpm)
app_pid_spin=0
app_pid=$BASHPID
app_queue_restart_delay=1
app_queue_url=()
app_i=0
# --------------------------------------------------------------
# vars > define passwd file
#
# generated passwords will be stored in the app bin folder
# and the perms on the file being severely restricted.
# --------------------------------------------------------------
app_dir_bin_pwd="${app_dir_home}/pwd"
app_file_bin_pwd="${app_dir_bin_pwd}/mysql.pwd"
##--------------------------------------------------------------------------
# exports
#
# GDK_BACKEND vital for running proteus in Ubuntu 23 which switches
# GNOME from x11 to Wayland as of Ubuntu 21.04 in 2021.
##--------------------------------------------------------------------------
export GDK_BACKEND=x11
export DATE=$(date '+%Y%m%d')
export YEAR=$(date +'%Y')
export TIME=$(date '+%H:%M:%S')
export ARGS=$1
export LOGS_DIR="$app_dir/logs"
export LOGS_FILE="$LOGS_DIR/proteus-${DATE}.log"
export SECONDS=0
##--------------------------------------------------------------------------
# vars > general
##--------------------------------------------------------------------------
gui_width=540
gui_height=525
gui_column="Available Packages"
gui_about="An app manager which allows you to install applications and packages with very minimal interaction."
gui_desc="Select the app / package you wish to install. Most apps will run as silent installs.\n\nStart typing or press <span color='#3477eb'><b>CTRL+F</b></span> to search for an app\n\nIf you encounter issues, review the logfile located at:\n <span color='#3477eb'><b>${LOGS_FILE}</b></span>\n\n"
##--------------------------------------------------------------------------
# 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
##--------------------------------------------------------------------------
get_version()
{
ver_join=${app_ver[*]}
ver_str=${ver_join// /.}
echo ${ver_str}
}
##--------------------------------------------------------------------------
# package exists
#
# returns if package exists at all to download or not
##--------------------------------------------------------------------------
function package_exists()
{
dpkg -l "$1" &> /dev/null
return $?
}
##--------------------------------------------------------------------------
# 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.
##--------------------------------------------------------------------------
get_version_compare_gt()
{
test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1";
}
##--------------------------------------------------------------------------
# options
#
# -d developer mode
# -h help menu
# -i install app from cli
# -n developer: null run
# -q quiet mode | logging disabled
# -s setup
# -t theme
# -u updates Proteus binary
# -v display version information
##--------------------------------------------------------------------------
opt_usage()
{
echo
printf " ${BLUE}${app_title}${NORMAL}\n" 1>&2
printf " ${GREYL}${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' " " "${0} [${GREYL}-i \"NodeJS\" --njs-ver 18${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' " " "-i, --install" "install app from cli" 1>&2
printf ' %-5s %-18s %-40s\n' " " "" " ${DEVGREY}-i \"members\"${NORMAL}" 1>&2
printf ' %-5s %-18s %-40s\n' " " " --njs-ver" "specify nodejs version to install" 1>&2
printf ' %-5s %-18s %-40s\n' " " "" " ${DEVGREY}-i \"NodeJS\" --njs-ver 18${NORMAL}" 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' " " "-q, --quiet" "quiet mode which disables logging" 1>&2
printf ' %-5s %-18s %-40s\n' " " "-t, --theme" "specify theme to use" 1>&2
printf ' %-5s %-18s %-40s\n' " " "" " Adwaita" 1>&2
printf ' %-5s %-18s %-40s\n' " " "" " Adwaita-dark" 1>&2
printf ' %-5s %-18s %-40s\n' " " "" " HighContrast" 1>&2
printf ' %-5s %-18s %-40s\n' " " "" " HighContrastInverse" 1>&2
printf ' %-5s %-18s %-40s\n' " " "-s, --setup" "install all ${app_title_short} prerequisites / dependencies" 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
}
OPT_APPS_CLI=()
while [ $# -gt 0 ]; do
case "$1" in
--php-ver*)
if [[ "$1" != *=* ]]; then shift; fi
arg="${1#*=}"
if ! [[ $(echo ${app_php_ver[@]} | grep -f -w $arg) ]]; then
php_available=$(printf " %s" "${app_php_ver[@]}")
echo -e " ${NORMAL}Bad PHP version provided."
echo -e " ${NORMAL} Enter One: ${YELLOW}${php_available}${NORMAL}"
echo -e " ${NORMAL} Example: ${LGRAY}./setup.sh -n -i php --php-ver 20${NORMAL}"
echo
exit 1
else
ARG_PHP_VER+=("${arg}")
fi
;;
--njs-ver*)
if [[ "$1" != *=* ]]; then shift; fi
arg="${1#*=}"
if ! [[ $(echo ${app_nodejs_ver[@]} | grep -f -w $arg) ]]; then
njs_available=$(printf " %s" "${app_nodejs_ver[@]}")
echo -e " ${NORMAL}Bad NodeJS version provided."
echo -e " ${NORMAL} Enter One: ${YELLOW}${njs_available}${NORMAL}"
echo -e " ${NORMAL} Example: ${LGRAY}./setup.sh -n -i NodeJS --njs-ver 20${NORMAL}"
echo
exit 1
else
ARG_NJS_VER+=("${arg}")
fi
;;
-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
;;
-i*|--install*)
if [[ "$1" != *=* ]]; then shift; fi
OPT_APP="${1#*=}"
OPT_APPS_CLI+=("${OPT_APP}")
;;
-n|--nullrun)
OPT_DEV_NULLRUN=true
echo -e " ${FUCHSIA}${BLINK}Devnull Enabled${NORMAL}"
;;
-q|--quiet)
OPT_NOLOG=true
echo -e " ${FUCHSIA}${BLINK}Logging Disabled{NORMAL}"
;;
-t*|--theme*)
if [[ "$1" != *=* ]]; then shift; fi
OPT_THEME="${1#*=}"
;;
-u|--update)
OPT_UPDATE=true
;;
-s|--setup)
OPT_SETUP=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
##--------------------------------------------------------------------------
# GTK Theme
#
# Invalid themes will default to 'Adwaita'
# - Adwaita
# - Adwaita-dark
# - HighContrast
# - HighContrastInverse
# - dark
# - ZorinBlue-Light
# - ZorinBlue-Dark
# - Red
# - Green
# - Grey
# - Orange
# - Purple
#
# If we're going for support on Ubuntu and Zorin, set default to theme
# both commonly share.
#
##--------------------------------------------------------------------------
if [ -z "${OPT_THEME}" ]; then
OPT_THEME="Adwaita-dark"
fi
export GTK_THEME="${OPT_THEME}"
##--------------------------------------------------------------------------
# vars > active repo branch
##--------------------------------------------------------------------------
app_repo_branch_sel=$( [[ -n "$OPT_BRANCH" ]] && echo "$OPT_BRANCH" || echo "$app_repo_branch" )
##--------------------------------------------------------------------------
# vars > /etc/hosts
#
# this is for users who want to add new entries in their host file
# for programs like pihole.
# once an entry has been added, it will not be re-added if you use the
# script and install this multiple times.
#
# do not remove the \t in between the IP and domain. those characters
# symbolize [TAB] when actually added to the hosts file.
##--------------------------------------------------------------------------
hosts="
127.0.0.5\tdevice.name.domain
127.0.0.6\tdevice.name.domain
127.0.0.7\tdevice.name.domain
"
##--------------------------------------------------------------------------
# vars > tor
#
# tor related websites
##--------------------------------------------------------------------------
tor_website_addr="4tth4kzmipldb5elklravakdwlnte3ck6m5ahl73nfbe6ni67zmyvxyd.onion"
tor_website_path="/var/www/html"
##--------------------------------------------------------------------------
# vars > netplan
#
# these settings are related to the netplan tweak.
# this action renames your network device from whatever the default
# may be over to 'eth0'.
#
# it will also assign a specified static IP address to your network
# adapter, as well as the default gateway. these are useful if you plan
# on running a pihole server.
#
# finally, it will set your network adapter to use Quad9's DNS servers
# Malware Blocking, DNSSEC Validation
#
# if you wish to use alternative Quad9 servers for No Malware Blocking
# or ECS, the list is provided below
#
# [ QUAD9 DNS ] DEFAULT
#
# Malware Blocking, DNSSEC Validation (most typical configuration)
# IPv4 Primary: 9.9.9.9
# IPv4 Secondary: 149.112.112.112
# IPv6 Primary: 2620:fe::fe
# IPv6 Secondary: 2620:fe::9
#
# Secured w/ECS: Malware blocking, DNSSEC Validation, ECS enabled
# IPv4 Primary: 9.9.9.11
# IPv4 Secondary: 149.112.112.11
# IPv6 Primary: 2620:fe::11
# IPv6 Secondary: 2620:fe::fe:11
#
# Unsecured: No Malware blocking, no DNSSEC validation (experts only!)
# IPv4 Primary: 9.9.9.10
# IPv4 Secondary: 149.112.112.10
# IPv6 Primary: 2620:fe::10
# IPv6 Secondary: 2620:fe::fe:10
#
# [ CLOUDFLARE ] DNSSEC
#
# IPv4 Primary: 1.1.1.1
# IPv4 Secondary: 1.0.0.1
# IPv6 Primary: 2606:4700:4700::1111
# IPv6 Secondary: 2606:4700:4700::1001
#
# [ COMODO ] DNSSEC
#
# IPv4 Primary: 8.26.56.26
# IPv4 Secondary: 8.20.247.20
#
# [ DNS.WATCH ]
#
# IPv4 Primary: 84.200.69.80
# IPv4 Secondary: 84.200.70.40
# IPv6 Primary: 2001:1608:10:25::1c04:b12f
# IPv6 Secondary: 2001:1608:10:25::9249:d69b
#
# [ GOOGLE ] ECS, DNSSEC
#
# IPv4 Primary: 1.1.1.1
# IPv4 Secondary: 1.0.0.1
# IPv6 Primary: 2606:4700:4700::1111
# IPv6 Secondary: 2606:4700:4700::1001
#
# [ OPENDNS ] DNSSEC
#
# IPv4 Primary: 208.67.222.222
# IPv4 Secondary: 208.67.220.220
# IPv6 Primary: 2620:119:35::35
# IPv6 Secondary: 2620:119:53::53
#
# [ LEVEL3 ]
#
# IPv4 Primary: 209.244.0.3
# IPv4 Secondary: 209.244.0.4
# IPv6 Primary: 2620:119:35::35
# IPv6 Secondary: 2620:119:53::53
#
##--------------------------------------------------------------------------
netplan_adapt_old=enp0s3
netplan_adapt_new=eth0
netplan_ip_static=192.168.0.10/24
netplan_ip_gateway=192.168.0.1
netplan_dns_1=9.9.9.9
netplan_dns_2=149.112.112.112
netplan_macaddr=$( cat /sys/class/net/$netplan_adapt_old/address 2> /dev/null )
##--------------------------------------------------------------------------
# arrays
#
# stores the list of apps to populate list
##--------------------------------------------------------------------------
apps=()
devs=()
##--------------------------------------------------------------------------
# line > comment
#
# comment REGEX FILE [COMMENT-MARK]
# comment "skip-grant-tables" "/etc/mysql/my.cnf"
##--------------------------------------------------------------------------
line_comment()
{
local regx="${1:?}"
local targ="${2:?}"
local mark="${3:-#}"
sudo sed -ri "s:^([ ]*)($regx):\\1$mark\\2:" "$targ"
}
##--------------------------------------------------------------------------
# line > uncomment
#
# uncomment REGEX FILE [COMMENT-MARK]
# uncomment "skip-grant-tables" "/etc/mysql/my.cnf"
##--------------------------------------------------------------------------
line_uncomment()
{
local regx="${1:?}"
local targ="${2:?}"
local mark="${3:-#}"
sudo sed -ri "s:^([ ]*)[$mark]+[ ]?([ ]*$regx):\\1\\2:" "$targ"
}
##--------------------------------------------------------------------------
# func > logs > begin
##--------------------------------------------------------------------------
Logs_Begin()
{
if [ $OPT_NOLOG ] ; then
echo
echo
printf '%-57s' " Logging for this manager has been disabled."
echo
echo
sleep 3
else
mkdir -p $LOGS_DIR
LOGS_PIPE=${LOGS_FILE}.pipe
# get name of display in use
local display=":$(ls /tmp/.X11-unix/* | sed 's#/tmp/.X11-unix/X##' | head -n 1)"
# get user using display
local user=$(who | grep '('$display')' | awk '{print $1}' | head -n 1)
if ! [[ -p $LOGS_PIPE ]]; then
mkfifo -m 775 $LOGS_PIPE
printf "%-57s\n" "${TIME} Creating new pipe ${LOGS_PIPE}" | tee -a "${LOGS_FILE}" >/dev/null
fi
LOGS_OBJ=${LOGS_FILE}
exec 3>&1
tee -a ${LOGS_OBJ} <$LOGS_PIPE >&3 &
app_pid_tee=$!
exec 1>$LOGS_PIPE
PIPE_OPENED=1
printf "%-57s\n" "${TIME} Logging to ${LOGS_OBJ}" | tee -a "${LOGS_FILE}" >/dev/null
printf "%-57s\n" "${TIME} Software : ${app_title}" | tee -a "${LOGS_FILE}" >/dev/null
printf "%-57s\n" "${TIME} Version : v$(get_version)" | tee -a "${LOGS_FILE}" >/dev/null
printf "%-57s\n" "${TIME} Process : $$" | tee -a "${LOGS_FILE}" >/dev/null
printf "%-57s\n" "${TIME} OS : ${OS}" | tee -a "${LOGS_FILE}" >/dev/null
printf "%-57s\n" "${TIME} OS VER : ${OS_VER}" | tee -a "${LOGS_FILE}" >/dev/null
printf "%-57s\n" "${TIME} DATE : ${DATE}" | tee -a "${LOGS_FILE}" >/dev/null
printf "%-57s\n" "${TIME} TIME : ${TIME}" | tee -a "${LOGS_FILE}" >/dev/null
fi
}
##--------------------------------------------------------------------------
# func > logs > finish
##--------------------------------------------------------------------------
Logs_Finish()
{
if [ ${PIPE_OPENED} ] ; then
exec 1<&3
sleep 0.2
ps --pid $app_pid_tee >/dev/null
local pipe_status=$?
if [ $pipe_status -eq 0 ] ; then
# using $(wait $app_pid_tee) would be better
# however, some commands leave file descriptors open
sleep 1
kill $app_pid_tee >> $LOGS_FILE 2>&1
fi
printf "%-57s\n" "${TIME} Destroying Pipe ${LOGS_PIPE} (${app_pid_tee})" | tee -a "${LOGS_FILE}" >/dev/null
rm $LOGS_PIPE
unset PIPE_OPENED
fi
duration=$SECONDS
elapsed="$(($duration / 60)) minutes and $(($duration % 60)) seconds elapsed."
printf "%-57s\n" "${TIME} User Input: OnClick ......... Exit App" | tee -a "${LOGS_FILE}" >/dev/null
printf "%-57s\n\n\n\n" "${TIME} ${elapsed}" | tee -a "${LOGS_FILE}" >/dev/null
}
##--------------------------------------------------------------------------
# Begin Logging
##--------------------------------------------------------------------------
Logs_Begin
##--------------------------------------------------------------------------
# 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 "\n%-57s\n\n" "${TIME} SUDO [SIGN-IN]: Welcome, ${USER}" | tee -a "${LOGS_FILE}" >/dev/null
else
printf "\n%-57s\n\n" "${TIME} SUDO Failure: Wrong Password x3" | tee -a "${LOGS_FILE}" >/dev/null
exit 1
fi
else
if [ -n "${USER}" ]; then
printf "\n%-57s\n\n" "${TIME} SUDO [EXISTING]: $USER" | tee -a "${LOGS_FILE}" >/dev/null
fi
fi
##--------------------------------------------------------------------------
# header > with comment
##--------------------------------------------------------------------------
show_header_comment()
{
local reason=$([ "${1}" ] && echo "${1}" || echo "Not Specified" )
clear
sleep 0.3
echo -e " ${BLUE}-------------------------------------------------------------------------${NORMAL}"
echo -e " ${YELLOW}${reason}"${NORMAL}
echo -e " ${BLUE}-------------------------------------------------------------------------${NORMAL}"
echo
sleep 0.3
echo -e " ${BOLD}${NORMAL}Waiting on selection ..." >&2
echo
}
##--------------------------------------------------------------------------
# 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 > spinner > halt
##--------------------------------------------------------------------------
spinner_halt()
{
if ps -p $app_pid_spin > /dev/null
then
kill -9 $app_pid_spin 2> /dev/null
printf "\n%-57s\n" "${TIME} KILL Spinner: PID (${app_pid_spin})" | tee -a "${LOGS_FILE}" >/dev/null
fi
}
##--------------------------------------------------------------------------
# func > cli selection menu
##--------------------------------------------------------------------------
cli_options()
{
opts_show()
{
local it=$1
for i in ${!CHOICES[*]}; do
if [[ "$i" == "$it" ]]; then
tput rev
printf '\e[1;33m'
printf '%4d. \e[1m\e[33m %s\t\e[0m\n' $i "${LIME_YELLOW} ${CHOICES[$i]} "
tput sgr0
else
printf '\e[1;33m'
printf '%4d. \e[1m\e[33m %s\t\e[0m\n' $i "${LIME_YELLOW} ${CHOICES[$i]} "
fi
tput cuf 2
done
}
tput civis
it=0
tput cuf 2
opts_show $it
while true; do
read -rsn1 key
local escaped_char=$( printf "\u1b" )
if [[ $key == $escaped_char ]]; then
read -rsn2 key
fi
tput cuu ${#CHOICES[@]} && tput ed
tput sc
case $key in
'[A' | '[C' )
it=$(($it-1));;
'[D' | '[B')
it=$(($it+1));;
'' )
return $it && exit;;
esac
local min_len=0
local farr_len=$(( ${#CHOICES[@]}-1))
if [[ "$it" -lt "$min_len" ]]; then
it=$(( ${#CHOICES[@]}-1 ))
elif [[ "$it" -gt "$farr_len" ]]; then
it=0
fi
opts_show $it
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.
##--------------------------------------------------------------------------
open_url()
{
local URL="$1"
xdg-open $URL || firefox $URL || sensible-browser $URL || x-www-browser $URL || gnome-open $URL
}
##--------------------------------------------------------------------------
# func > cmd title
##--------------------------------------------------------------------------
title()
{
printf '%-57s' " ${1}"
sleep 0.3
}
##--------------------------------------------------------------------------
# func > begin action
##--------------------------------------------------------------------------
begin()
{
# start spinner
spin &
# spinner PID
app_pid_spin=$!
printf "%-57s\n\n" "${TIME} NEW Spinner: PID (${app_pid_spin})" | tee -a "${LOGS_FILE}" >/dev/null
# kill spinner on any signal
trap "kill -9 $app_pid_spin 2> /dev/null" $(seq 0 15)
printf '%-57s' " ${1}"
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}"
##--------------------------------------------------------------------------
finish()
{
arg1=${1}
spinner_halt
# if arg1 not empty
if ! [ -z "${arg1}" ]; then
assoc_uri="${get_docs_uri[$arg1]}"
app_queue_url+=($assoc_uri)
fi
}
##--------------------------------------------------------------------------
# func > exit action
##--------------------------------------------------------------------------
exit()
{
finish
clear
}
##--------------------------------------------------------------------------
# func > env path (add)
#
# creates a new file inside /etc/profile.d/ which includes the new
# proteus bin folder.
#
# export PATH="$HOME/bin:$PATH"
##--------------------------------------------------------------------------
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 repo_branch=$([ "${1}" ] && echo "${1}" || echo "${app_repo_branch}" )
local branch_uri="${app_script/BRANCH/"$repo_branch"}"
local IsSilent=${2}
begin "Updating from branch [${repo_branch}]"
sleep 1
echo
printf '%-57s' " |--- Downloading update"
sleep 1
if [ -z "${OPT_DEV_NULLRUN}" ]; then
sudo wget -O "${app_file_proteus}" -q "$branch_uri" >> $LOGS_FILE 2>&1
fi
echo -e "[ ${STATUS_OK} ]"
printf '%-57s' " |--- Set ownership to ${USER}"
sleep 1
if [ -z "${OPT_DEV_NULLRUN}" ]; then
sudo chgrp ${USER} ${app_file_proteus} >> $LOGS_FILE 2>&1
sudo chown ${USER} ${app_file_proteus} >> $LOGS_FILE 2>&1
fi
echo -e "[ ${STATUS_OK} ]"
printf '%-57s' " |--- Set perms to u+x"
sleep 1
if [ -z "${OPT_DEV_NULLRUN}" ]; then
sudo chmod u+x ${app_file_proteus} >> $LOGS_FILE 2>&1
fi
echo -e "[ ${STATUS_OK} ]"
echo
sleep 1
echo -e " ${BOLD}${GREEN}Update Complete!${NORMAL}" >&2
sleep 1
finish
}
##--------------------------------------------------------------------------
# func > app update
#
# updates the /home/USER/bin/proteus file which allows proteus to be
# ran from anywhere.
##--------------------------------------------------------------------------
if [ "$OPT_UPDATE" = true ]; then
app_update ${app_repo_branch_sel}
fi
##--------------------------------------------------------------------------
# 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
#