@@ -3,11 +3,53 @@ none='\033[0m'
3
3
green=' \033[0;32m'
4
4
red=' \033[0;31m'
5
5
yellow=' \033[33m'
6
- course=" CYB101 "
6
+ course=" CYB102 "
7
7
8
8
branch=${1:- " main" }
9
9
scripts_repo=" https://raw.githubusercontent.com/codepath/cyb102-vm-setup/${branch} /Scripts/"
10
10
11
+ # Function to check and perform system updates
12
+ perform_system_updates () {
13
+
14
+ echo -e " Checking for system updates..."
15
+
16
+ # Check the last update time by examining the modification time of /var/lib/apt/periodic/update-success-stamp
17
+ if [ -f /var/lib/apt/periodic/update-success-stamp ]; then
18
+ last_update=$( date -r /var/lib/apt/periodic/update-success-stamp +%s)
19
+ current_time=$( date +%s)
20
+ update_age=$(( (current_time - last_update) / 86400 )) # Convert seconds to days
21
+
22
+ if [ $update_age -ge 7 ]; then # More than 7 days since last update
23
+ echo -e " ${yellow} INFO:${none} The system needs to update."
24
+ echo -e " ${yellow} INFO:${none} During that time, you will need to leave your machine on and connected to the internet."
25
+ read -p " Do you want to continue with the update? (y/n) " -n 1 -r
26
+ echo
27
+ if [[ ! $REPLY =~ ^[Yy]$ ]]; then
28
+ echo " Exiting the program. Goodbye!"
29
+ exit 1
30
+ fi
31
+ echo -e " Downloading and running the update script..."
32
+ wget " https://raw.githubusercontent.com/codepath/cyb102-vm-setup/main/Scripts/update.sh" -O update.sh
33
+ chmod +x update.sh
34
+ ./update.sh
35
+ else
36
+ echo -e " ${green} System is up-to-date.${none} "
37
+ fi
38
+ else
39
+ echo -e " ${yellow} INFO:${none} No update history found... the system needs to update."
40
+ echo -e " ${yellow} INFO:${none} During that time, you will need to leave your machine on and connected to the internet."
41
+ read -p " Do you want to continue with update? (y/n) " -n 1 -r
42
+ echo
43
+ if [[ ! $REPLY =~ ^[Yy]$ ]]; then
44
+ echo " Exiting the program. Goodbye!"
45
+ exit 1
46
+ fi
47
+ wget " https://raw.githubusercontent.com/codepath/cyb102-vm-setup/main/Scripts/update.sh" -O update.sh
48
+ chmod +x update.sh
49
+ ./update.sh
50
+ fi
51
+ }
52
+
11
53
# Welcome message
12
54
echo -e " Welcome to ${green} CodePath Cybersecurity${none} !"
13
55
echo -e " This tool will help you set up your environment for the ${course} course."
@@ -125,7 +167,13 @@ show_menu() {
125
167
install_all_scripts
126
168
;;
127
169
2)
128
- read -p " Enter the number of the unit to install (1-7): " unit_number
170
+ unit_number=" "
171
+ while [[ ! $unit_number =~ ^[1-7]$ ]]; do
172
+ read -p " Enter the number of the unit to install (1-7): " unit_number
173
+ if [[ ! $unit_number =~ ^[1-7]$ ]]; then
174
+ echo " Invalid input, please enter a number between 1 and 7."
175
+ fi
176
+ done
129
177
install_specific_unit " $unit_number "
130
178
;;
131
179
3)
@@ -142,6 +190,9 @@ show_menu() {
142
190
esac
143
191
}
144
192
193
+ # Ensure the system is updated before proceeding
194
+ perform_system_updates
195
+
145
196
# Main program loop
146
197
while true ; do
147
198
show_menu
0 commit comments