Updated script

This commit is contained in:
joeri 2024-08-03 13:06:16 +02:00
parent 1202f32d9a
commit 53e99dd148

View file

@ -1,24 +1,50 @@
#!/bin/bash
# Check the Linux distro
distro=$(cat /etc/os-release | grep ^NAME | cut -d '=' -f2- | sed 's/"//g')
# Function to update Ubuntu/Debian
update_debian_based() {
echo "Updating $1..."
sudo apt-get update && sudo apt-get upgrade -y
echo "Upgrade completed!"
}
# Update the OS
case $distro in
"Ubuntu" | "Linux Mint")
sudo apt update && sudo apt upgrade -y
;;
"Fedora" | "CentOS" | "RHEL")
# Function to update Fedora
update_fedora() {
echo "Updating Fedora..."
sudo dnf update -y
;;
"openSUSE")
sudo zypper update -y
;;
"Debian")
sudo apt update && sudo apt upgrade -y
;;
*)
echo "Unsupported Linux distribution: $distro"
echo "Upgrade completed!"
}
# Function to update CentOS
update_centos() {
echo "Updating CentOS..."
sudo yum update -y
echo "Upgrade completed!"
}
# Detecting the distribution based on /etc/os-release
if [ -f /etc/os-release ]; then
. /etc/os-release
DISTRO=$ID
else
echo "Cannot detect the OS. /etc/os-release not found."
exit 1
;;
fi
# Updating the system based on detected distribution
case "$DISTRO" in
ubuntu)
update_debian_based "Ubuntu"
;;
debian)
update_debian_based "Debian"
;;
fedora)
update_fedora
;;
centos)
update_centos
;;
*)
echo "Unsupported distribution: $DISTRO"
exit 1
esac