-
Notifications
You must be signed in to change notification settings - Fork 32
/
after-effects
executable file
·2728 lines (2289 loc) · 93.5 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
# shellcheck disable=SC2059
# vim: filetype=sh
# Author: Prasad Tengse
# Licence: GPLv3
# Github Repository: https://github.com/tprasadtp/ubuntu-post-install
# Requirements - Bash v4 and above
# - whiptail, wget, awk, sed, grep
#
set -o pipefail
readonly AE_EXEC_START=$(date +%s)
readonly SCRIPT=$(basename "$0")
# SCRIPT METADATA
readonly dir=$(cd -P -- "$(dirname -- "$0")" && pwd -P)
readonly REL_NAME="7.0.0"
readonly REL_NUM=700
# Handle Use interrupt
# trap ctrl-c and call ctrl_c()
trap ctrl_c_handler INT
function ctrl_c_handler() {
printf "${RED}• User Interrupt! CTRL-C${NC}\n"
exit 4
}
function _init_printf_variables()
{
#Initialize printf variables
readonly _phase_repo="(REPO)"
readonly _phase_ppa="(PPA)"
readonly _phase_install="(INST)"
readonly _phase_purge="(PURGE)"
readonly _phase_deb="(DPKG)"
readonly _phase_apt="(APT)"
readonly _phase_apt_key="(KEYS)"
readonly _phase_snap="(SNAP)"
# Log Premitives
readonly _info="[INF]"
readonly _dev="[DEV]"
readonly _debug="[DBG]"
readonly _cleanup="[DEL]"
readonly _success="[ OK]"
readonly _warn="[WRN]"
readonly _error="[ERR]"
readonly _variable="[VAR]"
readonly _crit="[CRT]"
#colors for display
readonly YELLOW=$'\e[38;5;220m'
readonly GREEN=$'\e[32m'
readonly RED=$'\e[31m'
readonly BLUE=$'\e[34m'
readonly LIGHT_BLUE=$'\e[38;5;159m'
readonly CYAN=$'\e[38;5;51m'
readonly NC=$'\e[0m'
readonly ORANGE=$'\e[38;5;208m'
readonly TEAL=$'\e[38;5;192m'
readonly PINK=$'\e[38;5;212m'
readonly GRAY=$'\e[38;5;246m'
readonly LOG_GRAY=$'\e[38;5;240m'
readonly LIGHT_GRAY=$'\e[38;5;242m'
readonly MAGENTA=$'\e[38;5;219m'
}
function _init_logging()
{
# Initialize phase 2
# Only variables necessary for logging & start logging
# Script related variables are defined in _init_script_variables
readonly log_file="$dir"/logs/after-effects.log
{
mkdir -p "$dir"/logs
} ||
{
printf "${RED}✕ Failed to create logs folder${NC}\n"; exit 2
}
# tmp dir
{
rm -rf /tmp/ae/*
mkdir -p /tmp/ae/
} ||
{
printf "${RED}✕ Failed to create tmp folder${NC}\n"; exit 2
}
# if file not exists touch it
if [[ ! -f ${log_file} ]]; then
if touch "${log_file}"; then
_log_info "Created log file"
else
printf "${RED}✕ Failed to create logfile!${NC}\n"
exit 2
fi
fi
# check if logs can be written
if [[ -w $log_file ]]; then
{
_log_debug "Initialized logging"
} ||
{
printf "${RED}✕ Failed to write to log file ${log_file} ${NC}\n"; exit 2
}
else
printf "${RED}✕ Log file is not writable!${NC}\n"
exit 2
fi
}
# Utility Functions
function _line_fill()
{
printf "_______________________________________________________\n"
}
function _log_and_exit()
{
# ARG-1 log msg
# ARG-2 exit code int
local msg="$1"
printf "${RED}✖ $msg ${NC}\n"
printf "$(date) ${_crit} $msg\n" >> "$log_file"
exit "$2"
}
function _script_exit_log()
{
# Script time
_log_stage "Cleanup and Exit"
readonly AE_EXEC_END=$(date +%s)
readonly AE_EXEC_TIME=$(( AE_EXEC_END - AE_EXEC_START ))
_log_debug "$SCRIPT took $AE_EXEC_TIME seconds to complete."
exit 0
}
function _log_info()
{
local msg="$1"
printf " • $msg\n"
printf "$(date) ${_info} $msg\n" >> "$log_file"
}
function _log_debug()
{
local msg="$1"
if [[ ${AE_DEBUG} -gt 0 ]]; then
printf "${GRAY} • $msg ${NC}\n"
fi
printf "$(date) ${_debug} $msg\n" >> "$log_file"
}
function _log_success()
{
local msg="$1"
printf "${TEAL} • $msg ${NC}\n"
printf "$(date) ${_success} $msg\n" >> "$log_file"
}
function _log_warn()
{
local msg="$1"
printf "${YELLOW} • $msg ${NC}\n"
printf "$(date) ${_warn} $msg\n" >> "$log_file"
}
function _log_stage()
{
local msg="$1"
printf "${MAGENTA}➜ $msg ${NC}\n"
printf "$(date) ${_info} $msg\n" >> "$log_file"
}
function _log_error()
{
local msg="$1"
printf "${RED} • $msg ${NC}\n"
printf "$(date) ${_error} $msg\n" >> "$log_file"
}
function _log_dev()
{
local msg="$1"
printf "${ORANGE} • $msg ${NC}\n"
printf "$(date) ${_dev} $msg\n" >> "$log_file"
}
function _log_notice()
{
local msg="$1"
printf "${CYAN} • $msg${NC}\n"
printf "$(date) ${_info} $msg\n" >> "$log_file"
}
function _log_var()
{
local var
var="$1"
if [[ $AE_DEBUG -gt 0 ]]; then
printf "${GRAY} » %-20s - %-10s${NC}\n" "${var}" "${!var}"
fi
printf "$(date) ${_variable} %-20s - %-10s\n" "${var}" "${!var}" >> "$log_file"
}
function _log_trace()
{
# This function adds time stamp to logs without using external utilities
# Output will be automatically written to $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
printf "$(date) [EXT] ${1} %s\n" "$line" &>> "$log_file"
if [[ $AE_DEBUG -gt 1 ]]; then
printf "${LOG_GRAY} » %s %s${NC}\n" "$1" "$line"
fi
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:-20}s"
__msg_string="$(printf "${fmt} : %s" "${desc}" "${value}")"
case ${lvl} in
0) _log_debug "${__msg_string}";;
1) _log_info "${__msg_string}";;
2) _log_notice "${__msg_string}";;
3) _log_dev "${__msg_string}";;
4) _log_warn "${__msg_string}";;
5) _log_error "${__msg_string}";;
*) _log_debug "${__msg_string}";;
esac
}
#shellcheck disable=SC2120
function detect_distribution()
{
# Read /etc/os-release and get
local OS_RELEASE_FILE
OS_RELEASE_FILE="${1:-/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_error "Hey, What kind of system is this?"
_log_and_exit "I cannot determine distro/codename!" "5"
fi
}
function _init_script_variables()
{
# Function defines Script variables
# Necessary variables used by the script are initialized here. This function
# should be called first before choices are made, always.
#shellcheck disable=SC2119
detect_distribution
# Achtung: Do not set code_name as readonly!!
code_name="${AE_DISTRO_CODENAME}"
readonly architecture="$(dpkg --print-architecture)"
case "${architecture}" in
amd64) _log_debug "Architecture is 64 bit.";
readonly ARCH="amd64";
;;
armhf) _log_debug "Running on ARM CPU with HW Floating point Processor";
readonly ARCH="armhf";
;;
arm64) _log_debug "This is an ARM64. Please be advised that not all repositories support this arch.";
readonly ARCH="arm64";
;;
* ) _log_error "Sorry! This architecture is not supported by this script!"
_log_and_exit "Unsupported Architecture. $(architecture)" "11"
;;
esac
# Get Hostname
readonly CLIENT_NAME=$(hostname)
# etc sources list dir
readonly SOURCES_FILE_DIR=/etc/apt/sources.list.d
# Trusted keys
if [[ -v ${TRUSTED_KEYRINGS_DIR} ]]; then
_log_and_exit "Reserved variable (TRUSTED_KEYRINGS_DIR) is set!" "66"
else
readonly TRUSTED_KEYRINGS_DIR=/usr/share/keyrings
fi
# Ping URL
readonly PING_URL="http://connectivitycheck.gstatic.com/generate_204"
#-------------------------- Release codenames --------------------------------------
readonly codename_latest_release="groovy"
readonly codename_previous_release="focal"
# 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 codename_upcoming_release="hirsute"
readonly codename_current_lts="focal"
readonly codename_previous_lts="bionic"
readonly codename_latest_debian_release="buster"
readonly codename_upcoming_debian_release="bullseye"
#============================ Switches/ booleans & Vars ================================
# Fix Repo not available for latest release
bool_fix_repo_not_available_for_latest="false"
# Allow repo fixes for Upcoming releases of ubuntu and its derivatives.
bool_fix_repo_not_available_for_upcoming_release="false"
# Checks for Version
# Define API node endpoints
bool_check_version="true"
readonly api_version_url="https://ae.prasadt.com/get/v3/version"
# Azure
readonly AZURE_METADATA_URL="http://169.254.169.254/metadata/instance/compute/location?api-version=2017-08-01&format=text"
# Achtung!!
# ========================================================================================= #
# 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
bool_purge_pkgs="false"
# Keep Downloaded DEB packages
bool_preserve_debs="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
bool_is_debian="false"
# Boolean to hold if --fix or --fix-mode-lts or --pre-release was applied
bool_codename_fix_appied="false"
}
function _init_print_basic_info()
{
# This function logs and displays the Necessary details which helps in debugging.
# Should be used after _init_script_variables function.
_log_property "Hostname" "${CLIENT_NAME}" 1
_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" "${ARCH}" 1
_log_property "Version(Number)" "${REL_NAME}(${REL_NUM})" 1
_log_property "SOURCES_FILE_DIR" "${SOURCES_FILE_DIR}"
_log_property "TRUSTED_KEYRINGS_DIR" "${TRUSTED_KEYRINGS_DIR}"
#disable hist chars so that I can print "!!"" properly
histchars=
}
function delete_log_file()
{
printf "➜ Deleting log file\n"
if rm "${dir}/logs/after-effects.log"; then
printf "${GREEN}• Done${NC}\n"
exit 0
else
printf "${RED}• Failed!${NC}\n"
exit 1;
fi
}
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;
_log_info "Checking dependencies"
for dependency in "${dependencies[@]}"; do
if command -v "$dependency" > /dev/null; then
_log_property "${dependency}" "INSTALLED"
else
_log_property "$dependency" "NOT INSTALLED"
dependency_check_failed_count=$((dependency_check_failed_count+1))
fi
done
if [ "$dependency_check_failed_count" -gt 0 ]; then
_log_error "One or more dependencies not installed."
_log_and_exit "Sorry! $SCRIPT cannot continue!" "1"
fi
}
function _eol_message()
{
# Display EOL Message and upgrade instruction URLs.
# Arguments: 1
# ARG 1: EOL Date
_log_error "This version of ${AE_DISTRO_NAME} is no longer supported."
_log_and_exit "${AE_DISTRO_PRETTY_NAME} will reach EOL pretty soon ($1)." "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 "code_name"
case ${code_name} in
# Ubuntu 18.04 and its derivatives
bionic ) readonly enable_ppa="true";
readonly distro_name="ubuntu";
_log_info "This is a LTS release of Ubuntu (18.04)"
_log_success "Keeping the codename as $code_name."
;;
tara | tessa | tina | tricia ) _log_info "This is Linux-Mint 19.X."
_log_info "Setting additional repositories to follow Ubuntu 18.04."
code_name="bionic";
readonly distro_name="ubuntu";
readonly enable_ppa="true";
_log_success "Changed codename to $code_name"
;;
juno | hera) _log_info "This release of Elementary OS is based on Ubuntu 18.04 Bionic."
_log_info "External repositories will use Ubuntu 18.04."
code_name="bionic";
readonly distro_name="ubuntu";
readonly enable_ppa="true";
_log_success "Changed codename to $code_name"
;;
# Ubuntu 20.04 and its derivatives (Current Ubuntu LTS release)
focal ) readonly enable_ppa="true";
readonly distro_name="ubuntu";
_log_info "This is latest LTS release of Ubuntu"
_log_success "Keeping the codename as $code_name."
;;
ulyana | ulyssa ) _log_info "Release is Linux mint 20.X."
_log_info "Setting additional repositories to follow Ubuntu 20.04."
code_name="focal";
readonly distro_name="ubuntu";
readonly enable_ppa="true";
_log_success "Changed codename to $code_name"
;;
# Current Ubuntu release (Can be non LTS)
groovy) readonly enable_ppa="true";
readonly distro_name="ubuntu";
_log_notice "Release is Ubuntu 20.10 Groovy Gorilla"
;;
# Upcoming Ubuntu release
hirsute) readonly enable_ppa="true";
readonly distro_name="ubuntu";
_log_warn "Release is Ubuntu 21.04 Hirsute Hippo (Unstable!!)"
;;
# Current Debian releases
stretch | buster ) bool_is_debian="true";
readonly distro_name="debian";
readonly enable_ppa="false";
_log_notice "This is Debian. PPAs are disabled."
;;
# Upcoming Debian release
bullseye ) bool_is_debian="true";
readonly enable_ppa="false";
readonly distro_name="debian";
_log_dev "You are running Debian Testing!"
_log_warn "This is pre release version of Debian. Use with caution!"
_log_notice "PPAs are disabled."
;;
# Unsupported releases
jessie) _eol_message "June 2020";;
xenial) _eol_message "April 2021";;
sarah | serena | sonya | sylvia) _eol_message "April 2021";;
tara | tessa | tina | tricia) _eol_message "April 2021";;
loki) _eol_message "April 2021";;
*) _log_error "Unknown or unsupported release($code_name) !!"
_script_exit_log;
exit 16;
;;
esac
_log_success "Applied release specific settings and fixes."
_log_var "code_name"
}
function _test_internet_connection ()
{
# Function to check internet connection
_log_info "Checking connectivity"
if wget --tries=2 --timeout=10 "$PING_URL" -O /dev/null -o /dev/null; then
_log_success "Connected!"
else
_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"
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
wget -q "${file_url}" -O "$file_name" >> $"$log_file"
exit_status="$?"
_log_property "Exit code (wget)" "$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 _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)
if [ "$bool_check_version" == "true" ]; then
_log_stage "Checking for updates"
_log_property "Version URL" "${api_version_url}"
rm -f "/tmp/ae/api-version.yml" || _log_debug "Deleting old version YAML failed."
# Get response/file
_get_remote_file /tmp/ae/api-version.yml "$api_version_url"
# Parse YAML to variables
eval "$(parse_yaml /tmp/ae/api-version.yml)"
# Assign them to local variables as sometimes bash if does not handle array elements very well.
local api_rel_num="${version__number[0]}"
# Assign Statistics reporting flag and endpoint to Global variables.
# Debug Info
_log_property "Version (API)" "${api_rel_num}"
_log_property "Version Name(API)" "${version__name[0]}"
# If release number is higher than one in the script throw error & ask to update.
if [[ $api_rel_num -gt $REL_NUM ]]; then
_log_error "A newer version is available."
_log_error "Please download latest version and try again."
_log_notice "Latest available version is ${version__name[0]}-${api_rel_num}."
_log_and_exit "You can disable version checks by passing --skip-version-check" "24"
elif [[ $api_rel_num -eq $REL_NUM ]]; then
_log_success "Running the latest version!"
elif [[ $api_rel_num -lt $REL_NUM ]]; then
_log_dev "You running development version ${REL_NAME}(${REL_NUM})."
_log_dev "Latest stable version is ${version__name[0]}(${api_rel_num})."
fi
# 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}"
param_bool="${2}"
case "${param_bool}" in
true | True | TRUE | Yes | yes | YES | 1 ) declare -g ${g_var}="true"
_log_var "$g_var"
;;
false | False | FALSE | No | no | NO | 0 ) declare -g ${g_var}="false"
_log_var "$g_var"
;;
*) declare -g ${g_var}="${default_val}"
_log_var "$g_var"
;;
esac
}
function _set_yaml_config()
{
local config_yaml_file
# Get and parse the file
_log_stage "Processing configuration..."
if [ "$bool_local_config" != "true" ]; then
_log_property "Config URL" "${url_remote_yaml}" 3
if [[ -e "/tmp/ae/api-config.yml" ]]; then
rm -f "/tmp/ae/api-config.yml" || _log_and_exit "Deleting old version YAML failed." "38"
fi
readonly config_yaml_file="/tmp/ae/api-config.yml"
# Get response/file
_get_remote_file "$config_yaml_file" "$url_remote_yaml"
else
_log_property "Config file" "$local_config_file" 2
readonly config_yaml_file="$local_config_file"
fi
# Parse YAML to variables
_log_property "Parsing config" "$config_yaml_file" 2
eval "$(parse_yaml "$config_yaml_file")"
# Repo flags
#################################################################################
_check_bool "add_docker_repo" "${config__add_repo__docker[0]}"
_check_bool "add_winehq_repo" "${config__add_repo__winehq[0]}"
_check_bool "add_mendeley_repo" "${config__add_repo__mendeley[0]}"
_check_bool "add_spotify_repo" "${config__add_repo__spotify[0]}"
_check_bool "add_signal_repo" "${config__add_repo__signal[0]}"
# ROS
_check_bool "add_ros_repo" "${config__add_repo__ros[0]}"
_check_bool "add_ros2_repo" "${config__add_repo__ros2[0]}"
# GitHub
_check_bool "add_gh_repo" "${config__add_repo__github[0]}"
_check_bool "add_hashicorp_repo" "${config__add_repo__hashicorp[0]}"
# Google
_check_bool "add_gvisor_repo" "${config__add_repo__gvisor[0]}"
_check_bool "add_bazel_repo" "${config__add_repo__bazel[0]}"
_check_bool "add_gcp_repo" "${config__add_repo__googlecloud[0]}"
_check_bool "add_gcsfuse_repo" "${config__add_repo__gcsfuse[0]}"
_check_bool "add_chrome_repo" "${config__add_repo__chrome[0]}"
# Microsoft
_check_bool "add_azurecli_repo" "${config__add_repo__azurecli[0]}"
_check_bool "add_edge_repo" "${config__add_repo__edge[0]}"
_check_bool "add_skype_repo" "${config__add_repo__skype[0]}"
_check_bool "add_vscode_repo" "${config__add_repo__vscode[0]}"
_check_bool "add_msteams_repo" "${config__add_repo__teams[0]}"
# Other Script Flags
#################################################################################
# Purge Packages
if [[ $bool_purge_pkgs == "true" ]]; then
_log_debug "Ignoring config.flags.purge_enabled because of cli flag"
else
_check_bool "bool_purge_pkgs" "${config__flags__purge_enabled[0]}"
fi
#bool_purge_pkgs="${config__flags__purge_enabled[0]}"
# Keep Debs
if [[ $bool_preserve_debs == "true" ]]; then
_log_debug "Ignoring config.flags.preserve_debs because of cli flag"
else
_check_bool "bool_preserve_debs" "${config__flags__preserve_debs[0]}"
fi
#bool_preserve_debs="${config__flags__preserve_debs[0]}"
# Uni-Mirror
_check_bool "bool_use_uf_mirror" "${config__flags__uni_freiburg_mirror[0]}"
# Tasks Flags
##################################################################################
_check_bool "ae_task_update" "${config__tasks__update[0]}"
_check_bool "ae_task_upgrade" "${config__tasks__upgrade[0]}"
_check_bool "ae_task_repo" "${config__tasks__repo[0]}"
_check_bool "ae_task_ppa" "${config__tasks__ppa[0]}"
_check_bool "ae_task_apt" "${config__tasks__apt[0]}"
_check_bool "ae_task_debs" "${config__tasks__debs[0]}"
_check_bool "ae_task_purge" "${config__tasks__purge[0]}"
_check_bool "ae_task_bin" "${config__tasks__binaries[0]}"
_check_bool "ae_task_snaps" "${config__tasks__snaps[0]}"
#################################################################################
# Parse Arrays
#################################################################################
# Config file YAML has arrays of apt packages.
# We need to parse apt packages, ppa's, deb packages, listed in yaml
# to bash arrays.
#--------------------------------------------------------------------------------
# APT Lists
#--------------------------------------------------------------------------------
# There are Seven lists under key config.install.apt.[mentioned from 1-7]
# 1. administration : Contains Administrative packages
# 2. security : contains Security related tools and packages
# 3. productivity : Office tools, writing tools, LateX, document tools and other
# productivity tools, Email clients, browsers, IM clients etc.
# : Example : LateX, TeXStudio, Libre office, pandoc empathy, Thunderbird
# 4. Multimedia : Multimedia tools like media players, audio converters and playes etc.
# 5. development : IDEs [Spyder, Jetbeans etc], languages [go, python, ruby, rust, java etc],
# : Containers [docker lxc rkt etc], Python libraries, compilers [gcc, clang]
# : SDKs [AWS SDK, Coogle Cloud SDK, open-jdk, Tensor Flow], headers
# : and libraries[ocl-icd-dev],
# : Anything related to development and *-dev or *-devl packages.
# 6. other : Everything which doesnot fit in the above categories.
# : Themes, Tools, Utilities like htop etc.
# 7. External : Any packages which are provided by ppas, or repositories not present in
# : base *buntu distribution. There's a possibility that the repository might not
# : be added or may be unavailable or offline. So Keeping the list seperate from
# : others packages minimizes errors if there are any.
# This classification is only for ease of use and need not be strictly followed. You can put
# vlc package in 'security', it will still install fine. This classification helps
# while writing configs and editing them. Its advised to follow it if your configs
# tend to get to couple of hundreds of lines. Also YAML file should be a valid YAML.
#--------------------------------------------------------------------------------
# Special list - Purge list
#--------------------------------------------------------------------------------
# There is a special package list under key, config.purge, which contains
# list of apt packages to be purged from the system if present.
# Lets get em, shall we?
# Copy package array
declare -gar parsed_purge_packages=("${config__purge_[@]}")
declare -gar parsed_administration_packages=("${config__install__apt__administration_[@]}")
declare -gar parsed_secutity_packages=("${config__install__apt__security_[@]}")
declare -gar parsed_productivity_packages=("${config__install__apt__productivity_[@]}")
declare -gar parsed_multimedia_packages=("${config__install__apt__multimedia_[@]}")
declare -gar parsed_development_packages=("${config__install__apt__development_[@]}")
declare -gar parsed_other_packages=("${config__install__apt__other_[@]}")
declare -gar parsed_external_packages=("${config__install__apt__external_[@]}")
#--------------------------------------------------------------------------------
# PPA Lists
#--------------------------------------------------------------------------------
# Config file contains list of PPAs to be added under key
# config.ppa
declare -gar parsed_ppa_list=("${config__ppa_[@]}")
#--------------------------------------------------------------------------------
# Debian packages
#--------------------------------------------------------------------------------
# Config file contains list of DEB packages to be downloaded & installed under key
# config.install.debian_packages
# The configuration is not simple URL its csv. <URL to Deb file>,<Name of the Package>
# This is for compatiblity reasons
declare -gar parsed_deb_files_list=("${config__install__debian_packages_[@]}")
#--------------------------------------------------------------------------------
# Static binaries
#--------------------------------------------------------------------------------
declare -gar parsed_bin_packages=("${config__install__binaries_[@]}")
#--------------------------------------------------------------------------------
# Snap Packages
#--------------------------------------------------------------------------------
declare -gar parsed_snap_normal_packages=("${config__install__snaps__normal_[@]}")
declare -gar parsed_snap_classic_packages=("${config__install__snaps__classic_[@]}")
declare -gar parsed_snap_edge_packages=("${config__install__snaps__edge_[@]}")
}
function _clean_apt_cache()
{
# Function to clean apt package cache. Takes care of -k flag in all the installs.
# Honor -k flag
# Delete DEBs
if [ "$bool_preserve_debs" != "true" ];then
_log_debug "Removing cached APT packages"
apt-get -q -o=Dpkg::Use-Pty=0 clean | _log_trace "${_phase_apt}"
else
_log_notice "Keeping cached packages because -k flag is set."
fi
}
function _install_dependencies()
{
# Install packages mentioned in the arguments.
# If installation fails exit the script.
# ARG 1: Packages in quote separated by space.
local packages=("$@")
_log_debug "Installing Packages ${packages[*]}"
# Check if array is empty
if [[ ${#packages[@]} -eq 0 ]]; then
_log_warn "Package array is empty!" "19"
else
apt-get -q -o=Dpkg::Use-Pty=0 -y --no-install-recommends install "${packages[@]}" |& _log_trace "${_phase_apt}" \
|| _log_and_exit "Failed to install dependencies. Script cannot continue!!" "21"
exit_status=$?
if [ $exit_status -eq 0 ]; then
_log_success "Installed"
else
_log_error "Something went wrong while installing dependencies."
_log_and_exit "Please see the log file for more details." "21"
fi
_clean_apt_cache
fi
}
function _install_pre_requisites()
{
# This function installs required packages for adding apt repositories
# These should be present in your base Ubuntu install. If not present then, this function
# will install them.
# Following are the packages installed by this function:
# linux-image-extra-<>, apt-transport-https, ca-certificates,
# curl, software-properties-common
local pre_requisite_packages=(apt-transport-https ca-certificates curl gnupg2)
_log_info "Installing necessary dependencies..."
_install_dependencies "${pre_requisite_packages[@]}"
}
function _fix_repo_not_available()
{
# If repository is not available for latest Ubuntu release, this uses last stable release
# (may not be LTS) for adding repository
_log_debug "Check and apply codename fixes"
if [ "$bool_fix_repo_not_available_for_latest" == "true" ]; then
# Check LTS fallback flag is being used
# if running on current LTS, and fix mode is LTS fallback to last LTS.
if [[ $bool_fix_repo_lts == "true" ]] && [[ $code_name == "${codename_current_lts}" ]] ; then
_log_warn "Using Previous LTS release ::${codename_previous_lts}::"
code_name="$codename_previous_lts"
# note applied fix
bool_codename_fix_appied="true"
elif [[ $bool_fix_repo_lts != "true" ]] && [[ $code_name == "${codename_latest_release}" ]] ; then
_log_warn "Using previous release ${codename_previous_release} as fallback"
# fallback is non LTS so it might disapper/become unsupported! warn
if [[ $codename_previous_release != "$codename_current_lts" ]]; then
_log_warn "Fallback Ubuntu (${codename_latest_release}) is a non LTS release!"
fi
code_name="$codename_previous_release"
bool_codename_fix_appied="true"
else