From 6786d2ca0a17ba16a636f854512250b99be5b88d Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sat, 18 Apr 2020 12:11:56 +0300 Subject: [PATCH] kiss: Unify usage outputs for all contrib scripts. Seeing as how these utilities are now better integrated, more effort should go into the overall interface between what should be the "benchmark" or example kiss scripts. --- contrib/kiss-chbuild | 4 ++-- contrib/kiss-depends | 11 +++++++---- contrib/kiss-depends-finder | 9 +++++++-- contrib/kiss-export | 10 +++++++--- contrib/kiss-fork | 6 ++++-- contrib/kiss-maintainer | 5 +++++ contrib/kiss-manifest | 11 +++++++---- contrib/kiss-manifest-tree | 11 +++++++---- contrib/kiss-owns | 3 +-- contrib/kiss-repodepends | 7 +++++++ contrib/kiss-revdepends | 7 +++++++ contrib/kiss-size | 11 +++++------ kiss | 4 ++-- 13 files changed, 68 insertions(+), 31 deletions(-) diff --git a/contrib/kiss-chbuild b/contrib/kiss-chbuild index 4b772b7..a4cd07e 100755 --- a/contrib/kiss-chbuild +++ b/contrib/kiss-chbuild @@ -12,7 +12,7 @@ clean() { } pid=$$ -url=https://github.com/kisslinux/repo/releases/download/1.9.0/ +url=https://github.com/kisslinux/repo/releases/download/1.9.11/ cd "${cac_dir:=$KISS_ROOT${XDG_CACHE_HOME:-$HOME/.cache}/kiss}" @@ -23,7 +23,7 @@ cd "${cac_dir:=$KISS_ROOT${XDG_CACHE_HOME:-$HOME/.cache}/kiss}" [ -d kiss-chroot ] || { log "Extracting chroot" - tar xvf kiss-chroot.tar.xz + tar xf kiss-chroot.tar.xz } log "Creating temporary chroot" diff --git a/contrib/kiss-depends b/contrib/kiss-depends index be23624..e989844 100755 --- a/contrib/kiss-depends +++ b/contrib/kiss-depends @@ -1,8 +1,11 @@ #!/bin/sh -ef # Display a package's dependencies. -kiss l "${1:-null}" >/dev/null +# Ignore shellcheck as we want the warning's behavior. +# shellcheck disable=2015 +[ "$1" ] && kiss l "${1:-null}" >/dev/null || { + printf 'usage: kiss-depends [pkg]\n' + exit 1 +} -db_dir=$KISS_ROOT/var/db/kiss/installed/${1:-null} - -cat "$db_dir/depends" 2>/dev/null +cat "$KISS_ROOT/var/db/kiss/installed/$1/depends" 2>/dev/null diff --git a/contrib/kiss-depends-finder b/contrib/kiss-depends-finder index 3c36494..1fe90ce 100755 --- a/contrib/kiss-depends-finder +++ b/contrib/kiss-depends-finder @@ -1,7 +1,12 @@ #!/bin/sh -e # Find missing dependencies by parsing 'ldd'. -kiss l "${1:-null}" >/dev/null +# Ignore shellcheck as we want the warning's behavior. +# shellcheck disable=2015 +[ "$1" ] && kiss l "${1:-null}" >/dev/null || { + printf 'usage: kiss-depends-finder [pkg]\n' + exit 1 +} db_dir=$KISS_ROOT/var/db/kiss/installed grep=$(command -v ggrep) || grep='grep' @@ -29,7 +34,7 @@ while read -r file; do # Skip listing these packages as dependencies. case $pkg in - musl|gcc|$1) ;; + musl|gcc|"$1") ;; *) printf '%s\n' "$pkg" ;; esac done diff --git a/contrib/kiss-export b/contrib/kiss-export index 3d9f3f4..774e5c6 100755 --- a/contrib/kiss-export +++ b/contrib/kiss-export @@ -1,11 +1,15 @@ #!/bin/sh -ef # Turn an installed package into a KISS tarball. -kiss l "${1:-null}" >/dev/null +# Ignore shellcheck as we want the warning's behavior. +# shellcheck disable=2015 +[ "$1" ] && kiss l "${1:-null}" >/dev/null || { + printf 'usage: kiss-export [pkg]\n' + exit 1 +} # Grab the package's version.. -read -r ver rel 2>/dev/null < \ - "$KISS_ROOT/var/db/kiss/installed/$1/version" +read -r ver rel 2>/dev/null < "$KISS_ROOT/var/db/kiss/installed/$1/version" # Reset the argument list. pkg=$1 diff --git a/contrib/kiss-fork b/contrib/kiss-fork index 6e5acdb..073fbaf 100755 --- a/contrib/kiss-fork +++ b/contrib/kiss-fork @@ -1,8 +1,10 @@ #!/bin/sh -ef # Copy a package's repository files into the current directory. -kiss s "${1:-null}" >/dev/null || { - printf 'usage: kiss-fork pkg_name\n' +# Ignore shellcheck as we want the warning's behavior. +# shellcheck disable=2015 +[ "$1" ] && kiss s "${1:-null}" >/dev/null || { + printf 'usage: kiss-fork [pkg]\n' exit 1 } diff --git a/contrib/kiss-maintainer b/contrib/kiss-maintainer index c5ece32..478d046 100755 --- a/contrib/kiss-maintainer +++ b/contrib/kiss-maintainer @@ -1,6 +1,11 @@ #!/bin/sh -ef # Find the maintainer of a package. +[ "$1" ] || { + printf 'usage: kiss-maintainer [pkg]\n' + exit 1 +} + kiss s "$1" | while read -r repo; do cd "$repo" m=$(git log -1 version 2>/dev/null) ||: m=${m##*Author: } diff --git a/contrib/kiss-manifest b/contrib/kiss-manifest index e7d9fe2..a7dab14 100755 --- a/contrib/kiss-manifest +++ b/contrib/kiss-manifest @@ -1,8 +1,11 @@ #!/bin/sh -ef # Display all files owned by a package. -kiss l "${1:-null}" >/dev/null +# Ignore shellcheck as we want the warning's behavior. +# shellcheck disable=2015 +[ "$1" ] && kiss l "${1:-null}" >/dev/null || { + printf 'usage: kiss-manifest [pkg]\n' + exit 1 +} -db_dir=$KISS_ROOT/var/db/kiss/installed/${1:-null} - -cat "$db_dir/manifest" 2>/dev/null +cat "$KISS_ROOT/var/db/kiss/installed/$1/manifest" 2>/dev/null diff --git a/contrib/kiss-manifest-tree b/contrib/kiss-manifest-tree index f5f938e..54a3c62 100755 --- a/contrib/kiss-manifest-tree +++ b/contrib/kiss-manifest-tree @@ -1,9 +1,12 @@ #!/bin/sh -ef # Display all files owned by a package in a tree. -kiss l "${1:-null}" - -db_dir=$KISS_ROOT/var/db/kiss/installed/${1:-null} +# Ignore shellcheck as we want the warning's behavior. +# shellcheck disable=2015 +[ "$1" ] && kiss l "${1:-null}" >/dev/null || { + printf 'usage: kiss-manifest-tree [pkg]\n' + exit 1 +} printf '%s\n' "[$1]:" -tree -C --fromfile "$db_dir/manifest" | tail -n +2 +tree -C --fromfile "$KISS_ROOT/var/db/kiss/installed/$1/manifest" | tail -n +2 diff --git a/contrib/kiss-owns b/contrib/kiss-owns index b300e55..4746ba3 100755 --- a/contrib/kiss-owns +++ b/contrib/kiss-owns @@ -5,9 +5,8 @@ # follow symlinks. file=$(readlink -f "$KISS_ROOT/${1##$KISS_ROOT}") -# Check if the file exists and exit if it is not. [ -f "$file" ] || { - printf '%s\n' "error: file '$1' doesn't exist." >&2 + printf 'usage: kiss-owns [/path/to/file]\n' exit 1 } diff --git a/contrib/kiss-repodepends b/contrib/kiss-repodepends index 2ef0bec..49617fb 100755 --- a/contrib/kiss-repodepends +++ b/contrib/kiss-repodepends @@ -1,4 +1,11 @@ #!/bin/sh # Display a package's original dependencies. +# Ignore shellcheck as we want the warning's behavior. +# shellcheck disable=2015 +[ "$1" ] && kiss s "${1:-null}" >/dev/null || { + printf 'usage: kiss-repodepends [pkg]\n' + exit 1 +} + cat "$(kiss s "$1")/depends" 2>/dev/null diff --git a/contrib/kiss-revdepends b/contrib/kiss-revdepends index d71026d..e8a19d7 100755 --- a/contrib/kiss-revdepends +++ b/contrib/kiss-revdepends @@ -1,6 +1,13 @@ #!/bin/sh -e # Display packages which depend on package. +# Ignore shellcheck as we want the warning's behavior. +# shellcheck disable=2015 +[ "$1" ] && kiss l "${1:-null}" >/dev/null || { + printf 'usage: kiss-revdepends [pkg]\n' + exit 1 +} + # 'cd' to the database directory as a simple way of # stripping the path and performing a 'basename'. cd "$KISS_ROOT/var/db/kiss/installed" diff --git a/contrib/kiss-size b/contrib/kiss-size index 367c26d..d569a8a 100755 --- a/contrib/kiss-size +++ b/contrib/kiss-size @@ -1,17 +1,16 @@ #!/bin/sh -ef # Show the size on disk for a package. -db_dir=$KISS_ROOT/var/db/kiss/installed/${1-null} - -# Check if package is installed and exit if it is not. -[ -d "$db_dir" ] || { - printf '%s\n' "error: '$1' not installed." >&2 +# Ignore shellcheck as we want the warning's behavior. +# shellcheck disable=2015 +[ "$1" ] && kiss l "${1:-null}" >/dev/null || { + printf 'usage: kiss-size [pkg]\n' exit 1 } # Filter directories from manifest and leave only files. # Directories in the manifest end in a trailing '/'. -files=$(sed 's|.*/$||' "$db_dir/manifest") +files=$(sed 's|.*/$||' "$KISS_ROOT/var/db/kiss/installed/$1/manifest") # Send the file list to 'du'. # This unquoted variable is safe as word splitting is intended diff --git a/kiss b/kiss index 56c6fb7..b710812 100755 --- a/kiss +++ b/kiss @@ -115,7 +115,7 @@ pkg_find() { # Figure out which repository a package belongs to by # searching for directories matching the package name # in $KISS_PATH/*. - query=$1 IFS=:; set -- + query=$1 all=$2 IFS=:; set -- # Both counts of word-splitting are intentional here. # Firstly to split the repositories and secondly to @@ -137,7 +137,7 @@ pkg_find() { # Show all search results if called from 'kiss search', else # print only the first match. - [ -t 1 ] || [ "$2" ] && printf '%s\n' "$@" || printf '%s\n' "$1" + [ -t 1 ] || [ "$all" ] && printf '%s\n' "$@" || printf '%s\n' "$1" } pkg_list() {