linutil/src/commands/system-update.sh

108 lines
3.4 KiB
Bash
Raw Normal View History

2024-07-15 20:00:04 +01:00
#!/bin/sh -e
. ./common-script.sh
2024-07-13 02:57:34 +01:00
fastUpdate() {
case ${PACKAGER} in
pacman)
if ! command_exists yay && ! command_exists paru; then
echo "Installing yay as AUR helper..."
sudo ${PACKAGER} --noconfirm -S base-devel || { echo -e "${RED}Failed to install base-devel${RC}"; exit 1; }
2024-07-13 02:57:34 +01:00
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 || { echo -e "${RED}Failed to install yay${RC}"; exit 1; }
2024-07-13 02:57:34 +01:00
else
echo "Aur helper already installed"
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
echo "No AUR helper found. Please install yay or paru."
2024-07-13 02:57:34 +01:00
exit 1
fi
${AUR_HELPER} --noconfirm -S rate-mirrors-bin
2024-07-18 21:44:20 +01:00
if [ -s /etc/pacman.d/mirrorlist ]; then
sudo cp /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.bak
fi
# 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
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
2024-07-14 05:02:52 +01:00
if ! command_exists nala; then
sudo apt-get install -y nala || { echo -e "${YELLOW}Falling back to apt-get${RC}"; PACKAGER="apt-get"; }
2024-07-14 05:02:52 +01:00
fi
if [ "${PACKAGER}" = "nala" ]; then
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
sudo nala update
PACKAGER="nala"
fi
2024-07-13 02:57:34 +01:00
sudo ${PACKAGER} upgrade -y
;;
dnf)
2024-07-14 05:02:52 +01:00
sudo ${PACKAGER} update -y
2024-07-13 02:57:34 +01:00
;;
zypper)
sudo ${PACKAGER} ref
sudo ${PACKAGER} --non-interactive dup
2024-07-14 05:02:52 +01:00
;;
yum)
sudo ${PACKAGER} update -y
sudo ${PACKAGER} upgrade -y
2024-07-13 02:57:34 +01:00
;;
2024-07-16 12:49:44 +01:00
xbps-install)
sudo ${PACKAGER} -Syu
;;
2024-07-13 02:57:34 +01:00
*)
echo -e "${RED}Unsupported package manager: $PACKAGER${RC}"
2024-07-13 02:57:34 +01:00
exit 1
;;
esac
}
updateSystem() {
echo -e "${GREEN}Updating system${RC}"
2024-07-13 02:57:34 +01:00
case ${PACKAGER} in
2024-07-14 05:02:52 +01:00
nala|apt-get)
sudo "${PACKAGER}" update -y
sudo "${PACKAGER}" upgrade -y
2024-07-13 02:57:34 +01:00
;;
2024-07-14 05:02:52 +01:00
yum|dnf)
sudo "${PACKAGER}" update -y
sudo "${PACKAGER}" upgrade -y
2024-07-13 02:57:34 +01:00
;;
pacman)
sudo "${PACKAGER}" -Sy --noconfirm --needed archlinux-keyring
sudo "${PACKAGER}" -Su --noconfirm
2024-07-13 02:57:34 +01:00
;;
zypper)
sudo ${PACKAGER} ref
sudo ${PACKAGER} --non-interactive dup
2024-07-13 02:57:34 +01:00
;;
2024-07-16 12:49:44 +01:00
xbps-install)
sudo ${PACKAGER} -Syu
;;
2024-07-13 02:57:34 +01:00
*)
echo -e "${RED}Unsupported package manager: ${PACKAGER}${RC}"
2024-07-13 02:57:34 +01:00
exit 1
;;
esac
}
2024-07-31 11:30:07 +01:00
updateFlatpaks() {
if command_exists flatpak; then
flatpak update -y
fi
}
2024-07-13 02:57:34 +01:00
checkEnv
fastUpdate
2024-07-16 12:49:44 +01:00
updateSystem
2024-07-31 11:30:07 +01:00
updateFlatpaks