diff --git a/script.sh b/script.sh index 3e98645..35613ad 100644 --- a/script.sh +++ b/script.sh @@ -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 \ No newline at end of file