Skip to content

Commit ce3900e

Browse files
committed
Add system update capability to the install_tool
1 parent 0f05e3f commit ce3900e

File tree

2 files changed

+72
-2
lines changed

2 files changed

+72
-2
lines changed

Scripts/update.sh

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
# Inform the user about adding the 'universe' repository
4+
echo "Adding the 'universe' repository..."
5+
sudo add-apt-repository universe -y
6+
echo "The 'universe' repository has been added successfully."
7+
8+
# Update the package list
9+
echo "Updating the package list..."
10+
sudo apt update
11+
echo "Package list updated successfully."
12+
13+
# Upgrade all the installed packages
14+
echo "Upgrading all installed packages. This might take a while..."
15+
sudo DEBIAN_FRONTEND=noninteractive apt upgrade -y
16+
echo "All packages have been upgraded successfully."
17+
18+
# Final completion message
19+
echo "Update and upgrade process completed successfully!"

install_tool.sh

+53-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,53 @@ none='\033[0m'
33
green='\033[0;32m'
44
red='\033[0;31m'
55
yellow='\033[33m'
6-
course="CYB101"
6+
course="CYB102"
77

88
branch=${1:-"main"}
99
scripts_repo="https://raw.githubusercontent.com/codepath/cyb102-vm-setup/${branch}/Scripts/"
1010

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+
1153
# Welcome message
1254
echo -e "Welcome to ${green}CodePath Cybersecurity${none}!"
1355
echo -e "This tool will help you set up your environment for the ${course} course."
@@ -125,7 +167,13 @@ show_menu() {
125167
install_all_scripts
126168
;;
127169
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
129177
install_specific_unit "$unit_number"
130178
;;
131179
3)
@@ -142,6 +190,9 @@ show_menu() {
142190
esac
143191
}
144192

193+
# Ensure the system is updated before proceeding
194+
perform_system_updates
195+
145196
# Main program loop
146197
while true; do
147198
show_menu

0 commit comments

Comments
 (0)