mirror of
ssh://git.janware.com/srv/git/janware/proj/jw-pkg
synced 2026-01-15 03:53:32 +01:00
pkg-manager.sh: Support running without sudo
To support minimal environments, notably minimal Docker containers which don't have /usr/bin/sudo by the time pkg-manager.sh is invoked (possibly to install sudo), support running all commands without invoking sudo first. Of course this only works if invoked as root. Note that this is still somewhat hacky, command-line parsing needs to be cleaned up. Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
cb2fa0c755
commit
f6c3f49fca
1 changed files with 17 additions and 9 deletions
|
|
@ -45,13 +45,15 @@ cmd_dup()
|
|||
done
|
||||
shift
|
||||
|
||||
[ "$sudo" ] && sudo="$sudo $env -S"
|
||||
|
||||
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"
|
||||
}
|
||||
run sudo $env -S zypper $global_opts dup $opts "$@"
|
||||
run $sudo zypper $global_opts dup $opts "$@"
|
||||
;;
|
||||
debian|ubuntu|raspbian)
|
||||
fatal "Tried to run distribution upgrade on unsupported platform \"$ID\""
|
||||
|
|
@ -84,30 +86,32 @@ cmd_install()
|
|||
done
|
||||
shift
|
||||
|
||||
[ "$sudo" ] && sudo="$sudo $env -S"
|
||||
|
||||
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"
|
||||
}
|
||||
run sudo $env -S zypper $global_opts install $opts "$@"
|
||||
run $sudo zypper $global_opts install $opts "$@"
|
||||
;;
|
||||
debian|ubuntu|raspbian)
|
||||
[ "$non_interactive" = 1 ] && {
|
||||
global_opts="$global_opts -yq"
|
||||
env="$env DEBIAN_FRONTEND=noninteractive"
|
||||
}
|
||||
run sudo $env -S apt-get $global_opts install "$@"
|
||||
run $sudo apt-get $global_opts install "$@"
|
||||
;;
|
||||
arch)
|
||||
[ "$non_interactive" = 1 ] && {
|
||||
global_opts="$global_opts --noconfirm"
|
||||
env="$env DEBIAN_FRONTEND=noninteractive"
|
||||
}
|
||||
run sudo $env -S pacman $global_opts -S --needed "$@"
|
||||
run $sudo pacman $global_opts -S --needed "$@"
|
||||
;;
|
||||
centos)
|
||||
run sudo $env -S yum $global_opts install -y "$@"
|
||||
run $sudo yum $global_opts install -y "$@"
|
||||
;;
|
||||
*)
|
||||
fatal "Tried to install on unsupported platform \"$ID\""
|
||||
|
|
@ -131,19 +135,21 @@ cmd_refresh()
|
|||
done
|
||||
shift
|
||||
|
||||
[ "$sudo" ] && sudo="$sudo $env -S"
|
||||
|
||||
case $ID in
|
||||
opensuse|suse)
|
||||
[ "$non_interactive" = 1 ] && {
|
||||
global_opts="$global_opts --non-interactive --gpg-auto-import-keys --no-gpg-checks"
|
||||
}
|
||||
run sudo $env -S zypper $global_opts refresh $opts "$@"
|
||||
run $sudo zypper $global_opts refresh $opts "$@"
|
||||
;;
|
||||
debian|ubuntu|raspbian)
|
||||
run sudo $env -S apt-get $global_opts update "$@"
|
||||
run $sudo apt-get $global_opts update "$@"
|
||||
;;
|
||||
centos)
|
||||
run sudo $env -S yum $global_opts clean expire-cache "$@"
|
||||
run sudo $env -S yum $global_opts makecache "$@"
|
||||
run $sudo yum $global_opts clean expire-cache "$@"
|
||||
run $sudo yum $global_opts makecache "$@"
|
||||
;;
|
||||
*)
|
||||
fatal "Tried to update unsupported platform \"$ID\""
|
||||
|
|
@ -155,6 +161,8 @@ cmd_refresh()
|
|||
myname=`basename $0`
|
||||
. /etc/os-release
|
||||
ID=${ID%%-*}
|
||||
[ "$EUID" ] || EUID=$(id -un)
|
||||
[ "$EUID" = 0 ] || sudo=/usr/bin/sudo
|
||||
cmd="$1"
|
||||
shift
|
||||
cmd_$cmd "$@"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue