kiss: clean up argument handling

This commit is contained in:
Dylan Araps 2020-09-14 12:22:25 +03:00
parent 1e0c80493a
commit 6dde0696d8
No known key found for this signature in database
GPG Key ID: 46D62DD9F1DE636E
1 changed files with 33 additions and 29 deletions

62
kiss
View File

@ -1373,41 +1373,45 @@ args() {
action=$1 action=$1
shift "$(($# != 0))" shift "$(($# != 0))"
# Unless this is a search, sanitize the user's input. The call to case $action in
# 'pkg_find()' supports basic globbing, ensure input doesn't expand b|build|c|checksum|d|download|i|install|r|remove)
# to anything except for when this behavior is needed. # This handles the globbing characters '*', '!', '[' and ']' and
# # basic white-space. Invalid input characters in other words.
# This handles the globbing characters '*', '!', '[' and ']' as per: case "$*" in
# https://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html *'*'*|*'!'*|*'['*|*']'*|*' '*|*' '*)
[ "${action##[as]*}" ] && case "$*" in *\**|*\!*|*\[*|*\]*) die "Arguments contain invalid characters: '!*[ \t]'"
die "Arguments contain invalid characters: '!*[]' ($*)" ;;
esac esac
# CRUX style usage using the current directory as the name of the package # CRUX style usage using the current directory as the name of the
# to be operated on. This needs to sit before the 'as_root()' calls as # package to be operated on. This needs to sit before the 'as_root()'
# they reset the current working directory during their invocations. # calls as they reset the cwd during their invocations.
[ "$1" ] || case $action in b|build|c|checksum|d|download|i|install|r|remove) [ "$1" ] || {
export KISS_PATH=${PWD%/*}:$KISS_PATH export KISS_PATH=${PWD%/*}:$KISS_PATH
set -- "${PWD##*/}" set -- "${PWD##*/}"
}
;;
esac esac
# Rerun the script as root with a fixed environment if needed. We sadly # Rerun the script as root with a fixed environment if needed. We sadly
# can't run singular functions as root so this is needed. # can't run singular functions as root so this is needed.
case $action in a|alternatives|i|install|r|remove) case $action in
[ -z "$1" ] || [ -w "$KISS_ROOT/" ] || [ "$uid" = 0 ] || { a|alternatives|i|install|r|remove)
as_root HOME="$HOME" \ [ -z "$1" ] || [ -w "$KISS_ROOT/" ] || [ "$uid" = 0 ] || {
XDG_CACHE_HOME="$XDG_CACHE_HOME" \ as_root HOME="$HOME" \
KISS_PATH="$KISS_PATH" \ XDG_CACHE_HOME="$XDG_CACHE_HOME" \
KISS_FORCE="$KISS_FORCE" \ KISS_PATH="$KISS_PATH" \
KISS_ROOT="$KISS_ROOT" \ KISS_FORCE="$KISS_FORCE" \
KISS_CHOICE="$KISS_CHOICE" \ KISS_ROOT="$KISS_ROOT" \
KISS_COLOR="$KISS_COLOR" \ KISS_CHOICE="$KISS_CHOICE" \
KISS_TMPDIR="$KISS_TMPDIR" \ KISS_COLOR="$KISS_COLOR" \
KISS_PID="$KISS_PID" \ KISS_TMPDIR="$KISS_TMPDIR" \
"$0" "$action" "$@" KISS_PID="$KISS_PID" \
"$0" "$action" "$@"
return return
} }
;;
esac esac
# Actions can be abbreviated to their first letter. This saves keystrokes # Actions can be abbreviated to their first letter. This saves keystrokes