-
Notifications
You must be signed in to change notification settings - Fork 2
/
install.sh
122 lines (97 loc) · 5.09 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
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
#!/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"
CONSTANTS_SCRIPT_PATH="$INSTALL_SCRIPT_DIRECTORY/scripts/core/constants.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|Would you like to set up the graphical login interface?"
["desktop"]="DESKTOP_COMPLETED|1|Would you like to set up the desktop environment?"
["development"]="DEVELOPMENT_COMPLETED|1|Would you like to set up the development environment?"
["privacy"]="PRIVACY_COMPLETED|1"
["security"]="SECURITY_COMPLETED|1"
)
# TODO: Add minimal installation type when there will be server scripts to differentiate.
# Define allowed scripts for each installation type
declare -A ALLOWED_SCRIPTS=(
["desktop"]="essentials interface desktop development privacy security"
["server"]="essentials privacy security"
)
# 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"
source "$CONSTANTS_SCRIPT_PATH"
# Ask user for backup confirmation before proceeding.
if [[ "$INITIAL_SETUP" -eq 0 ]]; then
ask_for_user_backup_before_proceeding
fi
# Ask user for system reset if not already completed, before proceeding.
if [[ "$SYSTEM_RESET" -eq 1 ]]; then
should_reset_system=$(ask_user_before_execution "Would you like to reset your system to a 'clean' state?" "true" "$INSTALL_SCRIPT_DIRECTORY/scripts/helpers/functions/system.sh#reset_system_to_clean_state")
fi
# Ask user for the installation type, before proceeding.
if [[ -z "$INSTALLATION_TYPE" ]]; then
declare -a INSTALLATION_TYPE_OPTIONS=("desktop" "server")
installation_type=$(choose_option "Select installation type" "${INSTALLATION_TYPE_OPTIONS[@]}")
change_flag_value "INSTALLATION_TYPE" "$installation_type" "$CONSTANTS_SCRIPT_PATH"
source "$CONSTANTS_SCRIPT_PATH"
fi
# Update system.
update_system
# Iterate over the scripts and execute them accordingly.
for script in "${ORDERED_SCRIPTS[@]}"; do
# Skip scripts not allowed for the current installation type.
if [[ ! " ${ALLOWED_SCRIPTS[$INSTALLATION_TYPE]} " =~ " $script " ]]; then
continue
fi
# 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_user_before_execution "$message" "false" "$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_success "${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"
# Change the completion flag value to 0 (true).
change_flag_value "$completion_flag" 0 "$FLAGS_SCRIPT_PATH"
elif [ "$script" == "security" ]; then
log_success "Installation procedure finished!"
log_success "Your system is ready to use!"
# Do not log the rerun warning.
reboot_system "${!completion_flag}" "$completion_flag" 1
fi
fi
fi
done