From 69534b8c7ca9a86246ac2ab7162aea02889e201f Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Tue, 20 Aug 2019 09:57:44 +0000 Subject: [PATCH] misc: cleanup --- kiss | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/kiss b/kiss index 16d2e24..413b034 100755 --- a/kiss +++ b/kiss @@ -62,7 +62,8 @@ pkg_search() { [ "$KISS_PATH" ] || die "\$KISS_PATH needs to be set" # Find the repository containing a package. - # Searches installed packages if the package is absent from the repositories. + # Searches installed packages if the package is absent + # from the repositories. set -- "$1" $(IFS=:; find $KISS_PATH "$KISS_ROOT/$pkg_db" \ -maxdepth 1 -name "$1") @@ -771,7 +772,7 @@ pkg_install() { log "[$pkg_name] Installing package" - # Block being able to abort the script with 'Ctrl+C' during installation. + # Block being able to abort the script with Ctrl+C during installation. # Removes all risk of the user aborting a package installation leaving # an incomplete package installed. trap '' INT @@ -782,13 +783,13 @@ pkg_install() { cp -f "$KISS_ROOT/$pkg_db/$pkg_name/manifest" "$cac_dir/m-$pkg_name" # This is repeated multiple times. Better to make it a function. - rsync_pkg() { + pkg_rsync() { rsync -HKav --exclude etc -- "$tar_dir/$pkg_name/" "$KISS_ROOT/" } # Install the package by using 'rsync' and overwrite any existing files # (excluding '/etc/'). - rsync_pkg + pkg_rsync # If '/etc/' exists in the package, install it but don't overwrite. [ -d "$tar_dir/$pkg_name/etc" ] && @@ -813,8 +814,8 @@ pkg_install() { # Install the package again to fix any non-leftover files being # removed above. - rsync_pkg ||: - rsync_pkg ||: + pkg_rsync ||: + pkg_rsync ||: # Reset 'trap' to its original value. Installation is done so # we no longer need to block 'Ctrl+C'. @@ -947,8 +948,10 @@ args() { # Rerun the script with 'sudo' if the user isn't root. # Cheeky but 'sudo' can't be used on shell functions themselves. - [ "$(id -u)" = 0 ] || - exec sudo KISS_PATH=$KISS_PATH kiss "$action" "$@" + [ "$(id -u)" = 0 ] || { + sudo KISS_PATH=$KISS_PATH kiss "$action" "$@" + return + } ;; esac @@ -1036,15 +1039,7 @@ args() { s|search) for pkg; do - # Create a list of all matching packages. - set -- $(IFS=:; find $KISS_PATH -mindepth 1 \ - -maxdepth 1 -name "$pkg") - - # Print all matches. If there aren't any, print an error. - printf '%s\n' "${@:-$(log "[$pkg] Not found")}" - - # Exit with an error if a search fails. - [ "$1" ] || exit 1 + pkg_search "$pkg" done ;;