-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_cent-ubuntu-alpine.sh
76 lines (66 loc) · 1.69 KB
/
update_cent-ubuntu-alpine.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
#!/bin/bash
TEXT_RESET='\e[0m'
TEXT_YELLOW='\e[0;33m'
TEXT_RED_B='\e[1;31m'
# Detecting the package manager
if command -v apt-get &> /dev/null; then
# Ubuntu
PACKAGE_MANAGER='apt-get'
elif command -v dnf &> /dev/null; then
# CentOS
PACKAGE_MANAGER='dnf'
elif command -v apk &> /dev/null; then
# Alpine Linux
PACKAGE_MANAGER='apk'
else
echo -e $TEXT_RED_B
echo "Unsupported Linux distribution."
echo -e $TEXT_RESET
exit 1
fi
# Updating the package manager
sudo $PACKAGE_MANAGER update
echo -e $TEXT_YELLOW
echo "${PACKAGE_MANAGER^^} update finished..."
echo -e $TEXT_RESET
# Performing package upgrades
if [ "$PACKAGE_MANAGER" == "apt-get" ]; then
# Ubuntu
sudo $PACKAGE_MANAGER dist-upgrade -y
else
# CentOS and Alpine Linux
sudo $PACKAGE_MANAGER upgrade -y
fi
echo -e $TEXT_YELLOW
echo "${PACKAGE_MANAGER^^} upgrade finished..."
echo -e $TEXT_RESET
# Cleaning up unused packages
sudo $PACKAGE_MANAGER autoremove -y
echo -e $TEXT_YELLOW
echo "${PACKAGE_MANAGER^^} auto remove finished..."
echo -e $TEXT_RESET
# Performing a release upgrade (if applicable)
if [ "$PACKAGE_MANAGER" == "apt-get" ]; then
sudo do-release-upgrade
echo -e $TEXT_YELLOW
echo 'APT release upgrade finished...'
echo -e $TEXT_RESET
fi
# Checking for reboot requirement
if [ -f /var/run/reboot-required ]; then
echo -e $TEXT_RED_B
echo 'Reboot required!'
echo -e $TEXT_RESET
fi
echo -e $TEXT_RED_B
echo "Update Complete! Press Y/N to reboot."
echo -e $TEXT_RESET
# Prompting for reboot
while true; do
read -p "Would you like to reboot now? " yn
case $yn in
[Yy]* ) reboot; break;;
[Nn]* ) exit;;
* ) echo "Please answer yes or no!";;
esac
done