32 lines
576 B
Bash
Executable File
32 lines
576 B
Bash
Executable File
#!/bin/sh
|
|
# xr PKGS... - like xbps-remove -o, but take sudo/su into account
|
|
|
|
which_sudo() {
|
|
if command -v sudo >/dev/null && sudo -l | grep -q -e ' ALL$' -e xbps-remove; 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_remove() {
|
|
if [ "$SUDO" = su ]; then
|
|
su root -c 'xbps-remove "$@"' -- sh "$@"
|
|
else
|
|
$SUDO xbps-remove "$@"
|
|
fi
|
|
}
|
|
|
|
SUDO=$(which_sudo)
|
|
do_remove -R "$@"
|
|
|
|
status=$?
|
|
if [ $status -eq 16 ]; then
|
|
do_install -u xbps &&
|
|
do_install -S "$@"
|
|
else
|
|
exit $status
|
|
fi
|