2024-06-02 22:13:33 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
# sc.requires: logger
|
|
|
|
|
2024-06-06 02:00:49 +02:00
|
|
|
pm_detect_package_manager() {
|
|
|
|
if command -v apt >/dev/null; then
|
2024-06-02 22:13:33 +02:00
|
|
|
echo apt
|
2024-06-06 02:00:49 +02:00
|
|
|
elif command -v pacman >/dev/null; then
|
|
|
|
echo pacman
|
|
|
|
elif command -v dnf >/dev/null; then
|
2024-06-02 22:13:33 +02:00
|
|
|
echo dnf
|
2024-06-06 02:00:49 +02:00
|
|
|
elif command -v yum >/dev/null; then
|
2024-06-02 22:13:33 +02:00
|
|
|
echo yum
|
2024-06-06 02:00:49 +02:00
|
|
|
elif command -v zypper >/dev/null; then
|
2024-06-02 22:13:33 +02:00
|
|
|
echo zypper
|
2024-06-06 02:00:49 +02:00
|
|
|
elif command -v brew >/dev/null; then
|
2024-06-02 22:13:33 +02:00
|
|
|
echo brew
|
2024-06-06 02:00:49 +02:00
|
|
|
elif command -v apk >/dev/null; then
|
2024-06-02 22:13:33 +02:00
|
|
|
echo apk
|
2024-06-06 02:00:49 +02:00
|
|
|
elif command -v nix-env >/dev/null; then
|
2024-06-02 22:13:33 +02:00
|
|
|
echo nix
|
|
|
|
else
|
|
|
|
fatal_log "no supported package manager found"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2024-06-06 02:00:49 +02:00
|
|
|
SC_PACKAGE_MANAGER="${SC_PACKAGE_MANAGER:-$(pm_detect_package_manager)}"
|
2024-06-02 22:13:33 +02:00
|
|
|
|
2024-06-06 02:00:49 +02:00
|
|
|
pm_upgrade_packages() {
|
|
|
|
LOGI "Upgrading packages using ${SC_PACKAGE_MANAGER}..."
|
|
|
|
|
|
|
|
case "$SC_PACKAGE_MANAGER" in
|
|
|
|
apt)
|
|
|
|
sudo apt update && sudo apt upgrade -y
|
|
|
|
;;
|
|
|
|
pacman)
|
|
|
|
sudo pacman -Syu
|
|
|
|
;;
|
|
|
|
dnf)
|
|
|
|
sudo dnf upgrade --refresh -y
|
|
|
|
;;
|
|
|
|
yum)
|
|
|
|
sudo yum update -y
|
|
|
|
;;
|
|
|
|
zypper)
|
|
|
|
sudo zypper refresh && sudo zypper update -y
|
|
|
|
;;
|
|
|
|
brew)
|
|
|
|
brew update && brew upgrade
|
|
|
|
;;
|
|
|
|
apk)
|
|
|
|
sudo apk update && sudo apk upgrade
|
|
|
|
;;
|
|
|
|
nix)
|
|
|
|
nix-env --upgrade
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
fatal_log "Unsupported package manager: ${SC_PACKAGE_MANAGER}"
|
|
|
|
exit 1
|
|
|
|
;;
|
2024-06-02 22:13:33 +02:00
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2024-06-06 02:00:49 +02:00
|
|
|
pm_install_packages() {
|
|
|
|
LOGI "Installing packages using ${SC_PACKAGE_MANAGER}..."
|
|
|
|
packages="$@"
|
|
|
|
|
|
|
|
case "$SC_PACKAGE_MANAGER" in
|
|
|
|
apt)
|
|
|
|
sudo apt install -y $packages
|
|
|
|
;;
|
|
|
|
pacman)
|
|
|
|
sudo pacman -S --noconfirm $packages
|
|
|
|
;;
|
|
|
|
dnf)
|
|
|
|
sudo dnf install -y $packages
|
|
|
|
;;
|
|
|
|
yum)
|
|
|
|
sudo yum install -y $packages
|
|
|
|
;;
|
|
|
|
zypper)
|
|
|
|
sudo zypper install -y $packages
|
|
|
|
;;
|
|
|
|
brew)
|
|
|
|
brew install $packages
|
|
|
|
;;
|
|
|
|
apk)
|
|
|
|
sudo apk add $packages
|
|
|
|
;;
|
|
|
|
nix)
|
|
|
|
nix-env -i $packages
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
fatal_log "Unsupported package manager: ${SC_PACKAGE_MANAGER}"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
pm_remove_packages() {
|
|
|
|
LOGI "Removing packages using ${SC_PACKAGE_MANAGER}..."
|
|
|
|
packages="$@"
|
|
|
|
|
|
|
|
case "$SC_PACKAGE_MANAGER" in
|
|
|
|
apt)
|
|
|
|
sudo apt remove -y $packages
|
|
|
|
;;
|
|
|
|
pacman)
|
|
|
|
sudo pacman -Rns --noconfirm $packages
|
|
|
|
;;
|
|
|
|
dnf)
|
|
|
|
sudo dnf remove -y $packages
|
|
|
|
;;
|
|
|
|
yum)
|
|
|
|
sudo yum remove -y $packages
|
|
|
|
;;
|
|
|
|
zypper)
|
|
|
|
sudo zypper remove -y $packages
|
|
|
|
;;
|
|
|
|
brew)
|
|
|
|
brew uninstall $packages
|
|
|
|
;;
|
|
|
|
apk)
|
|
|
|
sudo apk del $packages
|
|
|
|
;;
|
|
|
|
nix)
|
|
|
|
nix-env -e $packages
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
fatal_log "Unsupported package manager: ${SC_PACKAGE_MANAGER}"
|
|
|
|
exit 1
|
|
|
|
;;
|
2024-06-02 22:13:33 +02:00
|
|
|
esac
|
|
|
|
}
|