forked from xrhstosmour/arch-tuner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
97 lines (75 loc) · 3.9 KB
/
install.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
#!/bin/bash
# Catch exit signal (CTRL + C) to terminate the whole script.
trap "exit" INT
# Terminate script on error.
set -e
# Constant variable of the scripts' working directory to use for relative paths.
INSTALL_SCRIPT_DIRECTORY=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
# Constant variable for the flags script path.
FLAGS_SCRIPT_PATH="$INSTALL_SCRIPT_DIRECTORY/scripts/core/flags.sh"
declare -a ORDERED_SCRIPTS=("essentials" "interface" "desktop" "development" "privacy" "security")
# Scripts to run containing their completion flag, initial setup value and optional message, splitted by "|".
declare -A SCRIPTS=(
["essentials"]="ESSENTIALS_COMPLETED|1"
["interface"]="INTERFACE_COMPLETED|1|Do you want to install display manager and GPU drivers?"
["desktop"]="DESKTOP_COMPLETED|1|Do you want to install desktop applications?"
["development"]="DEVELOPMENT_COMPLETED|1|Do you want to install development tools and programming languages?"
["privacy"]="PRIVACY_COMPLETED|1"
["security"]="SECURITY_COMPLETED|1"
)
# TODO: Give execution permission to all the needed scripts.
# Import functions and flags.
source "$INSTALL_SCRIPT_DIRECTORY/scripts/helpers/functions/ui.sh"
source "$INSTALL_SCRIPT_DIRECTORY/scripts/helpers/functions/system.sh"
source "$INSTALL_SCRIPT_DIRECTORY/scripts/helpers/functions/strings.sh"
source "$FLAGS_SCRIPT_PATH"
# Ask user for backup confirmation before proceeding.
if [[ "$INITIAL_SETUP" -eq 0 ]]; then
ask_for_user_backup_before_proceeding
fi
# Update system.
update_system
# Iterate over the scripts and execute them accordingly.
for script in "${ORDERED_SCRIPTS[@]}"; do
# Split the script info based on the delimiter "|".
IFS="|" read -ra script_info <<<"${SCRIPTS[$script]}"
completion_flag="${script_info[0]}"
message="${script_info[2]}"
# Check if script has not already been completed.
if [ "${!completion_flag}" -eq 1 ]; then
# Flag to track if the user executed a script, 1 (false) by default.
user_choice=1
# Check if there's a prompt message for the script.
if [[ "$message" ]]; then
# Ask user for approval before executing script and change the flag value accordingly.
user_answer=$(ask_for_user_approval_before_executing_script "$message" "$INSTALL_SCRIPT_DIRECTORY/scripts/utilities/$script.sh")
if [[ "$user_answer" == "y" ]]; then
user_choice=0
elif [[ "$user_answer" == "n" ]]; then
user_choice=1
fi
else
log_info "Executing $script script..."
sh "$INSTALL_SCRIPT_DIRECTORY/scripts/utilities/$script.sh"
log_info "${script^} script execution finished!"
user_choice=0
fi
# Check if the user executed the script before marking as complete and reboot.
if [[ "$user_choice" -eq 0 ]]; then
# Set completion flag to 0 (true) if it's "desktop" or "development".
[[ "$script" == "desktop" || "$script" == "development" ]] && change_flag_value "$completion_flag" 0 "$FLAGS_SCRIPT_PATH"
# Reboot system for the rest of the scripts.
if [[ "$script" == "essentials" || "$script" == "interface" || "$script" == "privacy" ]]; then
# Before rebooting, if the script is the first one the "essentials" one, change the INITIAL_SETUP flag to 1 (false).
[[ "$script" == "essentials" ]] && change_flag_value "INITIAL_SETUP" 1 "$FLAGS_SCRIPT_PATH"
# Proceed with rebooting the system.
reboot_system "${!completion_flag}" "$completion_flag"
elif [ "$script" == "security" ]; then
log_info "Installation procedure finished!"
log_info "Your system is ready to use!"
# Do not log the rerun warning.
reboot_system "${!completion_flag}" "$completion_flag" 1
fi
fi
fi
done