#!/bin/bash # Function to update Ubuntu/Debian update_debian_based() { echo "Updating $1..." sudo apt-get update && sudo apt-get upgrade -y echo "Upgrade completed!" } # Function to update Fedora update_fedora() { echo "Updating Fedora..." sudo dnf update -y 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