This repository has been archived by the owner on Aug 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 31
/
after-effects
executable file
·3474 lines (3012 loc) · 122 KB
/
after-effects
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
#!/usr/bin/env bash
# Copyright (c) 2022 Prasad Tengse
# SPDX-License-Identifier: GPL-3.0-only
# shellcheck disable=SC2059,SC2154,SC2155
set -o pipefail
function __init_core_variables() {
declare AE_RUN_VARLIST_CHECK_OUTPUT="${!AE_*}"
if [[ -n ${AE_RUN_VARLIST_CHECK_OUTPUT} ]]; then
printf "\e[31m✕ Following reserved variables are set [${AE_RUN_VARLIST_CHECK_OUTPUT}]! \e[0m \n"
printf "\e[31m✕ Script cannot continue as it might intefere with its functions! \e[0m \n"
exit 3
fi
# Script
readonly AE_SCRIPT=$(basename "$0")
# Start tik
readonly AE_EXEC_START=$(date +%s)
# Version
readonly AE_VERSION="9.3.0"
# ERR
declare -a AE_RUN_STACK_ERR
#colors for display
readonly AE_COLOR_YELLOW=$'\e[38;5;220m'
readonly AE_COLOR_GREEN=$'\e[32m'
readonly AE_COLOR_RED=$'\e[31m'
readonly AE_COLOR_NC=$'\e[0m'
# Log handler indicator
AE_RUN_FILELOGGER_ACTIVE="false"
# Handle Signals
trap term_exit_handler EXIT
trap ctrl_c_signal_handler INT
trap term_signal_handler SIGTERM TERM
# Extra colors
readonly AE_COLOR_BLUE=$'\e[38;5;159m'
readonly AE_COLOR_CYAN=$'\e[38;5;51m'
readonly AE_COLOR_ORANGE=$'\e[38;5;208m'
readonly AE_COLOR_TEAL=$'\e[38;5;192m'
readonly AE_COLOR_PINK=$'\e[38;5;212m'
readonly AE_COLOR_GRAY=$'\e[38;5;246m'
readonly AE_COLOR_LGRAY=$'\e[38;5;240m'
readonly AE_COLOR_MAGENTA=$'\e[38;5;219m'
readonly AE_RUN_BASE_DIR="$(pwd -P)"
#Initialize printf variables
readonly AE_LOG_PHASE_CORE="(CORE)"
readonly AE_LOG_PHASE_REPO="(REPO)"
readonly AE_LOG_PHASE_PPA="(PPA)"
readonly AE_LOG_PHASE_DEB="(DPKG)"
readonly AE_LOG_PHASE_APT="(APT)"
readonly AE_LOG_PHASE_APTKEY="(KEYS)"
readonly AE_LOG_PHASE_SNAP="(SNAP)"
readonly AE_LOG_PHASE_BIN="(BIN)"
}
# Signal handler
function ctrl_c_signal_handler() {
log_error "User Interrupt! CTRL-C"
exit 4
}
# Signal handler
function term_signal_handler() {
log_error "User Interrupt! SIGTERM"
exit 4
}
# Cleanup handler
function term_exit_handler() {
declare -r exit_code="$?"
if [[ $AE_RUN_ENABLE_CLEANUP_HANDLER == "true" ]]; then
declare cleanup_status=0
log_stage "Cleanup and Exit"
log_debug "Removing temporary files"
if [[ -d ${AE_RUN_TMP_DIR} ]]; then
if ! rm -f "${AE_RUN_TMP_DIR}"/*; then
cleanup_status=1
fi
if ! rmdir "${AE_RUN_TMP_DIR}"; then
cleanup_status=1
fi
fi
if [[ $cleanup_status -gt 0 ]]; then
log_error "Failed to remove temporary files"
log_error "Ignoring this error as they will be cleaned up by systemd"
fi
readonly AE_EXEC_END="$(date +%s)"
readonly AE_EXEC_TIME="$((AE_EXEC_END - AE_EXEC_START))"
log_debug "$AE_SCRIPT took $AE_EXEC_TIME seconds to complete."
if [[ ${#AE_RUN_STACK_ERR} -gt 0 ]]; then
log_error "Some Errors occured during installation!"
for i in "${!AE_RUN_STACK_ERR[@]}"; do
log_error "ERR-$((i + 1)) - ${AE_RUN_STACK_ERR[$i]}"
# error did not lead to exit but we will exit with non zero indicating error occured
# otherwise dont alter it
if [[ $exit_code -eq 0 ]]; then
exit 1
fi
done
else
log_debug "Error stack is clean :)"
fi
fi
}
function __init_logfile() {
readonly AE_LOG_FILE="${AE_RUN_BASE_DIR}/logs/after-effects.log"
local bool_created_logfile
if ! mkdir -p "${AE_RUN_BASE_DIR}/logs"; then
log_and_exit "Failed to create Failed to create logs folder" 2
fi
# tmp dir
if tmp_dir="$(mktemp -d)"; then
AE_RUN_ENABLE_CLEANUP_HANDLER="true"
else
log_and_exit "Failed to create tmp folder" 2
fi
declare -gr AE_RUN_TMP_DIR="${tmp_dir}"
# if file not exists touch it
if [[ ! -f ${AE_LOG_FILE} ]]; then
if touch "${AE_LOG_FILE}"; then
bool_created_logfile="true"
else
log_and_exit "Failed to create logfile!${AE_COLOR_NC}" 2
fi
fi
# check if logs can be written
if [[ -w $AE_LOG_FILE ]]; then
if touch "${AE_LOG_FILE}"; then
AE_RUN_FILELOGGER_ACTIVE="true"
[[ $bool_created_logfile == "true" ]] && log_debug "Created log file: ${AE_LOG_FILE}"
log_debug "Initialized logging"
else
AE_RUN_FILELOGGER_ACTIVE="false"
log_error "Failed to write to log file ${AE_LOG_FILE}"
exit 2
fi
else
log_and_exit "Log file - ${AE_LOG_FILE} is not writable!" 2
fi
}
function __logger_core() {
if [[ $# -ne 2 ]]; then
return
else
declare -r lvl="${1}"
declare -r lvl_msg="${2}"
declare -r lvl_ts="$(date)"
declare lvl_console="1"
declare lvl_prefix=" "
declare lvl_nc="${AE_COLOR_NC}"
case ${lvl} in
stage)
declare -r lvl_str="INFO"
declare -r lvl_sym="➜"
declare -r lvl_color="${AE_COLOR_MAGENTA}"
declare -r lvl_prefix=""
;;
trace)
declare -r lvl_str="VERBOSE"
declare -r lvl_sym="»"
declare -r lvl_color="${AE_COLOR_LGRAY}"
[[ ${AE_DEBUG} -lt 2 ]] && lvl_console="0"
;;
variable | var)
declare -r lvl_str="VERBOSE"
declare -r lvl_sym="»"
declare -r lvl_color="${AE_COLOR_LGRAY}"
[[ ${AE_DEBUG} -lt 2 ]] && lvl_console="0"
;;
debug)
declare -r lvl_str="DEBUG"
declare -r lvl_sym="•"
declare -r lvl_color="${AE_COLOR_GRAY}"
[[ ${AE_DEBUG} -lt 1 ]] && lvl_console="0"
;;
info)
declare -r lvl_str="INFO"
declare -r lvl_sym="•"
declare -r lvl_color=""
declare -r lvl_nc=""
declare -r lvl_console="1"
;;
success)
declare -r lvl_str="INFO"
declare -r lvl_sym="•"
declare -r lvl_color="${AE_COLOR_TEAL}"
;;
dev)
declare -r lvl_str="NOTICE"
declare -r lvl_sym="•"
declare -r lvl_color="${AE_COLOR_ORANGE}"
;;
notice)
declare -r lvl_str="NOTICE"
declare -r lvl_sym="•"
declare -r lvl_color="${AE_COLOR_CYAN}"
;;
warn | warning)
declare -r lvl_str="WARNING"
declare -r lvl_sym="•"
declare -r lvl_color="${AE_COLOR_YELLOW}"
;;
error)
declare -r lvl_str="ERROR"
declare -r lvl_sym="•"
declare -r lvl_color="${AE_COLOR_RED}"
;;
critical)
declare -r lvl_str="CRITICAL"
declare -r lvl_sym="✖"
declare -r lvl_color="${AE_COLOR_RED}"
declare -r lvl_prefix=""
;;
esac
fi
if [[ $lvl_console -eq 1 ]]; then
printf "%s%s%s %s %s\n" "${lvl_color}" "${lvl_prefix}" "${lvl_sym}" "${lvl_msg}" "${lvl_nc}"
fi
if [[ $AE_RUN_FILELOGGER_ACTIVE == "true" ]]; then
printf "%s %-25s %-10s %s\n" "${lvl_ts}" "${FUNCNAME[2]}" "[${lvl_str}]" "$lvl_msg" >>"$AE_LOG_FILE"
fi
}
function log_and_exit() {
# ARG-1 log msg
# ARG-2 exit code int
local msg="$1"
local code="${2:-1}"
__logger_core "critical" "$msg"
exit "${code}"
}
function log_info() {
__logger_core "info" "${1}"
}
function log_debug() {
__logger_core "debug" "${1}"
}
function log_success() {
__logger_core "success" "${1}"
}
function log_warn() {
__logger_core "warn" "${1}"
}
function log_stage() {
local msg="$1"
__logger_core "stage" "${msg}"
}
function log_error() {
__logger_core "error" "${1}"
}
function log_dev() {
__logger_core "dev" "${1}"
}
function log_notice() {
__logger_core "notice" "${1}"
}
function log_var() {
local var
var="$1"
__logger_core "variable" "$(printf "%-35s - %-10s\n" "${var}" "${!var}")"
}
function log_trace() {
local line msg
# This function adds time stamp to logs without using external utilities
# Output will be automatically written to $AE_LOG_FILE
# Arguments : 1
# ARG -1: printf variable for formatting the log
# Usage command | _add_timestamp_to_logs "$1"
while IFS= read -r line; do
__logger_core "trace" "$(printf "%s %s" "${1:-UNKNOWN}" "$line")"
done
}
function log_property() {
# Args (4)
# Arg 1 : Property name
# Arg 2 : Property value
# Arg 3 : log level can be 0-debug(default)
# 1-info
# 2-notice
# 3-dev
# 4-warning
# 5-error
# other defaults to debug.
# Arg 4 : Format string spacing (default=18)
local desc value fmt lvl
local __msg_string
desc="${1}"
value="${2}"
lvl="${3:-0}"
fmt="%-${4:-22}s"
__msg_string="$(printf "${fmt} : %s" "${desc}" "${value}")"
case ${lvl} in
0) __logger_core "debug" "${__msg_string}" ;;
1) __logger_core "info" "${__msg_string}" ;;
2) __logger_core "notice" "${__msg_string}" ;;
3) __logger_core "dev" "${__msg_string}" ;;
4) __logger_core "warn" "${__msg_string}" ;;
5) __logger_core "error" "${__msg_string}" ;;
*) __logger_core "debug" "${__msg_string}" ;;
esac
}
function __setup_platform_vars() {
# Function defines Script variables
# Necessary variables used by the script are initialized here. This function
# should be called first before choices are made, always.
declare -r OS_RELEASE_FILE="/etc/os-release"
if [[ -r "${OS_RELEASE_FILE}" ]]; then
log_debug "Found os-release file ${OS_RELEASE_FILE}"
# Read Version Code Name
readonly AE_DISTRO_CODENAME="$(awk '/VERSION_CODENAME=/' "${OS_RELEASE_FILE}" | sed 's/VERSION_CODENAME=//' | tr '[:upper:]' '[:lower:]')"
# Read Human Readable Full Version Name
readonly AE_DISTRO_PRETTY_NAME="$(awk '/PRETTY_NAME=/' "${OS_RELEASE_FILE}" | sed 's/PRETTY_NAME=//' | tr -d '"')"
# Read Human Readable Distro Name
readonly AE_DISTRO_NAME="$(awk '/^NAME=/' "${OS_RELEASE_FILE}" | sed 's/^NAME=//' | tr -d '"')"
else
log_and_exit "Script cannot determine distro/codename!" "5"
fi
declare -r architecture="$(uname -m)"
case "${architecture}" in
x86_64)
log_debug "Architecture is 64 bit."
readonly AE_ARCH="amd64"
;;
armv7* | armv8*)
log_debug "Running on ARM CPU with HW Floating point Processor"
readonly AE_ARCH="armhf"
;;
aarch64 | arm64)
log_debug "This is an ARM64. Please be advised that not all repositories support this arch."
readonly AE_ARCH="arm64"
;;
*)
log_and_exit "Unsupported Architecture. ${architecture}" "11"
;;
esac
readonly AE_APT_KEYRINGS_DIR=/usr/share/keyrings
# etc sources list dir
readonly AE_APT_SOURCES_DIR=/etc/apt/sources.list.d
#-------------------------- Release codenames --------------------------------------
readonly AE_UBUNTU_CODENAME_LATEST="mantic"
# 404 is a placeholder which is set when there are
# no suitable releases which can use this feature or
# the release is unknown or too early in developement.
readonly AE_UBUNTU_CODENAME_UPCOMING="noble"
readonly AE_UBUNTU_CODENAME_LATEST_LTS="jammy"
readonly AE_DEBIAN_CODENAME_LATEST="bookworm"
readonly AE_DEBIAN_CODENAME_UPCOMING="trixie"
#============================ Switches/ booleans & Vars ================================
# Allow repo fixes for Upcoming releases of ubuntu and its derivatives.
AE_RUN_FIX_UPCOMING="false"
# By default version checks are enabled
AE_RUN_VERSION_CHECK="true"
# Not used
# readonly AE_DEPRECATED_VERSION_URL="https://ae.prasadt.com/get/v3/version"
# Purge not required packages
# Default is false
# Requires command line option -d to be passed via command line otherwise it will not work.
# Set this to true if you don't want to pass -d every time
AE_RUN_CONFIG_FLAG_PURGE="false"
# Keep Downloaded DEB packages
AE_RUN_CONFIG_FLAG_PRESERVE_PKGS="false"
#
# ================================================================================== #
# Achtung!
# Do not change any of the variables below this if you don't know what they do.
# They are essential for correct working of the script.
# Check Debian Flags
AE_RUN_IS_DEBIAN="false"
# Boolean to hold if --pre-release was applied
AE_RUN_FIX_ACTIVE="false"
}
function delete_log_file() {
printf "➜ Deleting log file\n"
if rm "${AE_RUN_BASE_DIR}/logs/after-effects.log"; then
printf "${AE_COLOR_GREEN}• Done${AE_COLOR_NC}\n"
exit 0
else
printf "${AE_COLOR_RED}• Failed!${AE_COLOR_NC}\n"
exit 1
fi
}
# Checks if command is available
function has_command() {
if command -v "$1" >/dev/null; then
return 0
else
return 1
fi
return 1
}
function __print_runtime_info() {
# This function logs and displays the Necessary details which helps in debugging.
if has_command hostname; then
log_property "Hostname" "$(hostname)" 1
else
log_property "Hostname" "UNKNOWN"
fi
log_property "OS" "${AE_DISTRO_PRETTY_NAME}" 1
log_property "Distribution" "${AE_DISTRO_NAME}" 1
log_property "Release" "${AE_DISTRO_CODENAME}" 1
log_property "Architecture" "${AE_ARCH}" 1
log_property "Version" "${AE_VERSION}" 1
log_property "AE_APT_SOURCES_DIR" "${AE_APT_SOURCES_DIR}"
log_property "AE_APT_KEYRINGS_DIR" "${AE_APT_KEYRINGS_DIR}"
log_property "AE_RUN_BASE_DIR" "${AE_RUN_BASE_DIR}"
log_property "AE_LOG_FILE" "${AE_LOG_FILE}"
}
function _check_dependencies() {
#Checks if commands in array are available.
# Accepts one argument as array.
local dependencies=("$@")
local dependency_check_failed_count dependency
dependency_check_failed_count=0
for dependency in "${dependencies[@]}"; do
if has_command "$dependency" >/dev/null; then
log_property "${dependency}" "INSTALLED"
else
log_property "$dependency" "MISSING"
dependency_check_failed_count=$((dependency_check_failed_count + 1))
fi
done
if [ "$dependency_check_failed_count" -gt 0 ]; then
return 1
else
return 0
fi
}
function _eol_message() {
# Display EOL Message and upgrade instruction URLs.
# Arguments: 1
# ARG 1: EOL Date
log_and_exit "${AE_DISTRO_PRETTY_NAME} is no longer supported. ($1)." "12"
}
function _usup_message() {
log_and_exit "${AE_DISTRO_PRETTY_NAME} is not supported by the script." "12"
}
function _fix_ubuntu_derivatives() {
# Some Ubuntu based distributions use their own codename (Linux mint, Elementary)
# Some repositories require that ubuntu codename is used.
# This function fixes that for
# Linux Mint 20.x : Ubuntu 20.04 Xenial,
# Linux Mint 19.x : Ubuntu 18.04 Xenial,
# Elementary OS Juno,Hera: Ubuntu 18.04 Xenial
# Pop!_OS uses Ubuntu codenames (No need to apply fix)
# KDE Neon, Bodhi, Peppermint use Ubuntu codenames
# If the release is not known this function exits the script for safety.
log_stage "Checking for Ubuntu derivates/Debian"
log_var "AE_DISTRO_CODENAME"
declare -g AE_RUN_CODENAME="$AE_DISTRO_CODENAME"
log_var "AE_RUN_CODENAME"
case ${AE_RUN_CODENAME} in
noble)
readonly AE_RUN_DISTRO_NAME="ubuntu"
log_warn "Release is Ubuntu 24.04 Noble Numbat"
;;
# Ubuntu 23.10 and its derivatives
mantic)
readonly AE_RUN_DISTRO_NAME="ubuntu"
log_warn "Release is Ubuntu 23.14 Mantic Minotaur"
;;
# Ubuntu 23.04 and its derivatives
lunar)
readonly AE_RUN_DISTRO_NAME="ubuntu"
log_info "Release is Ubuntu 23.04 Lunar Lobster"
;;
# Ubuntu 22.04 and its derivatives
jammy)
readonly AE_RUN_DISTRO_NAME="ubuntu"
log_info "Release is Ubuntu 22.04 LTS Jammy Jellyfish"
;;
venessa | vera | victoria)
log_info "This is Linux-Mint 21.X."
log_info "Setting additional repositories to follow Ubuntu 22.04."
AE_RUN_CODENAME="jammy"
readonly AE_RUN_DISTRO_NAME="ubuntu"
log_success "Changed codename to $AE_RUN_CODENAME"
;;
# Ubuntu 20.04 and its derivatives
focal)
readonly AE_RUN_DISTRO_NAME="ubuntu"
log_info "This is latest LTS release of Ubuntu"
log_success "Keeping the codename as $AE_RUN_CODENAME."
;;
ulyana | ulyssa | uma | una)
log_info "Release is Linux Mint 20.X."
log_info "Setting additional repositories to follow Ubuntu 20.04."
AE_RUN_CODENAME="focal"
readonly AE_RUN_DISTRO_NAME="ubuntu"
readonly AE_RUN_SNAP_REMOVE_APT_BLOCK="true"
log_success "Changed codename to $AE_RUN_CODENAME"
;;
odin)
log_info "Release is elementaryOS 6 - Odin."
log_info "Setting additional repositories to follow Ubuntu 20.04."
AE_RUN_CODENAME="focal"
readonly AE_RUN_DISTRO_NAME="ubuntu"
log_success "Changed codename to $AE_RUN_CODENAME"
;;
jolnir)
log_info "Release is elementaryOS 6.1 - Jólnir."
log_info "Setting additional repositories to follow Ubuntu 20.04."
AE_RUN_CODENAME="focal"
readonly AE_RUN_DISTRO_NAME="ubuntu"
log_success "Changed codename to $AE_RUN_CODENAME"
;;
horus)
log_info "Release is elementaryOS 7 - Horus."
log_info "Setting additional repositories to follow Ubuntu 22.04."
AE_RUN_CODENAME="jammy"
readonly AE_RUN_DISTRO_NAME="ubuntu"
log_success "Changed codename to $AE_RUN_CODENAME"
;;
bullseye)
AE_RUN_IS_DEBIAN="true"
readonly AE_RUN_DISTRO_NAME="debian"
log_notice "This is Debian 11 Bullseye. PPAs are disabled."
;;
bookworm)
AE_RUN_IS_DEBIAN="true"
readonly AE_RUN_DISTRO_NAME="debian"
log_notice "This is Debian 12 Bookworm. PPAs are disabled."
;;
trixie)
AE_RUN_IS_DEBIAN="true"
readonly AE_RUN_DISTRO_NAME="debian"
log_dev "You are running Debian Testing!"
log_notice "This is Debian Trixie. PPAs are disabled."
;;
# Unsupported releases
kinetic) _usup_message ;;
buster) _usup_message ;;
stretch) _eol_message "June 30, 2022" ;;
bionic) _eol_message "April 2023" ;;
tara | tessa | tina | tricia) _eol_message "April 2023" ;;
juno | hera) _eol_message "April 2023" ;;
*)
log_and_exit "Unknown or unsupported release($AE_RUN_CODENAME) !" "16"
;;
esac
log_success "Applied release specific settings and fixes."
log_var "AE_RUN_CODENAME"
# Save a copy of AE_RUN_CODENAME
# shellcheck disable=SC2034
declare -gr AE_BASE_CODENAME="${AE_RUN_CODENAME}"
log_var "AE_BASE_CODENAME"
log_var "AE_RUN_IS_DEBIAN"
}
function __not_connected_to_internet() {
log_error "You are not connected to the Internet!. "
log_error "Please check your Internet connection and try again."
log_and_exit "No internet connection!" "14"
}
function __test_internet() {
# Function to check internet connection
log_info "Checking connectivity"
if has_command wget; then
if wget -q -O /dev/null http://www.gstatic.com/generate_204 2>&1 | log_trace "${AE_LOG_PHASE_CORE}"; then
log_success "Connected!"
else
__not_connected_to_internet
fi
elif has_command curl; then
if curl -sSfL -o /dev/null http://www.gstatic.com/generate_204 2>&1 | log_trace "${AE_LOG_PHASE_CORE}"; then
log_success "Connected!"
else
__not_connected_to_internet
fi
else
log_and_exit "No wget or curl command found!" "15"
fi
}
function _test_conflicting_apps() {
# Function checks if any apps like syanptic aptitude are running.
local lock
for lock in synaptic update-manager software-center apt-get dpkg aptitude; do
# shellcheck disable=SC2009
if ps -U root -u root u | grep $lock | grep -v grep >/dev/null; then
log_and_exit "Installation won't work. Please close $lock first then try again." "15"
else
log_property "$lock" "not running"
fi
done
log_success "No conflicts detected"
}
function parse_yaml() {
local yaml_file="${1}"
local prefix="${2}"
local s
local w
local fs
s='[[:space:]]*'
w='[a-zA-Z0-9_.-]*'
fs="$(echo @ | tr @ '\034')"
(
#shellcheck disable=SC1003
sed -e '/- [^\"]'"[^\']"'.*: /s|\([ ]*\)- \([[:space:]]*\)|\1-\'$'\n'' \1\2|g' |
sed -ne '/^--/s|--||g; s|\"|\\\"|g; s/[[:space:]]*$//g;' \
-e "/#.*[\"\']/!s| #.*||g; /^#/s|#.*||g;" \
-e "s|^\($s\)\($w\)$s:$s\"\(.*\)\"$s\$|\1$fs\2$fs\3|p" \
-e "s|^\($s\)\($w\)${s}[:-]$s\(.*\)$s\$|\1$fs\2$fs\3|p" |
awk -F"$fs" '{
indent = length($1)/2;
if (length($2) == 0) { conj[indent]="+";} else {conj[indent]="";}
vname[indent] = $2;
for (i in vname) {if (i > indent) {delete vname[i]}}
if (length($3) > 0) {
vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])("__")}
printf("%s%s%s%s=(\"%s\")\n", "'"$prefix"'",vn, $2, conj[indent-1],$3);
}
}' |
sed -e 's/_=/+=/g' |
awk 'BEGIN {
FS="=";
OFS="="
}
/(-|\.).*=/ {
gsub("-|\\.", "_", $1)
}
{ print }'
) <"$yaml_file"
}
function _get_remote_file() {
# Function to get remote file/response
# exits script if it fails.
# Accepts 2 arguments.
# ARG 1: File name; Name of the local file the response or file should be saved as.
# ARG 2: URL to the file
local file_name="${1}"
local exit_status
local file_url="${2}"
log_property "URL is set to" "${file_url}"
if [[ $# -eq 2 ]]; then
# Remote files
if has_command wget; then
log_debug "Fetch handler is wget"
wget -q "${file_url}" -O "$file_name" 2>&1 | log_trace "${AE_LOG_PHASE_CORE}"
exit_status="$?"
elif has_command curl; then
log_debug "Fetch handler is curl"
curl -sSfL "${file_url}" --output "$file_name" 2>&1 | log_trace "${AE_LOG_PHASE_CORE}"
exit_status="$?"
else
log_and_exit "No handlers available for fetching remote data!" "28"
fi
log_property "Exit code" "$exit_status"
if [[ $exit_status -ne 0 ]]; then
log_error "Something went wrong while retrieving ${file_name}."
log_and_exit "Error Getting file." "28"
fi
else
log_and_exit "Invalid number of arguments <_get_remote_file> Requires 2, got $#." "19"
fi
}
function compare_versions() {
# Function to compare two semver version strings.
#
# REQUIRED ARGUMENTS:
# Accepts two arguments both of which are semver version strings.
#
# ARG1 - CURRENT_SEMVER. Usually obtained from
# a) Within the script
# b) Executing {binary} --version --short
# c) Version marker files from ~/bin or /usr/share/vmark-files/{binary}
# d) Package manager's metadata
# ARG2 - UPSTREAM_SEMVER. Usually obtained from
# a) Upcheck API endpoint
# b) GitHub releases API
# This function will NOT handle fetching/reading these values.
#
# DEPENDENCIES: One of the following is required.
# a) 'sh-logger' snippet from tprasadtp/templates repository.
# b) 'log_debug' function. Minimum dummy implementation is below.
# ```bash
# function log_debug(){}
# ```
# LOGGING: All logs generated by this function are at debug level (handled by `log_debug`).
# Compares CURRENT_SEMVER and UPSTREAM_SEMVER mostly according to semver specs and
# Returns RESULTS:
# If CURRENT_SEMVER > UPSTREAM_SEMVER return value is 2. (no update required)
# If CURRENT_SEMVER < UPSTREAM_SEMVER return value is 1. (update is required)
# If CURRENT_SEMVER == UPSTREAM_SEMVER return value is 0. (no update required)
# ERRORS:
# a) 21 - CURRENT_SEMVER is invalid
# b) 22 - UPSTREAM_SEMVER is invalid
# c) 10 - 'log_debug' function is not defined
# d) 30 - For some reason, evaluation isn't completed
# e) 40 - Unhadled condition.
#
# NOTES:
# Please note that return values 21 and 22 indicates version is not compliant accoring
# to our versioning policy. It might be a valid semver according to semver specs,
# but is non compliant with our tagging policy, which follows
# MAJOR.MINOR.PATCH-<PRERELEASE_IDENTIFIER>.<PRERELEASE_VERSION>
# For pre releases, PRERELEASE_IDENTIFIER can be 'alpha', 'beta' or 'rc' with an
# optional <PRERELEASE_VERSION> which MUST be a non negative integer.
# Check if log_debug function is defined
if ! declare -F "log_debug" >/dev/null; then
return 10
fi
# Define semver regex according to policy tprasadtp/templates/semver-regex.md
declare -r SEMVER_REGEX="^[vV]?(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(\-(alpha|beta|rc)(\.(0|[1-9][0-9]*))?)?\$"
local current_semver upstream_semver
current_semver="$1"
upstream_semver="$2"
log_debug "Current version : ${current_semver}"
log_debug "Upstream version : ${upstream_semver}"
local current_major current_minor current_patch current_pre current_pre_num
local upstream_major upstream_minor upstream_patch upstream_pre upstream_pre_num
# Parse current semver
if [[ $current_semver =~ $SEMVER_REGEX ]]; then
current_major="${BASH_REMATCH[1]}"
current_minor="${BASH_REMATCH[2]}"
current_patch="${BASH_REMATCH[3]}"
current_pre="${BASH_REMATCH[5]}"
current_pre_num="${BASH_REMATCH[7]}"
log_debug "Parsed version (current) -> major:${current_major} minor:${current_minor} patch:${current_patch} pre:${current_pre} prenum:${current_pre_num}"
else
return 21
fi
# Parse upstream semver.
if [[ ${upstream_semver} =~ $SEMVER_REGEX ]]; then
upstream_major="${BASH_REMATCH[1]}"
upstream_minor="${BASH_REMATCH[2]}"
upstream_patch="${BASH_REMATCH[3]}"
upstream_pre="${BASH_REMATCH[5]}"
upstream_pre_num="${BASH_REMATCH[7]}"
log_debug "Parsed version (upstream) -> major:${upstream_major} minor:${upstream_minor} patch:${upstream_patch} pre:${upstream_pre} prenum:${upstream_pre_num}"
else
return 22
fi
# Compare semver versions
# Major version
if [[ ${upstream_major} -gt ${current_major} ]]; then
log_debug "Upstream release is newer than current ${upstream_major} > ${current_major} (major)"
return 1
elif [[ ${upstream_major} -lt ${current_major} ]]; then
log_debug "Current version is newer than upstream available ${upstream_major} < ${current_major} (major)"
return 2
fi
# Minor version
# This will only be executed if MAJOR versions match.
if [[ ${upstream_minor} -gt ${current_minor} ]]; then
log_debug "Upstream release is newer than current ${upstream_minor} > ${current_minor} (minor)"
return 1
elif [[ ${upstream_minor} -lt ${current_minor} ]]; then
log_debug "Current version is newer than upstream available ${upstream_minor} < ${current_minor} (minor)"
return 2
fi
# Patch version
# This will only be executed if MAJOR AND MINOR versions match.
if [[ ${upstream_patch} -gt ${current_patch} ]]; then
log_debug "Upstream release is newer than current ${upstream_patch} > ${current_patch} (patch)"
return 1
elif [[ ${upstream_patch} -lt ${current_patch} ]]; then
log_debug "Current version is newer than upstream available ${upstream_patch} < ${current_patch} (patch)"
return 2
fi
# What follows below is the mess of somewhat following semver specs.
log_debug "Major, Minor and Patch version match."
# Check if pre release strings are present in one of the versions. whichever lacks pre release string
# is the upstream one. For Eg. 2.3.6-beta.1 < 2.3.6
# upstream version has NO pre release fields but current one DOES
# current: 2.2.2-rc.1 upstream: 2.2.2, then upstream is newer.
if [[ -z ${upstream_pre} ]] && [[ -n $current_pre ]]; then
log_debug "Upstream version has no pre release fields, it is newer!"
return 1
# upstream version HAS prerelease fields but current one DOES NOT
# current: 2.2.2 upstream: 2.2.2-rc.1, then current is newer.
elif [[ -n ${upstream_pre} ]] && [[ -z $current_pre ]]; then
log_debug "Current version has no pre release fields, it is newer!"
return 2
fi
# We do not follow complete semver specs.
# This is done for simplicity. All our versioning policies only include
# pre release tags of format MAJOR.MINOR.PATCH-<PRERELEASE_IDENTIFIER>.<PRERELEASE_VERSION>
# In our policies its strictly forbidden to include build numbers and build identifiers in
# the tags created. We only embed build number information in
# execultables themeselves or as packaging metadata like docker labels.
# In case of pre release versions, we only have <PRERELEASE_IDENTIFIER>.<PRERELEASE_VERSION>
# or <PRERELEASE_IDENTIFIER>. Thus, all other cases are ignored.
# Check if pre release identifiers match.
# Spec 11.4.2
# Identifiers with letters or hyphens are compared lexically in ASCII sort order.
if [[ $upstream_pre > $current_pre ]]; then
log_debug "Upstream pre release identider is lexographically greater than current one.(prerelease)"
return 1
elif [[ $upstream_pre < $current_pre ]]; then
log_debug "Current pre release identider is lexographically greater than upstream one.(prerelease)"
return 2
else
log_debug "Current and upstream pre release identifiers match"
fi
# Spec 11.4.4: A larger set of pre-release fields has a higher precedence than a smaller set,
# if all of the preceding identifiers are equal.
# check if both PRERELEASE_VERSION fields are empty, if so both versions are equal.
if [[ -z $upstream_pre_num ]] && [[ -z $current_pre_num ]]; then
log_debug "pre-release version identifiers are empty for both fields. (all)"
return 0
fi
# upstream version has pre release version field but current one doesnt
# current: 2.2.2-rc upstream: 2.2.2.rc.1, then upstream is newer.
if [[ -z ${upstream_pre_num} ]] && [[ -n $current_pre_num ]]; then
log_debug "Upstream has pre release number but current one does not. Upstream is newer (prerelease-num)"
return 1
# upstream version has lacks pre release version field but current one does
# current: 2.2.2-rc.1 upstream: 2.2.2.rc, then current is newer.
elif [[ -n ${upstream_pre_num} ]] && [[ -z $upstream_pre_num ]]; then
log_debug "Current version pre release number but current one does not. Current version is newer. (prerelease-num)"
return 2
fi
if [[ ${upstream_pre_num} -gt ${current_pre_num} ]]; then
log_debug "Upstream release is newer than current ${upstream_pre_num} > ${current_pre_num} (prerelease-num)"
return 1
elif [[ ${upstream_pre_num} -lt ${current_pre_num} ]]; then
log_debug "Current version is newer than upstream available ${upstream_pre_num} < ${current_pre_num} (prerelease-num)"
return 2
elif [[ ${upstream_pre_num} -eq ${current_pre_num} ]]; then
log_debug "Current and upstream pre release nums match. ${upstream_pre_num} = ${current_pre_num} (all)"
return 0
fi
# We should never reach this condition. If we do, indicate we did not handle all conditions.
# This should trigger a bug report prompt/message in logs.
return 40
}
function _version_checks() {
# Checks if its running latest version.
# Also suggest updating to latest version if current version is not latest,
# Allows to deprecate old version as it can be suggested.
# Check if Version Checks is enabled. (Default is enabled)
declare upcheck_gh_api_res latest_semver_tag vcompare_result
# Check if update checks are enabled (default=true)
if [ "$AE_RUN_VERSION_CHECK" == "true" ]; then
log_stage "Checking for updates"
# Get latest version from GitHub release endpoint
latest_semver_tag="$(wget -q --timeout 20 --tries 3 -O- https://api.github.com/repos/tprasadtp/ubuntu-post-install/releases/latest | grep -Po '"tag_name": "\K.*?(?=")')"
upcheck_gh_api_res="$?"
if [[ $upcheck_gh_api_res -ne 0 ]]; then
log_error "Failed to check for updates!"
log_and_exit "Either check your connectivity or disable version checks with --no-version-check" "31"
fi
# Remove leading v if necessary
latest_semver="${latest_semver_tag#v}"
log_info "Latest available version is ${latest_semver}"
# Compare versions <CURRR> <UPSTREAM>
log_debug "Comparing versions"
compare_versions "${AE_VERSION}" "${latest_semver}"
vcompare_result="$?"
# Evaluate
case $vcompare_result in
1)
log_error "Thou art running older version of this script,"
log_error "Please download latest version and try again."
log_and_exit "You can disable version checks by passing --no-version-check" "24"
;;
0)
log_success "Running the latest version!"
;;
2)
log_dev "You are running development version of the script"
;;
21)
log_warn "Script's semver is invalid! Please report this bug!"
log_warn "Disabling update checks!"
;;
22)
log_warn "Latest version is invalid! Please report this bug!"
;;
*)
log_error "Failed to evaluate version check result- ${vcompare_result}"
;;
esac
# If version checks have been disabled
else
log_warn "Version checks have been disabled."
fi
}
function _check_bool() {
# Function to check if config has valid values for bool.
# Accepted values are true and false
# If invalid, defaults to false.
# Accepts global var and bool to check as arguments
local g_var param_bool default_val
if [[ $# -eq 2 ]]; then
default_val="false"
else
log_and_exit "Internal error! bool validator takes only two arguments!" "19"
fi
g_var="${1}"