1
0
mirror of https://codeberg.org/kiss-community/kiss synced 2024-07-03 06:22:27 +00:00

kiss: as_root: Move to func

This commit is contained in:
Dylan Araps 2020-01-30 09:50:18 +02:00
parent a7580cc8ee
commit 3e86270338
No known key found for this signature in database
GPG Key ID: 46D62DD9F1DE636E

12
kiss
View File

@ -49,6 +49,7 @@ prompt() {
} }
as_root() { as_root() {
[ "$(id -u)" = 0 ] || {
if command -v sudo >/dev/null; then if command -v sudo >/dev/null; then
sudo -E KISS_FORCE="$KISS_FORCE" "$@" sudo -E KISS_FORCE="$KISS_FORCE" "$@"
elif command -v doas >/dev/null; then elif command -v doas >/dev/null; then
@ -56,6 +57,9 @@ as_root() {
else else
su -pc "KISS_FORCE=$KISS_FORCE $*" su -pc "KISS_FORCE=$KISS_FORCE $*"
fi fi
exit
}
} }
regex_escape() { regex_escape() {
@ -1153,10 +1157,7 @@ args() {
a|alternatives) a|alternatives)
# Rerun the script with 'su' if the user isn't root. # Rerun the script with 'su' if the user isn't root.
# Cheeky but 'su' can't be used on shell functions themselves. # Cheeky but 'su' can't be used on shell functions themselves.
[ -z "$1" ] || [ "$(id -u)" = 0 ] || { [ -z "$1" ] || as_root kiss "$action" "$@"
as_root kiss "$action" "$@"
return
}
;; ;;
i|install|r|remove) i|install|r|remove)
@ -1164,10 +1165,7 @@ args() {
# Rerun the script with 'su' if the user isn't root. # Rerun the script with 'su' if the user isn't root.
# Cheeky but 'su' can't be used on shell functions themselves. # Cheeky but 'su' can't be used on shell functions themselves.
[ "$(id -u)" = 0 ] || {
as_root kiss "$action" "$@" as_root kiss "$action" "$@"
return
}
;; ;;
esac esac