Updated script
This commit is contained in:
parent
1202f32d9a
commit
53e99dd148
1 changed files with 44 additions and 18 deletions
54
script.sh
54
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
|
||||
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"
|
||||
;;
|
||||
"openSUSE")
|
||||
sudo zypper update -y
|
||||
debian)
|
||||
update_debian_based "Debian"
|
||||
;;
|
||||
"Debian")
|
||||
sudo apt update && sudo apt upgrade -y
|
||||
fedora)
|
||||
update_fedora
|
||||
;;
|
||||
centos)
|
||||
update_centos
|
||||
;;
|
||||
*)
|
||||
echo "Unsupported Linux distribution: $distro"
|
||||
echo "Unsupported distribution: $DISTRO"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
Loading…
Reference in a new issue