2024-07-14 03:16:02 +01:00
|
|
|
#!/bin/sh
|
|
|
|
RC='\033[0m'
|
|
|
|
RED='\033[31m'
|
|
|
|
YELLOW='\033[33m'
|
|
|
|
GREEN='\033[32m'
|
2024-07-13 02:57:34 +01:00
|
|
|
|
|
|
|
command_exists() {
|
2024-07-14 03:16:02 +01:00
|
|
|
which $1 >/dev/null 2>&1
|
2024-07-13 02:57:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
checkEnv() {
|
|
|
|
## Check for requirements.
|
|
|
|
REQUIREMENTS='curl groups sudo'
|
2024-07-14 03:16:02 +01:00
|
|
|
for req in ${REQUIREMENTS}; do
|
|
|
|
if ! command_exists ${req}; then
|
|
|
|
printf "${RED}To run me, you need: ${REQUIREMENTS}${RC}\n"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
done
|
2024-07-13 02:57:34 +01:00
|
|
|
|
2024-07-14 03:16:02 +01:00
|
|
|
## Check Package Handler
|
2024-07-13 02:57:34 +01:00
|
|
|
PACKAGEMANAGER='apt-get dnf pacman zypper'
|
|
|
|
for pgm in ${PACKAGEMANAGER}; do
|
|
|
|
if command_exists ${pgm}; then
|
|
|
|
PACKAGER=${pgm}
|
2024-07-14 03:16:02 +01:00
|
|
|
printf "Using ${pgm}\n"
|
|
|
|
break
|
2024-07-13 02:57:34 +01:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ -z "${PACKAGER}" ]; then
|
2024-07-14 03:16:02 +01:00
|
|
|
printf "${RED}Can't find a supported package manager${RC}\n"
|
2024-07-13 02:57:34 +01:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
## Check SuperUser Group
|
|
|
|
SUPERUSERGROUP='wheel sudo root'
|
|
|
|
for sug in ${SUPERUSERGROUP}; do
|
2024-07-14 03:16:02 +01:00
|
|
|
if groups | grep ${sug} >/dev/null; then
|
2024-07-13 02:57:34 +01:00
|
|
|
SUGROUP=${sug}
|
2024-07-14 03:16:02 +01:00
|
|
|
printf "Super user group ${SUGROUP}\n"
|
|
|
|
break
|
2024-07-13 02:57:34 +01:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
## Check if member of the sudo group.
|
|
|
|
if ! groups | grep ${SUGROUP} >/dev/null; then
|
2024-07-14 03:16:02 +01:00
|
|
|
printf "${RED}You need to be a member of the sudo group to run me!${RC}\n"
|
2024-07-13 02:57:34 +01:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
DTYPE="unknown" # Default to unknown
|
2024-07-14 00:15:20 +01:00
|
|
|
# Use /etc/os-release for modern distro identification
|
|
|
|
if [ -f /etc/os-release ]; then
|
2024-07-14 03:16:02 +01:00
|
|
|
. /etc/os-release
|
|
|
|
DTYPE=$ID
|
2024-07-14 00:15:20 +01:00
|
|
|
fi
|
2024-07-13 02:57:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fastUpdate() {
|
|
|
|
case ${PACKAGER} in
|
|
|
|
pacman)
|
|
|
|
if ! command_exists yay && ! command_exists paru; then
|
2024-07-14 03:16:02 +01:00
|
|
|
printf "Installing yay as AUR helper...\n"
|
2024-07-13 02:57:34 +01:00
|
|
|
sudo ${PACKAGER} --noconfirm -S base-devel
|
|
|
|
cd /opt && sudo git clone https://aur.archlinux.org/yay-git.git && sudo chown -R ${USER}:${USER} ./yay-git
|
|
|
|
cd yay-git && makepkg --noconfirm -si
|
|
|
|
else
|
2024-07-14 03:16:02 +01:00
|
|
|
printf "Aur helper already installed\n"
|
2024-07-13 02:57:34 +01:00
|
|
|
fi
|
|
|
|
if command_exists yay; then
|
|
|
|
AUR_HELPER="yay"
|
|
|
|
elif command_exists paru; then
|
|
|
|
AUR_HELPER="paru"
|
|
|
|
else
|
2024-07-14 03:16:02 +01:00
|
|
|
printf "No AUR helper found. Please install yay or paru.\n"
|
2024-07-13 02:57:34 +01:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
${AUR_HELPER} --noconfirm -S rate-mirrors-bin
|
|
|
|
sudo cp /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.bak
|
2024-07-14 00:15:20 +01:00
|
|
|
|
|
|
|
# If for some reason DTYPE is still unknown use always arch so the rate-mirrors does not fail
|
2024-07-14 03:16:02 +01:00
|
|
|
dtype_local=${DTYPE}
|
|
|
|
if [ "${DTYPE}" = "unknown" ]; then
|
2024-07-14 00:15:20 +01:00
|
|
|
dtype_local="arch"
|
|
|
|
fi
|
|
|
|
sudo rate-mirrors --top-mirrors-number-to-retest=5 --disable-comments --save /etc/pacman.d/mirrorlist --allow-root ${dtype_local}
|
2024-07-13 02:57:34 +01:00
|
|
|
;;
|
|
|
|
apt-get|nala)
|
|
|
|
sudo apt-get update
|
|
|
|
sudo apt-get install -y nala
|
|
|
|
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
|
|
|
|
sudo nala update
|
|
|
|
PACKAGER="nala"
|
|
|
|
sudo ${PACKAGER} upgrade -y
|
|
|
|
;;
|
|
|
|
dnf)
|
|
|
|
;;
|
|
|
|
zypper)
|
|
|
|
;;
|
|
|
|
*)
|
2024-07-14 03:16:02 +01:00
|
|
|
printf "${RED}Unsupported package manager: ${PACKAGER}${RC}\n"
|
2024-07-13 02:57:34 +01:00
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
updateSystem() {
|
2024-07-14 03:16:02 +01:00
|
|
|
printf "${GREEN}Updating system${RC}\n"
|
2024-07-13 02:57:34 +01:00
|
|
|
case ${PACKAGER} in
|
|
|
|
nala)
|
|
|
|
sudo ${PACKAGER} update -y
|
|
|
|
sudo ${PACKAGER} upgrade -y
|
|
|
|
;;
|
|
|
|
yum)
|
|
|
|
sudo ${PACKAGER} update -y
|
|
|
|
sudo ${PACKAGER} upgrade -y
|
|
|
|
;;
|
|
|
|
dnf)
|
|
|
|
sudo ${PACKAGER} update -y
|
|
|
|
sudo ${PACKAGER} upgrade -y
|
|
|
|
;;
|
|
|
|
pacman)
|
|
|
|
sudo ${PACKAGER} -Syu --noconfirm
|
|
|
|
;;
|
|
|
|
zypper)
|
|
|
|
sudo ${PACKAGER} refresh
|
|
|
|
sudo ${PACKAGER} update -y
|
|
|
|
;;
|
|
|
|
*)
|
2024-07-14 03:16:02 +01:00
|
|
|
printf "${RED}Unsupported package manager: ${PACKAGER}${RC}\n"
|
2024-07-13 02:57:34 +01:00
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
checkEnv
|
|
|
|
fastUpdate
|
2024-07-14 03:16:02 +01:00
|
|
|
updateSystem
|