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

105 lines
3.7 KiB
Bash
Raw Normal View History

2024-07-15 14:00:04 -05:00
#!/bin/sh -e
. ../common-script.sh
2024-07-12 20:57:34 -05:00
fastUpdate() {
2024-09-17 18:19:41 +05:30
case "$PACKAGER" in
2024-07-12 20:57:34 -05:00
pacman)
2024-11-08 20:33:41 +05:30
"$AUR_HELPER" -S --needed --noconfirm rate-mirrors-bin
2024-09-19 08:02:44 +05:30
printf "%b\n" "${YELLOW}Generating a new list of mirrors using rate-mirrors. This process may take a few seconds...${RC}"
2024-08-27 17:40:44 -04:00
2024-11-08 20:33:41 +05:30
if [ -s "/etc/pacman.d/mirrorlist" ]; then
"$ESCALATION_TOOL" cp /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.bak
2024-07-18 15:44:20 -05:00
fi
2024-08-27 17:40:44 -04:00
# If for some reason DTYPE is still unknown use always arch so the rate-mirrors does not fail
2024-11-08 20:33:41 +05:30
dtype_local="$DTYPE"
if [ "$dtype_local" = "unknown" ]; then
dtype_local="arch"
fi
2024-08-27 17:40:44 -04:00
2024-11-08 20:33:41 +05:30
if ! "$ESCALATION_TOOL" rate-mirrors --top-mirrors-number-to-retest=5 --disable-comments --save /etc/pacman.d/mirrorlist --allow-root "$dtype_local" > /dev/null || [ ! -s "/etc/pacman.d/mirrorlist" ]; then
2024-09-12 16:14:50 -04:00
printf "%b\n" "${RED}Rate-mirrors failed, restoring backup.${RC}"
"$ESCALATION_TOOL" cp /etc/pacman.d/mirrorlist.bak /etc/pacman.d/mirrorlist
2024-08-27 17:40:44 -04:00
fi
2024-07-12 20:57:34 -05:00
;;
apt-get|nala)
2024-11-08 20:33:41 +05:30
if [ "$PACKAGER" = "apt-get" ]; then
printf "%b\n" "${YELLOW}Installing nala for faster updates.${RC}"
"$ESCALATION_TOOL" "$PACKAGER" update
if "$ESCALATION_TOOL" "$PACKAGER" install -y nala; then
PACKAGER="nala";
printf "%b\n" "${CYAN}Using $PACKAGER as package manager${RC}"
else
printf "%b\n" "${RED}Nala installation failed.${RC}"
printf "%b\n" "${YELLOW}Falling back to apt-get.${RC}"
fi
2024-07-13 23:02:52 -05:00
fi
2024-08-27 17:40:44 -04:00
2024-09-17 17:53:23 +05:30
if [ "$PACKAGER" = "nala" ]; then
2024-11-08 20:33:41 +05:30
if [ -f "/etc/apt/sources.list.d/nala-sources.list" ]; then
"$ESCALATION_TOOL" cp /etc/apt/sources.list.d/nala-sources.list /etc/apt/sources.list.d/nala-sources.list.bak
fi
if ! "$ESCALATION_TOOL" nala fetch --auto -y || [ ! -s "/etc/apt/sources.list.d/nala-sources.list" ]; then
printf "%b\n" "${RED}Nala fetch failed, restoring backup.${RC}"
"$ESCALATION_TOOL" cp /etc/apt/sources.list.d/nala-sources.list.bak /etc/apt/sources.list.d/nala-sources.list
fi
2024-07-13 23:02:52 -05:00
fi
2024-07-12 20:57:34 -05:00
;;
dnf)
"$ESCALATION_TOOL" "$PACKAGER" update -y
2024-07-12 20:57:34 -05:00
;;
zypper)
"$ESCALATION_TOOL" "$PACKAGER" ref
2024-07-13 23:02:52 -05:00
;;
apk)
"$ESCALATION_TOOL" "$PACKAGER" update
;;
2024-07-12 20:57:34 -05:00
*)
2024-11-08 20:33:41 +05:30
printf "%b\n" "${RED}Unsupported package manager: ${PACKAGER}${RC}"
2024-07-12 20:57:34 -05:00
exit 1
;;
esac
}
updateSystem() {
2024-11-08 20:33:41 +05:30
printf "%b\n" "${YELLOW}Updating system packages.${RC}"
2024-09-17 17:53:23 +05:30
case "$PACKAGER" in
apt-get|nala)
"$ESCALATION_TOOL" "$PACKAGER" upgrade -y
2024-07-12 20:57:34 -05:00
;;
dnf)
"$ESCALATION_TOOL" "$PACKAGER" upgrade -y
2024-07-12 20:57:34 -05:00
;;
pacman)
"$ESCALATION_TOOL" "$PACKAGER" -Sy --noconfirm --needed archlinux-keyring
2024-11-08 20:33:41 +05:30
"$AUR_HELPER" -Su --noconfirm
2024-07-12 20:57:34 -05:00
;;
zypper)
"$ESCALATION_TOOL" "$PACKAGER" --non-interactive dup
2024-07-12 20:57:34 -05:00
;;
apk)
"$ESCALATION_TOOL" "$PACKAGER" upgrade
;;
2024-07-12 20:57:34 -05:00
*)
2024-11-08 20:33:41 +05:30
printf "%b\n" "${RED}Unsupported package manager: ${PACKAGER}${RC}"
2024-07-12 20:57:34 -05:00
exit 1
;;
esac
}
2024-07-31 03:30:07 -07:00
updateFlatpaks() {
if command_exists flatpak; then
2024-11-08 20:33:41 +05:30
printf "%b\n" "${YELLOW}Updating flatpak packages.${RC}"
flatpak update -y
2024-07-31 03:30:07 -07:00
fi
}
2024-07-12 20:57:34 -05:00
checkEnv
2024-09-05 19:23:24 -04:00
checkAURHelper
2024-08-23 09:12:47 -04:00
checkEscalationTool
2024-07-12 20:57:34 -05:00
fastUpdate
2024-07-16 13:49:44 +02:00
updateSystem
2024-09-19 08:02:44 +05:30
updateFlatpaks