diff options
Diffstat (limited to 'xi')
-rw-r--r--[-rwxr-xr-x] | xi | 67 |
1 files changed, 42 insertions, 25 deletions
diff --git a/xi b/xi index 0541b3c..df328f1 100755..100644 --- a/xi +++ b/xi @@ -1,38 +1,55 @@ #!/bin/sh # xi PKGS... - like xbps-install -S, but take cwd repo and sudo/su into account -BRANCH=$(git symbolic-ref -q --short HEAD 2>/dev/null) if [ -n "$XBPS_HOSTDIR" ]; then XBPS_BINPKGS="$XBPS_HOSTDIR/binpkgs" else XBPS_DISTDIR="$(xdistdir 2>/dev/null)" || XBPS_DISTDIR=. XBPS_BINPKGS="$XBPS_DISTDIR/hostdir/binpkgs" fi -ADDREPO=" - --repository=$XBPS_BINPKGS/$BRANCH - --repository=$XBPS_BINPKGS/$BRANCH/nonfree - --repository=$XBPS_BINPKGS/$BRANCH/multilib - --repository=$XBPS_BINPKGS/$BRANCH/multilib/nonfree - --repository=$XBPS_BINPKGS/$BRANCH/debug - --repository=$XBPS_BINPKGS - --repository=$XBPS_BINPKGS/nonfree - --repository=$XBPS_BINPKGS/multilib - --repository=$XBPS_BINPKGS/multilib/nonfree - --repository=$XBPS_BINPKGS/debug -" -SUDO= -if command -v sudo >/dev/null && - sudo -l | grep -q -e ' ALL$' -e xbps-install; then - SUDO=sudo -elif command -v doas >/dev/null && [ -f /etc/doas.conf ]; then - SUDO=doas -elif [ "$(whoami)" != root ]; then - SUDO='su root -c '\''"$@"'\'' -- -' +set -- \ + --repository="$XBPS_BINPKGS" \ + --repository="$XBPS_BINPKGS/nonfree" \ + --repository="$XBPS_BINPKGS/multilib" \ + --repository="$XBPS_BINPKGS/multilib/nonfree" \ + --repository="$XBPS_BINPKGS/debug" \ + "$@" + +if BRANCH=$(git symbolic-ref -q --short HEAD 2>/dev/null) && [ -n "$BRANCH" ]; then + set -- \ + --repository="$XBPS_BINPKGS/$BRANCH" \ + --repository="$XBPS_BINPKGS/$BRANCH/nonfree" \ + --repository="$XBPS_BINPKGS/$BRANCH/multilib" \ + --repository="$XBPS_BINPKGS/$BRANCH/multilib/nonfree" \ + --repository="$XBPS_BINPKGS/$BRANCH/debug" \ + "$@" fi -$SUDO xbps-install $ADDREPO -S "$@" -if [ $? -eq 16 ]; then - $SUDO xbps-install -u xbps - $SUDO xbps-install $ADDREPO -S "$@" +which_sudo() { + if command -v sudo >/dev/null && sudo -l | grep -q -e ' ALL$' -e xbps-install; then + echo sudo + elif command -v doas >/dev/null && [ -f /etc/doas.conf ]; then + echo doas + elif [ "$(id -u)" != 0 ]; then + echo su + fi +} + +do_install() { + if [ "$SUDO" = su ]; then + su root -c 'xbps-install "$@"' -- sh "$@" + else + $SUDO xbps-install "$@" + fi +} + +SUDO=$(which_sudo) +do_install -S "$@" +status=$? +if [ $status -eq 16 ]; then + do_install -u xbps && + do_install -S "$@" +else + exit $status fi |