linutil/tabs/system-setup/system-update.sh

103 lines
3.1 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)
2024-08-27 22:40:44 +01:00
$AUR_HELPER -S --needed --noconfirm rate-mirrors-bin
2024-08-27 22:40:44 +01:00
2024-07-18 21:44:20 +01:00
if [ -s /etc/pacman.d/mirrorlist ]; then
2024-08-23 14:12:47 +01:00
$ESCALATION_TOOL cp /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.bak
2024-07-18 21:44:20 +01:00
fi
2024-08-27 22:40:44 +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
dtype_local="arch"
fi
2024-08-27 22:40:44 +01:00
2024-08-23 14:12:47 +01:00
$ESCALATION_TOOL rate-mirrors --top-mirrors-number-to-retest=5 --disable-comments --save /etc/pacman.d/mirrorlist --allow-root ${dtype_local}
2024-08-27 22:40:44 +01:00
if [ $? -ne 0 ] || [ ! -s /etc/pacman.d/mirrorlist ]; then
2024-09-12 21:14:50 +01:00
printf "%b\n" "${RED}Rate-mirrors failed, restoring backup.${RC}"
2024-08-27 22:40:44 +01:00
$ESCALATION_TOOL cp /etc/pacman.d/mirrorlist.bak /etc/pacman.d/mirrorlist
fi
2024-07-13 02:57:34 +01:00
;;
2024-08-29 06:56:50 +01:00
2024-07-13 02:57:34 +01:00
apt-get|nala)
2024-08-23 14:12:47 +01:00
$ESCALATION_TOOL apt-get update
2024-07-14 05:02:52 +01:00
if ! command_exists nala; then
2024-09-12 21:14:50 +01:00
$ESCALATION_TOOL apt-get install -y nala || { printf "%b\n" "${YELLOW}Falling back to apt-get${RC}"; PACKAGER="apt-get"; }
2024-07-14 05:02:52 +01:00
fi
2024-08-27 22:40:44 +01:00
2024-07-14 05:02:52 +01:00
if [ "${PACKAGER}" = "nala" ]; then
2024-08-23 14:12:47 +01:00
$ESCALATION_TOOL cp /etc/apt/sources.list /etc/apt/sources.list.bak
$ESCALATION_TOOL nala update
2024-07-14 05:02:52 +01:00
PACKAGER="nala"
fi
2024-08-27 22:40:44 +01:00
2024-08-23 14:12:47 +01:00
$ESCALATION_TOOL ${PACKAGER} upgrade -y
2024-07-13 02:57:34 +01:00
;;
dnf)
2024-08-23 14:12:47 +01:00
$ESCALATION_TOOL ${PACKAGER} update -y
2024-07-13 02:57:34 +01:00
;;
zypper)
2024-08-23 14:12:47 +01:00
$ESCALATION_TOOL ${PACKAGER} ref
$ESCALATION_TOOL ${PACKAGER} --non-interactive dup
2024-07-14 05:02:52 +01:00
;;
yum)
2024-08-23 14:12:47 +01:00
$ESCALATION_TOOL ${PACKAGER} update -y
$ESCALATION_TOOL ${PACKAGER} upgrade -y
2024-07-13 02:57:34 +01:00
;;
2024-07-16 12:49:44 +01:00
xbps-install)
2024-08-23 14:12:47 +01:00
$ESCALATION_TOOL ${PACKAGER} -Syu
2024-07-16 12:49:44 +01:00
;;
2024-07-13 02:57:34 +01:00
*)
2024-09-12 21:14:50 +01:00
printf "%b\n" "${RED}Unsupported package manager: $PACKAGER${RC}"
2024-07-13 02:57:34 +01:00
exit 1
;;
esac
}
updateSystem() {
2024-09-17 03:10:02 +01:00
printf "%b\n" "${YELLOW}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)
2024-08-23 14:12:47 +01:00
$ESCALATION_TOOL "${PACKAGER}" update -y
$ESCALATION_TOOL "${PACKAGER}" upgrade -y
2024-07-13 02:57:34 +01:00
;;
2024-07-14 05:02:52 +01:00
yum|dnf)
2024-08-23 14:12:47 +01:00
$ESCALATION_TOOL "${PACKAGER}" update -y
$ESCALATION_TOOL "${PACKAGER}" upgrade -y
2024-07-13 02:57:34 +01:00
;;
pacman)
2024-08-23 14:12:47 +01:00
$ESCALATION_TOOL "${PACKAGER}" -Sy --noconfirm --needed archlinux-keyring
$ESCALATION_TOOL "${PACKAGER}" -Su --noconfirm
2024-07-13 02:57:34 +01:00
;;
zypper)
2024-08-23 14:12:47 +01:00
$ESCALATION_TOOL ${PACKAGER} ref
$ESCALATION_TOOL ${PACKAGER} --non-interactive dup
2024-07-13 02:57:34 +01:00
;;
2024-07-16 12:49:44 +01:00
xbps-install)
2024-08-23 14:12:47 +01:00
$ESCALATION_TOOL ${PACKAGER} -Syu
2024-07-16 12:49:44 +01:00
;;
2024-07-13 02:57:34 +01:00
*)
2024-09-12 21:14:50 +01:00
printf "%b\n" "${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
2024-09-06 00:23:24 +01:00
checkAURHelper
2024-08-23 14:12:47 +01:00
checkEscalationTool
2024-07-13 02:57:34 +01:00
fastUpdate
2024-07-16 12:49:44 +01:00
updateSystem
2024-09-05 00:05:58 +01:00
updateFlatpaks