From 9e07793903c752c7249c68da9da06bf24ca37e6b Mon Sep 17 00:00:00 2001 From: "dylan.araps@gmail.com" Date: Sat, 21 Sep 2019 17:22:55 +0000 Subject: kiss: prettier output FossilOrigin-Name: 6a4855b3e6d58ab10f402c231dc238e2218102022ce76eb6b2d9817ab051f9ac --- kiss | 132 +++++++++++++++++++++++++++++++++---------------------------------- 1 file changed, 65 insertions(+), 67 deletions(-) diff --git a/kiss b/kiss index 980c597..6b6aec3 100755 --- a/kiss +++ b/kiss @@ -12,17 +12,18 @@ # # Dylan Araps. +log() { + # Print a message prettily. + printf '\033[1;32m%s \033[m%s\033[m %s\n' \ + "${3:-->}" "${2:+}$1${2:+}" "$2" +} + die() { # Print a message and exit with '1' (error). - printf '\033[1;31m!>\033[m %s.\n' "$@" >&2 + log "$1" "$2" "!>" >&2 exit 1 } -log() { - # Print a message prettily. - printf '\033[1;32m->\033[m %s.\n' "$@" -} - contains() { # Check if a "string list" contains a word. case " $1 " in *" $2 "*) return 0; esac @@ -31,14 +32,14 @@ contains() { pkg_lint() { # Check that each mandatory file in the package entry exists. - log "[$1] Checking repository files" + log "$1" "Checking repository files" repo_dir=$(pkg_find "$1") cd "$repo_dir" || die "'$repo_dir' not accessible" - [ -f sources ] || die "[$1] Sources file not found" - [ -x build ] || die "[$1] Build file not found or not executable" - [ -s version ] || die "[$1] Version file not found or empty" + [ -f sources ] || die "$1" "Sources file not found" + [ -x build ] || die "$1" "Build file not found or not executable" + [ -s version ] || die "$1" "Version file not found or empty" read -r _ release < version [ "$release" ] || die "Release field not found in version file" @@ -100,7 +101,7 @@ pkg_list() { pkg_sources() { # Download any remote package sources. The existence of local # files is also checked. - log "[$1] Downloading sources" + log "$1" "Downloading sources" # Store each downloaded source in a directory named after the # package it belongs to. This avoid conflicts between two packages @@ -114,21 +115,21 @@ pkg_sources() { # Remote source. *://*) [ -f "${src##*/}" ] && { - log "[$1] Found cached source '${src##*/}'" + log "$1" "Found cached source '${src##*/}'" continue } wget "$src" || { rm -f "${src##*/}" - die "[$1] Failed to download $src" + die "$1" "Failed to download $src" } ;; # Local source. *) - [ -f "$repo_dir/$src" ] || die "[$1] No local file '$src'" + [ -f "$repo_dir/$src" ] || die "$1" "No local file '$src'" - log "[$1] Found local file '$src'" + log "$1" "Found local file '$src'" ;; esac done < "$repo_dir/sources" @@ -137,7 +138,7 @@ pkg_sources() { pkg_extract() { # Extract all source archives to the build directory and copy over # any local repository files. - log "[$1] Extracting sources" + log "$1" "Extracting sources" repo_dir=$(pkg_find "$1") @@ -150,7 +151,7 @@ pkg_extract() { # allows for manual extraction. *://*.tar*|*://*.tgz) tar xf "$src_dir/$1/${src##*/}" --strip-components 1 \ - || die "[$1] Couldn't extract ${src##*/}" + || die "$1" "Couldn't extract ${src##*/}" ;; *) @@ -163,7 +164,7 @@ pkg_extract() { cp -f "$src_dir/$1/${src##*/}" . else - die "[$1] Local file $src not found" + die "$1" "Local file $src not found" fi ;; esac @@ -201,7 +202,7 @@ pkg_strip() { # Package has stripping disabled, stop here. [ -f "$(pkg_find "$1")/nostrip" ] && return - log "[$1] Stripping binaries and libraries" + log "$1" "Stripping binaries and libraries" # Strip only files matching the below ELF types. find "$pkg_dir/$1" -type f | while read -r file; do @@ -223,7 +224,7 @@ pkg_fixdeps() { # each binary and library with 'ldd'. This catches any extra # libraries and or dependencies pulled in by the package's # build suite. - log "[$1] Checking for missing dependencies" + log "$1" "Checking for missing dependencies" # Go to the directory containing the built package to # simplify path building. @@ -284,7 +285,7 @@ pkg_manifest() ( # Generate the package's manifest file. This is a list of each file # and directory inside the package. The file is used when uninstalling # packages, checking for package conflicts and for general debugging. - log "[$1] Generating manifest" + log "$1" "Generating manifest" # This funcion runs as a sub-shell to avoid having to 'cd' back to the # prior directory before being able to continue. @@ -301,16 +302,16 @@ pkg_manifest() ( pkg_tar() { # Create a tar-ball from the built package's files. # This tar-ball also contains the package's database entry. - log "[$1] Creating tar-ball" + log "$1" "Creating tar-ball" # Read the version information to name the package. read -r version release < "$(pkg_find "$1")/version" # Create a tar-ball from the contents of the built package. tar zpcf "$bin_dir/$1#$version-$release.tar.gz" -C "$pkg_dir/$1" . || - die "[$1] Failed to create tar-ball" + die "$1" "Failed to create tar-ball" - log "[$1] Successfully created tar-ball" + log "$1" "Successfully created tar-ball" } pkg_build() { @@ -375,7 +376,7 @@ pkg_build() { # This calls 'args' to inherit a root check and call # to 'sudo' to elevate permissions. [ -f "$bin_dir/$pkg#$version-$release.tar.gz" ] && { - log "[$pkg] Found pre-built binary, installing" + log "$pkg" "Found pre-built binary, installing" (KISS_FORCE=1 args i "$bin_dir/$pkg#$version-$release.tar.gz") # Remove the now installed package from the build @@ -391,7 +392,7 @@ pkg_build() { for pkg; do # Ensure that checksums exist prior to building the package. [ -f "$(pkg_find "$pkg")/checksums" ] || { - log "[$pkg] Checksums are missing" + log "$pkg" "Checksums are missing" # Instead of dying above, log it to the terminal. Also define a # variable so we *can* die after all checksum files have been @@ -410,7 +411,7 @@ pkg_build() { # set. for pkg; do pkg_checksums "$pkg" | cmp -s - "$(pkg_find "$pkg")/checksums" || { - log "[$pkg] Checksum mismatch" + log "$pkg" "Checksum mismatch" # Instead of dying above, log it to the terminal. Also define a # variable so we *can* die after all checksum files have been @@ -436,13 +437,13 @@ pkg_build() { cd "$mak_dir/$pkg" # Call the build script. - "$repo_dir/build" "$pkg_dir/$pkg" || die "[$pkg] Build failed" + "$repo_dir/build" "$pkg_dir/$pkg" || die "$pkg" "Build failed" # Copy the repository files to the package directory. # This acts as the database entry. cp -Rf "$repo_dir" "$pkg_dir/$pkg/$pkg_db/" - log "[$pkg] Successfully built package" + log "$pkg" "Successfully built package" # Create the manifest file early and make it empty. # This ensure that the manifest is added to the manifest... @@ -457,7 +458,7 @@ pkg_build() { # Skip this check if this is a package update. contains "$explicit" "$pkg" && [ -z "$pkg_update" ] && continue - log "[$pkg] Needed as a dependency or has an update, installing" + log "$pkg" "Needed as a dependency or has an update, installing" (KISS_FORCE=1 args i "$pkg") done @@ -473,8 +474,8 @@ pkg_build() { # Only ask for confirmation if more than one package needs to be installed. [ $# -gt 1 ] && { - log "Install built packages? [$*]" \ - "Press Enter to continue or Ctrl+C to abort here" + log "Install built packages? [$*]" + log "Press Enter to continue or Ctrl+C to abort here" # POSIX 'read' has none of the "nice" options like '-n', '-p' # etc etc. This is the most basic usage of 'read'. @@ -504,19 +505,19 @@ pkg_checksums() { # Die here if source for some reason, doesn't exist. else - die "[$1] Couldn't find source '$src'" + die "$1" "Couldn't find source '$src'" fi # An easy way to get 'sha256sum' to print with the 'basename' # of files is to 'cd' to the file's directory beforehand. (cd "$src_path" && sha256sum "${src##*/}") || - die "[$1] Failed to generate checksums" + die "$1" "Failed to generate checksums" done < "$repo_dir/sources" } pkg_conflicts() { # Check to see if a package conflicts with another. - log "[$2] Checking for package conflicts" + log "$2" "Checking for package conflicts" set +ef @@ -547,7 +548,7 @@ pkg_remove() { # The package is not installed, don't do anything. pkg_list "$1" >/dev/null || { - log "[$1] Not installed" + log "$1" "Not installed" return } @@ -565,9 +566,7 @@ pkg_remove() { # Disable globbing. set -f - [ "$required_by" ] && - die "[$1] Package is required by ${required_by%, }" \ - "[$1] Aborting here..." + [ "$required_by" ] && die "$1" "Package is required by ${required_by%, }" # Block being able to abort the script with 'Ctrl+C' during removal. # Removes all risk of the user aborting a package removal leaving @@ -590,7 +589,7 @@ pkg_remove() { # we no longer need to block 'Ctrl+C'. trap pkg_clean EXIT INT - log "[$1] Removed successfully" + log "$1" "Removed successfully" } pkg_install() { @@ -609,8 +608,7 @@ pkg_install() { tar_name=$1\#$version-$release.tar.gz [ -f "$bin_dir/$tar_name" ] || - die "Package '$1' has not been built" \ - "Run 'kiss build $1'" + die "Package '$1' has not been built, run 'kiss build $1'" tar_file=$bin_dir/$tar_name fi @@ -630,9 +628,9 @@ pkg_install() { # Extract the tar-ball to catch any errors before installation begins. tar pxf "$tar_file" -C "$tar_dir/$pkg_name" || - die "[$pkg_name] Failed to extract tar-ball" + die "$pkg_name" "Failed to extract tar-ball" - log "[$pkg_name] Checking that all dependencies are installed" + log "$pkg_name" "Checking that all dependencies are installed" # Make sure that all run-time dependencies are installed prior to # installing the package. @@ -644,9 +642,9 @@ pkg_install() { install_dep="$install_dep'$dep', " done < "$tar_dir/$pkg_name/$pkg_db/$pkg_name/depends" - [ "$install_dep" ] && die "[$1] Package requires ${install_dep%, }" + [ "$install_dep" ] && die "$1" "Package requires ${install_dep%, }" - log "[$pkg_name] Installing package incrementally" + log "$pkg_name" "Installing package incrementally" # Block being able to abort the script with Ctrl+C during installation. # Removes all risk of the user aborting a package installation leaving @@ -713,11 +711,11 @@ pkg_install() { trap pkg_clean EXIT INT if [ -x "$sys_db/$pkg_name/post-install" ]; then - log "[$pkg_name] Running post-install script" + log "$pkg_name" "Running post-install script" "$sys_db/$pkg_name/post-install" ||: fi - log "[$pkg_name] Installed successfully" + log "$pkg_name" "Installed successfully" } pkg_updates() { @@ -741,24 +739,24 @@ pkg_updates() { cd "$(git rev-parse --show-toplevel 2>/dev/null)" 2>/dev/null ||: [ -d .git ] || { - log "[$repo] Not a git repository, skipping" + log "$repo" "Not a git repository, skipping" continue } [ "$(git remote 2>/dev/null)" ] || { - log "[$repo] No remote, skipping" + log "$repo" "No remote, skipping" continue } contains "$repos" "$PWD" || { repos="$repos $PWD " - log "[$PWD] Updating repository" + log "$PWD" "Updating repository" if [ -w "$PWD" ]; then git pull else - log "[$PWD] Need root to update" + log "$PWD" "Need root to update" sudo git pull fi } @@ -786,9 +784,9 @@ pkg_updates() { # If the package manager has an update, handle it first. contains "$outdated" kiss && { - log "Detected package manager update" \ - "The package manager will be updated first" \ - "Continue?: Press Enter to continue or Ctrl+C to abort here" + log "Detected package manager update" + log "The package manager will be updated first" + log "Continue?: Press Enter to continue or Ctrl+C to abort here" # POSIX 'read' has none of the "nice" options like '-n', '-p' # etc etc. This is the most basic usage of 'read'. @@ -798,8 +796,8 @@ pkg_updates() { pkg_build kiss args i kiss - log "Updated the package manager" \ - "Re-run 'kiss update' to update your system" + log "Updated the package manager" + log "Re-run 'kiss update' to update your system" exit 0 } @@ -892,7 +890,7 @@ args() { for pkg; do pkg_checksums "$pkg" > "$(pkg_find "$pkg")/checksums" - log "[$pkg] Generated checksums" + log "$pkg" "Generated checksums" done ;; @@ -927,7 +925,7 @@ args() { for pkg in $remove_pkgs; do pkg_list "$pkg" >/dev/null || - die "[$pkg] Not installed" + die "$pkg" "Not installed" pkg_remove "$pkg" "${KISS_FORCE:-check}" done @@ -950,14 +948,14 @@ args() { ;; h|help|-h|--help|'') - log 'kiss [b|c|i|l|r|s|u] [pkg] [pkg] [pkg]' \ - 'build: Build a package' \ - 'checksum: Generate checksums' \ - 'install: Install a package' \ - 'list: List installed packages' \ - 'remove: Remove a package' \ - 'search: Search for a package' \ - 'update: Check for updates' + log 'kiss [b|c|i|l|r|s|u] [pkg] [pkg] [pkg]' + log 'build: Build a package' + log 'checksum: Generate checksums' + log 'install: Install a package' + log 'list: List installed packages' + log 'remove: Remove a package' + log 'search: Search for a package' + log 'update: Check for updates' ;; *) die "'kiss $action' is not a valid command" ;; -- cgit v1.2.3 From 259e287098dfcfffa22047a97eadf01f436aa075 Mon Sep 17 00:00:00 2001 From: "dylan.araps@gmail.com" Date: Sat, 21 Sep 2019 17:25:51 +0000 Subject: kiss: explain log FossilOrigin-Name: 82aa30ad2f6f4320960eb6bc30e79ce9f272fb1f7f20853eec13785e9e2637d9 --- kiss | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/kiss b/kiss index 6b6aec3..9c558c6 100755 --- a/kiss +++ b/kiss @@ -14,6 +14,11 @@ log() { # Print a message prettily. + # '\033[1;32m': Set text to color '2' and make it bold. + # '\033[m': Reset text formatting. + # '${3:-->}': If the 3rd argument is missing, set prefix to '->'. + # '${2:+}': If the 2nd argument exists, set the text style of '$1'. + # '${2:+}': If the 2nd argument exists, reset text formatting. printf '\033[1;32m%s \033[m%s\033[m %s\n' \ "${3:-->}" "${2:+}$1${2:+}" "$2" } -- cgit v1.2.3 From b94798a504d268a4268a21e9400e60bd40ddd8fd Mon Sep 17 00:00:00 2001 From: "dylan.araps@gmail.com" Date: Sat, 21 Sep 2019 17:35:01 +0000 Subject: kiss: pretty version FossilOrigin-Name: 535713e3c5039f47b8259595991f8e33a440a91950825d2a1a7ee26632957302 --- kiss | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kiss b/kiss index 9c558c6..cf2bf2e 100755 --- a/kiss +++ b/kiss @@ -949,7 +949,7 @@ args() { ;; v|version|-v|--version) - printf 'kiss 0.30.2\n' + log kiss 0.30.2 ;; h|help|-h|--help|'') -- cgit v1.2.3 From efbd557718aeb991266ad1f81dafb792adba007f Mon Sep 17 00:00:00 2001 From: "dylan.araps@gmail.com" Date: Sat, 21 Sep 2019 17:48:00 +0000 Subject: docs: update FossilOrigin-Name: 7c414b663b0d47a281d8654c1d6f52a7c96d40bf13bec114db8833f7edddefee --- kiss | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/kiss b/kiss index cf2bf2e..e95dd48 100755 --- a/kiss +++ b/kiss @@ -14,11 +14,11 @@ log() { # Print a message prettily. - # '\033[1;32m': Set text to color '2' and make it bold. - # '\033[m': Reset text formatting. - # '${3:-->}': If the 3rd argument is missing, set prefix to '->'. - # '${2:+}': If the 2nd argument exists, set the text style of '$1'. - # '${2:+}': If the 2nd argument exists, reset text formatting. + # '\033[1;32m' Set text to color '2' and make it bold. + # '\033[m': Reset text formatting. + # '${3:-->}': If the 3rd argument is missing, set prefix to '->'. + # '${2:+[1;33m}': If the 2nd argument exists, set the text style of '$1'. + # '${2:+[m}': If the 2nd argument exists, reset text formatting. printf '\033[1;32m%s \033[m%s\033[m %s\n' \ "${3:-->}" "${2:+}$1${2:+}" "$2" } -- cgit v1.2.3 From ee96f67f988f33d115757dea507c5476c7e7e610 Mon Sep 17 00:00:00 2001 From: "dylan.araps@gmail.com" Date: Sat, 21 Sep 2019 18:10:24 +0000 Subject: kiss: better colors FossilOrigin-Name: 13e9bff46a6c7e753c458ab78982b468dfc48d39e277db17659129a745abe675 --- kiss | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kiss b/kiss index e95dd48..5f54a86 100755 --- a/kiss +++ b/kiss @@ -19,8 +19,8 @@ log() { # '${3:-->}': If the 3rd argument is missing, set prefix to '->'. # '${2:+[1;33m}': If the 2nd argument exists, set the text style of '$1'. # '${2:+[m}': If the 2nd argument exists, reset text formatting. - printf '\033[1;32m%s \033[m%s\033[m %s\n' \ - "${3:-->}" "${2:+}$1${2:+}" "$2" + printf '\033[1;33m%s \033[m%s\033[m %s\n' \ + "${3:-->}" "${2:+}$1${2:+}" "$2" } die() { -- cgit v1.2.3 From a8605785eb2475fe9f16c910c8e1fc814d5ffd3b Mon Sep 17 00:00:00 2001 From: "dylan.araps@gmail.com" Date: Sat, 21 Sep 2019 18:32:02 +0000 Subject: docs: update FossilOrigin-Name: cc5f8c63d85d47b2d8605ada569c661e979dddabf719963847f198978514c872 --- kiss | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/kiss b/kiss index 5f54a86..b886407 100755 --- a/kiss +++ b/kiss @@ -14,6 +14,11 @@ log() { # Print a message prettily. + # + # This function uses the literal escape character (Ctrl+V+Escape) as + # a simple way of *safely* bypassing the escape sequence restrictions + # on 'printf %s'. Cheeky, I know. + # # '\033[1;32m' Set text to color '2' and make it bold. # '\033[m': Reset text formatting. # '${3:-->}': If the 3rd argument is missing, set prefix to '->'. -- cgit v1.2.3