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
|
#!/bin/bash
|
||||||
|
|
||||||
# Check the Linux distro
|
# Function to update Ubuntu/Debian
|
||||||
distro=$(cat /etc/os-release | grep ^NAME | cut -d '=' -f2- | sed 's/"//g')
|
update_debian_based() {
|
||||||
|
echo "Updating $1..."
|
||||||
|
sudo apt-get update && sudo apt-get upgrade -y
|
||||||
|
echo "Upgrade completed!"
|
||||||
|
}
|
||||||
|
|
||||||
# Update the OS
|
# Function to update Fedora
|
||||||
case $distro in
|
update_fedora() {
|
||||||
"Ubuntu" | "Linux Mint")
|
echo "Updating Fedora..."
|
||||||
sudo apt update && sudo apt upgrade -y
|
|
||||||
;;
|
|
||||||
"Fedora" | "CentOS" | "RHEL")
|
|
||||||
sudo dnf update -y
|
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")
|
debian)
|
||||||
sudo zypper update -y
|
update_debian_based "Debian"
|
||||||
;;
|
;;
|
||||||
"Debian")
|
fedora)
|
||||||
sudo apt update && sudo apt upgrade -y
|
update_fedora
|
||||||
|
;;
|
||||||
|
centos)
|
||||||
|
update_centos
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "Unsupported Linux distribution: $distro"
|
echo "Unsupported distribution: $DISTRO"
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
|
||||||
esac
|
esac
|
||||||
Loading…
Reference in a new issue