jw-pkg/scripts/pkg-manager.sh

114 lines
1.8 KiB
Bash
Raw Normal View History

#!/bin/sh
log()
{
echo $@ >&2
}
err()
{
echo $@ >&2
}
fatal()
{
err "Giving up: $@"
exit 1
}
usage()
{
cat<<-EOT
$myname cmd args
EOT
}
run()
{
log "Running ==== $@"
eval "$@"
}
cmd_install()
{
local env opts global_opts
local non_interactive
set -- `getopt 'y' $*`
while [ "$1" != -- ] ; do
case "$1" in
-y)
non_interactive=1
;;
esac
shift
done
shift
case $ID in
opensuse|suse)
[ "$non_interactive" = 1 ] && {
opts="--force-resolution --auto-agree-with-licenses"
global_opts="$global_opts --non-interactive --gpg-auto-import-keys --no-gpg-checks"
}
eval run sudo $env -S zypper $global_opts install $opts "$@"
;;
debian|ubuntu)
[ "$non_interactive" = 1 ] && {
global_opts="$global_opts -yq"
env="$env DEBIAN_FRONTEND=noninteractive"
}
eval run sudo $env -S apt-get $global_opts install "$@"
;;
arch)
[ "$non_interactive" = 1 ] && {
global_opts="$global_opts --noconfirm"
env="$env DEBIAN_FRONTEND=noninteractive"
}
eval run sudo $env -S pacman $global_opts -S --needed "$@"
;;
*)
fatal "Tried to install on unsupported platform \"$ID\""
;;
esac
}
cmd_refresh()
{
local env opts global_opts
local non_interactive
set -- `getopt 'y' $*`
while [ "$1" != -- ] ; do
case "$1" in
-y)
non_interactive=1
;;
esac
shift
done
shift
case $ID in
opensuse|suse)
[ "$non_interactive" = 1 ] && {
global_opts="$global_opts --non-interactive --gpg-auto-import-keys --no-gpg-checks"
}
eval run sudo $env -S zypper $global_opts refresh $opts "$@"
;;
debian|ubuntu)
eval run sudo $env -S apt-get $global_opts update "$@"
;;
*)
fatal "Tried to update unsupported platform \"$ID\""
;;
esac
}
# -- here we go
myname=`basename $0`
. /etc/os-release
cmd="$1"
shift
eval cmd_$cmd "$@"