init
This commit is contained in:
commit
1816522a71
11 changed files with 229 additions and 0 deletions
64
lib/pm
Normal file
64
lib/pm
Normal file
|
@ -0,0 +1,64 @@
|
|||
#!/bin/sh
|
||||
|
||||
# sc.requires: logger
|
||||
|
||||
detect_package_manager() {
|
||||
if command -v apt > /dev/null; then
|
||||
echo apt
|
||||
elif command -v pacman > /dev/null; then
|
||||
echo arch
|
||||
elif command -v dnf > /dev/null; then
|
||||
echo dnf
|
||||
elif command -v yum > /dev/null; then
|
||||
echo yum
|
||||
elif command -v zypper > /dev/null; then
|
||||
echo zypper
|
||||
elif command -v brew > /dev/null; then
|
||||
echo brew
|
||||
elif command -v apk > /dev/null; then
|
||||
echo apk
|
||||
elif command -v nix-env > /dev/null; then
|
||||
echo nix
|
||||
else
|
||||
fatal_log "no supported package manager found"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
SC_PACKAGE_MANAGER="${SC_PACKAGE_MANAGER:-$(detect_package_manager)}"
|
||||
|
||||
upgrade_packages() {
|
||||
case $SC_PACKAGE_MANAGER in
|
||||
apt) apt update && apt upgrade -y ;;
|
||||
arch) pacman -Syyu --noconfirm ;;
|
||||
dnf) dnf upgrade -y ;;
|
||||
yum) yum update -y ;;
|
||||
zypper) zypper refresh && zypper update -y ;;
|
||||
brew) brew update && brew upgrade ;;
|
||||
apk) apk update && apk upgrade ;;
|
||||
nix) nix-channel --update && nix-env -u ;;
|
||||
*)
|
||||
fatal_log "unsupported package manager: $SC_PACKAGE_MANAGER"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
install_package() {
|
||||
[ $# -lt 1 ] && fatal_log "usage: install_package <package>" && exit 1
|
||||
package=$1
|
||||
case $SC_PACKAGE_MANAGER in
|
||||
apt) apt install -y "$package" ;;
|
||||
arch) pacman -S --noconfirm "$package" ;;
|
||||
dnf) dnf install -y "$package" ;;
|
||||
yum) yum install -y "$package" ;;
|
||||
zypper) zypper install -y "$package" ;;
|
||||
brew) brew install "$package" ;;
|
||||
apk) apk add "$package" ;;
|
||||
nix) nix-env -iA nixpkgs."$package" ;;
|
||||
*)
|
||||
fatal_log "unsupported package manager: $SC_PACKAGE_MANAGER"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue