-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlinux-server-update-script.sh
31 lines (25 loc) · 1 KB
/
linux-server-update-script.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
#!/bin/bash
# Update package lists
echo "Updating all packages"
sudo apt update
sleep 3
sudo apt upgrade -y
# Clean up old and unnecessary packages
echo "Removing unnecessary packages"
sudo apt autoremove -y
# Perform a distro upgrade but only with user acceptance to prevent any breaking changes from being applied
# "--simulate" command used here so no actual upgrade is performed before user prompt
dist_upgrade_available=$(sudo apt dist-upgrade --simulate | grep "upgraded, 0 newly installed")
if [[ -z $dist_upgrade_available ]]; then
# Prompt the user for a distribution upgrade
read -p "A distribution upgrade is available. Do you want to perform it? (y/n): " choice
if [[ $choice =~ ^[Yy]$ ]]; then
# Warn user and Perform distribution upgrade
echo "Warning: Full system upgrade is starting and might take some time to complete"
sudo apt dist-upgrade
else
echo "Skipping distribution upgrade."
fi
else
echo "No distribution upgrade available."
fi