From 831e01c0c611fa4f7263a0b8785df6bd42a84d15 Mon Sep 17 00:00:00 2001 From: Joseph Werle Date: Tue, 14 Jun 2022 11:36:12 +0200 Subject: [PATCH 01/13] chore(): 1.1.3 --- bpkg.json | 2 +- bpkg.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bpkg.json b/bpkg.json index 307a5eca..cbc3577d 100644 --- a/bpkg.json +++ b/bpkg.json @@ -1,6 +1,6 @@ { "name": "bpkg", - "version": "1.1.2", + "version": "1.1.3", "description": "Lightweight bash package manager", "global": true, "repo": "bpkg/bpkg", diff --git a/bpkg.sh b/bpkg.sh index e7801c9e..40cabf0f 100755 --- a/bpkg.sh +++ b/bpkg.sh @@ -7,7 +7,7 @@ if [[ ${BASH_SOURCE[0]} != "$0" ]]; then fi ## bpkg version -VERSION="1.1.2" +VERSION="1.1.3" ## output error to stderr error () { From ea415ea0dda40bcafb84e8953f8efdf1a6bbb52b Mon Sep 17 00:00:00 2001 From: Joseph Werle Date: Tue, 14 Jun 2022 11:36:12 +0200 Subject: [PATCH 02/13] chore(): 1.1.3 --- setup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.sh b/setup.sh index eb2f31bb..2d24051e 100755 --- a/setup.sh +++ b/setup.sh @@ -9,7 +9,7 @@ # " "" # bash package manager -VERSION="1.1.2" +VERSION="1.1.3" TAG=${TAG:-$VERSION} BRANCH=${BRANCH:-$TAG} REMOTE=${REMOTE:-https://github.com/bpkg/bpkg.git} From bd8c92f28ca8adddcdc100829f6f26f91609be6a Mon Sep 17 00:00:00 2001 From: Joseph Werle Date: Tue, 14 Jun 2022 12:12:27 +0200 Subject: [PATCH 03/13] chore(scripts): add 'update-version.sh' script --- scripts/update-versions.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100755 scripts/update-versions.sh diff --git a/scripts/update-versions.sh b/scripts/update-versions.sh new file mode 100755 index 00000000..925d9ea3 --- /dev/null +++ b/scripts/update-versions.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +declare shell_targets=(setup.sh bpkg.sh) +declare json_targets=(bpkg.json) +declare latest="$(git describe --tags --abbrev=0)" + +for target in "${shell_targets[@]}"; do + sed -i "s/VERSION=.*/VERSION=\"$latest\"/g" "$target" +done + +for target in "${json_targets[@]}"; do + sed -i "s/\"version\"\s*:\s*\".*\",/\"version\": \"$latest\",/g" "$target" +done From b9b0ec631ebfedd13c054305f31670568c915760 Mon Sep 17 00:00:00 2001 From: Sam Likins Date: Wed, 18 Jan 2023 18:06:26 -0800 Subject: [PATCH 04/13] Modify local install link: Changed symbolic link from absolute to relative for compliance in shared containers --- lib/install/install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/install/install.sh b/lib/install/install.sh index 017db6cc..ee31efc8 100755 --- a/lib/install/install.sh +++ b/lib/install/install.sh @@ -523,7 +523,7 @@ bpkg_install_from_remote () { info "$scriptname to PATH" "$BPKG_PACKAGE_DEPS/bin/$scriptname" if (( force_actions == 1 )); then - ln -sf "$BPKG_PACKAGE_DEPS/$name/$script" "$BPKG_PACKAGE_DEPS/bin/$scriptname" + ln -sf "../$name/$script" "$BPKG_PACKAGE_DEPS/bin/$scriptname" else if test -f "$BPKG_PACKAGE_DEPS/bin/$scriptname"; then warn "'$BPKG_PACKAGE_DEPS/bin/$scriptname' already exists. Overwrite? (yN)" @@ -534,7 +534,7 @@ bpkg_install_from_remote () { esac fi - ln -s "$BPKG_PACKAGE_DEPS/$name/$script" "$BPKG_PACKAGE_DEPS/bin/$scriptname" + ln -s "../$name/$script" "$BPKG_PACKAGE_DEPS/bin/$scriptname" fi chmod u+x "$BPKG_PACKAGE_DEPS/bin/$scriptname" fi From d1e1a7624222efd0a4ae063aaeba08178c0da6cc Mon Sep 17 00:00:00 2001 From: Sam Likins Date: Sun, 12 Mar 2023 08:22:31 -0700 Subject: [PATCH 05/13] Added install development dependencies functionality. --- lib/getdeps/getdeps.sh | 17 ++++++++++++++++- lib/install/install.sh | 29 ++++++++++++++++++++++++----- 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/lib/getdeps/getdeps.sh b/lib/getdeps/getdeps.sh index fa922da0..f8a1a25b 100755 --- a/lib/getdeps/getdeps.sh +++ b/lib/getdeps/getdeps.sh @@ -1,9 +1,12 @@ #!/usr/bin/env bash +let install_dev=0 + ## output usage usage () { echo "Installs dependencies for a package." echo "usage: bpkg-getdeps [-h|--help]" + echo " or: bpkg-getdeps [-d|--dev]" echo " or: bpkg-getdeps" } @@ -18,6 +21,11 @@ bpkg_getdeps () { usage return 0 ;; + + -d|--dev) + shift + install_dev=1 + ;; esac ## ensure there is a package to read @@ -30,10 +38,17 @@ bpkg_getdeps () { fi # shellcheck disable=SC2002 - dependencies=$(cat "${pkg}" | bpkg-json -b | grep '\[\"dependencies' | sed "s/\[\"dependencies\",//" | sed "s/\"\]$(printf '\t')\"/@/" | tr -d '"') + dependencies=$(cat "${pkg}" | bpkg-json -b | grep '\["dependencies"' | sed "s/\[\"dependencies\",//" | sed "s/\"\]$(printf '\t')\"/@/" | tr -d '"') # shellcheck disable=SC2206 dependencies=(${dependencies[@]}) + if (( 1 == install_dev )); then + # shellcheck disable=SC2002 + dependencies_dev=$(cat "${pkg}" | bpkg-json -b | grep '\["dependencies-dev"' | sed "s/\[\"dependencies-dev\",//" | sed "s/\"\]$(printf '\t')\"/@/" | tr -d '"') + # shellcheck disable=SC2206 + dependencies=(${dependencies[@]} ${dependencies_dev[@]}) + fi + ## run bpkg install for each dependency for (( i = 0; i < ${#dependencies[@]} ; ++i )); do ( diff --git a/lib/install/install.sh b/lib/install/install.sh index ee31efc8..20241f6a 100755 --- a/lib/install/install.sh +++ b/lib/install/install.sh @@ -30,6 +30,7 @@ fi bpkg_initrc let prevent_prune=0 +let install_dev=0 let force_actions=${BPKG_FORCE_ACTIONS:-0} let needs_global=0 @@ -42,10 +43,11 @@ validate_parameters () { return 0 } -## outut usage +## output usage usage () { echo 'usage: bpkg-install [directory]' echo ' or: bpkg-install [-h|--help]' + echo ' or: bpkg-install [-d|--dev]' echo ' or: bpkg-install [-g|--global] [-f|--force] ...' echo ' or: bpkg-install [-g|--global] [-f|--force] .../' } @@ -192,6 +194,11 @@ bpkg_install () { force_actions=1 ;; + -d|--dev) + shift + install_dev=1 + ;; + --no-prune) shift prevent_prune=1 @@ -211,9 +218,14 @@ bpkg_install () { export BPKG_FORCE_ACTIONS=$force_actions + BPKG_DEPS_EXEC="bpkg_getdeps" + if (( 1 == install_dev )); then + BPKG_DEPS_EXEC="${BPKG_DEPS_EXEC} --dev" + fi + ## ensure there is a package to install if (( ${#pkgs[@]} == 0 )); then - bpkg_getdeps + ${BPKG_DEPS_EXEC} return $? fi @@ -221,7 +233,7 @@ bpkg_install () { for pkg in "${pkgs[@]}"; do if test -d "$(bpkg_realpath "$pkg" 2>/dev/null)"; then - if ! (cd "$pkg" && bpkg_getdeps); then + if ! (cd "$pkg" && ${BPKG_DEPS_EXEC}); then return 1 fi @@ -233,7 +245,7 @@ bpkg_install () { local i=0 for remote in "${BPKG_REMOTES[@]}"; do local git_remote=${BPKG_GIT_REMOTES[$i]} - if bpkg_install_from_remote "$pkg" "$remote" "$git_remote" $needs_global; then + if bpkg_install_from_remote "$pkg" "$remote" "$git_remote" $needs_global $install_dev; then did_fail=0 break elif [[ "$?" == '2' ]]; then @@ -262,6 +274,7 @@ bpkg_install_from_remote () { local remote=$2 local git_remote=$3 local needs_global=$4 + local install_dev=$5 local url='' local uri='' @@ -506,7 +519,13 @@ bpkg_install_from_remote () { # install package dependencies info "Install dependencies for $name" - (cd "$BPKG_PACKAGE_DEPS/$name" && bpkg_getdeps) + + BPKG_DEPS_EXEC="bpkg_getdeps" + if (( 1 == install_dev )); then + BPKG_DEPS_EXEC="${BPKG_DEPS_EXEC} --dev" + fi + + (cd "$BPKG_PACKAGE_DEPS/$name" && ${BPKG_DEPS_EXEC}) ## grab each script and place in deps directory for script in "${scripts[@]}"; do From 96d024a19b292a1cb28809895a8d3c3cb84b2570 Mon Sep 17 00:00:00 2001 From: Joseph Werle Date: Sun, 12 Mar 2023 14:10:22 -0400 Subject: [PATCH 06/13] chore(): 1.1.4 --- bpkg.json | 2 +- bpkg.sh | 2 +- setup.sh | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bpkg.json b/bpkg.json index cbc3577d..c2c0b1dd 100644 --- a/bpkg.json +++ b/bpkg.json @@ -1,6 +1,6 @@ { "name": "bpkg", - "version": "1.1.3", + "version": "1.1.4", "description": "Lightweight bash package manager", "global": true, "repo": "bpkg/bpkg", diff --git a/bpkg.sh b/bpkg.sh index 40cabf0f..d28bd4b7 100755 --- a/bpkg.sh +++ b/bpkg.sh @@ -7,7 +7,7 @@ if [[ ${BASH_SOURCE[0]} != "$0" ]]; then fi ## bpkg version -VERSION="1.1.3" +VERSION="1.1.4" ## output error to stderr error () { diff --git a/setup.sh b/setup.sh index 2d24051e..97bd7687 100755 --- a/setup.sh +++ b/setup.sh @@ -9,7 +9,7 @@ # " "" # bash package manager -VERSION="1.1.3" +VERSION="1.1.4" TAG=${TAG:-$VERSION} BRANCH=${BRANCH:-$TAG} REMOTE=${REMOTE:-https://github.com/bpkg/bpkg.git} From df685b5f6834dde54ede0c9f996e0c1387588382 Mon Sep 17 00:00:00 2001 From: Sam Likins Date: Sun, 12 Mar 2023 11:16:11 -0700 Subject: [PATCH 07/13] Added `commands` run configuration documentation and correct TOC. --- README.md | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 96ca2b73..089a14a2 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,7 @@ You can install shell scripts globally (on `${PREFIX:-/usr/local/bin}`) or use t * [Usage](#usage) * [Installing packages](#installing-packages) * [Packages With Dependencies](#packages-with-dependencies) + * [Running packages with `bpkg`](#running-packages-with-bpkg) * [Retrieving package info](#retrieving-package-info) * [Package details](#package-details) * [bpkg.json](#bpkgjson) @@ -24,11 +25,14 @@ You can install shell scripts globally (on `${PREFIX:-/usr/local/bin}`) or use t * [global](#global) * [install](#install-1) * [scripts](#scripts) - * [files](#files) + * [files (optional)](#files-optional) * [dependencies (optional)](#dependencies-optional) + * [commands (optional)](#commands-optional) * [Packaging best practices](#packaging-best-practices) * [Package exports](#package-exports) * [Sponsors](#sponsors) + * [Contributors](#contributors) + * [Backers](#backers) * [License](#license) @@ -240,9 +244,9 @@ This is an array of scripts that will be installed into a project. "scripts": ["script.sh"] ``` -### files +### files (optional) -This is an array of files that will be installed into a project. +This is an array of non-script files that will be installed into a project. ```json "files": ["bar.txt", "foo.txt"] @@ -258,6 +262,23 @@ This is a hash of dependencies. The keys are the package names, and the values a } ``` +### commands (optional) + +This is a hash of commands. The keys are the names of the commands and the values are the commands to execute in a shell. The commands can be called from the command line with `bpkg run` followed by the command name. + +```json + "commands": { + "say-hello": "echo \"Hello $1\"" + } +``` + +The commands are run with `eval`, which runs the command as if on the command line. Commands can contain environment variables, and supports [shell features] (including *[special parameters]* and *[shell expansions]*). Passed parameters (on the command line after the command name) can be accessed in the command by using `$@` or `$1`. + +```bash +$ bpkg run say-hello "Bash Package Manager" +Hello Bash Package Manager +``` + ## Packaging best practices These are guidelines that we strongly encourage developers to follow. From e2e373acf68b20ba3a6cf4ec473c37b06b8d1ad5 Mon Sep 17 00:00:00 2001 From: Sam Likins Date: Sun, 12 Mar 2023 11:57:48 -0700 Subject: [PATCH 08/13] Added missing markdown links. --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 089a14a2..92643f01 100644 --- a/README.md +++ b/README.md @@ -348,3 +348,6 @@ See file `LICENSE` for a more detailed description of its terms. [clib]: https://github.com/clibs/clib [term]: https://github.com/bpkg/term [json]: http://json.org/example +[shell features]: https://www.gnu.org/software/bash/manual/html_node/Basic-Shell-Features.html +[special parameters]: https://www.gnu.org/software/bash/manual/html_node/Special-Parameters.html +[shell expansions]: https://www.gnu.org/software/bash/manual/html_node/Shell-Expansions.html From 79481450fe2e28953f23d6b9ce90ccc73fbeee79 Mon Sep 17 00:00:00 2001 From: Sam Likins Date: Fri, 21 Apr 2023 05:37:10 -0700 Subject: [PATCH 09/13] List Commands with Descriptions (#161) * Updated `utils.sh` with `bpkg_exec_exist` and `bpkg_exec_or_exit`. * Updated scripts with `bpkg_exec_or_exit`. * Updated `install.sh` to utilize utility functions. * Updated `runner` in `run.sh`. * Added `--list` option to `run.sh`. * Added `commands-description` to `bpkg.json`. * Updated README TOC and missing `dependencies-dev` section. * Added `commands-description` section to README. * Corrected failing shellcheck. --- README.md | 63 +++++--- bpkg.json | 4 + lib/install/install.sh | 140 ++++-------------- lib/list/list.sh | 6 +- lib/package/package.sh | 15 +- lib/run/run.sh | 108 ++++++++------ lib/show/show.sh | 13 +- lib/source/source.sh | 15 +- lib/suggest/suggest.sh | 7 +- lib/update/update.sh | 6 +- lib/utils/utils.sh | 326 ++++++++++++++++++++++------------------- 11 files changed, 348 insertions(+), 355 deletions(-) diff --git a/README.md b/README.md index 92643f01..e10c4479 100644 --- a/README.md +++ b/README.md @@ -8,33 +8,34 @@ You can install shell scripts globally (on `${PREFIX:-/usr/local/bin}`) or use t * [Install](#install) - * [0. Dependencies](#0-dependencies) - * [1. Install script](#1-install-script) - * [2. clib](#2-clib) - * [3. Source Code](#3-source-code) + * [0. Dependencies](#0-dependencies) + * [1. Install script](#1-install-script) + * [2. clib](#2-clib) + * [3. Source Code](#3-source-code) * [Usage](#usage) - * [Installing packages](#installing-packages) - * [Packages With Dependencies](#packages-with-dependencies) - * [Running packages with `bpkg`](#running-packages-with-bpkg) - * [Retrieving package info](#retrieving-package-info) + * [Installing packages](#installing-packages) + * [Packages With Dependencies](#packages-with-dependencies) + * [Running packages with `bpkg`](#running-packages-with-bpkg) + * [Retrieving package info](#retrieving-package-info) * [Package details](#package-details) * [bpkg.json](#bpkgjson) - * [name](#name) - * [version (optional)](#version-optional) - * [description](#description) - * [global](#global) - * [install](#install-1) - * [scripts](#scripts) - * [files (optional)](#files-optional) - * [dependencies (optional)](#dependencies-optional) - * [commands (optional)](#commands-optional) + * [name](#name) + * [version (optional)](#version-optional) + * [description](#description) + * [global](#global) + * [install](#install-1) + * [scripts](#scripts) + * [files (optional)](#files-optional) + * [dependencies (optional)](#dependencies-optional) + * [dependencies-dev (optional)](#dependencies-dev-optional) + * [commands (optional)](#commands-optional) + * [commands-description (optional)](#commands-description-optional) * [Packaging best practices](#packaging-best-practices) - * [Package exports](#package-exports) + * [Package exports](#package-exports) * [Sponsors](#sponsors) - * [Contributors](#contributors) - * [Backers](#backers) + * [Contributors](#contributors) + * [Backers](#backers) * [License](#license) - ## Install @@ -262,6 +263,16 @@ This is a hash of dependencies. The keys are the package names, and the values a } ``` +### dependencies-dev (optional) + +This is a hash of dependencies only needed during development. Like the `dependencies` array, the keys are the package names, and the values are the version specifiers; `'master'` or a tagged release can be used as the identifier. These development dependencies are installed by adding the `-d` or `--dev` flags to the `bpkg install` command. + +```json + "dependencies-dev": { + "term": "0.0.1" + } +``` + ### commands (optional) This is a hash of commands. The keys are the names of the commands and the values are the commands to execute in a shell. The commands can be called from the command line with `bpkg run` followed by the command name. @@ -279,6 +290,16 @@ $ bpkg run say-hello "Bash Package Manager" Hello Bash Package Manager ``` +### commands-description (optional) + +This is a hash of descriptions for configured commands. The keys are the names of the commands and the values are the descriptions for the specified commands. The command descriptions can be listed on the command line by providing the `-l` or `--list` flags after the `bpkg run` command. + +```json + "commands-description": { + "say-hello": "Output hello to provided name (ex: bpkg run say-hello John)" + } +``` + ## Packaging best practices These are guidelines that we strongly encourage developers to follow. diff --git a/bpkg.json b/bpkg.json index c2c0b1dd..6895246f 100644 --- a/bpkg.json +++ b/bpkg.json @@ -8,5 +8,9 @@ "commands": { "lint": "command shellcheck **/*.sh", "list-sources": "echo ${BPKG_PACKAGE_SOURCES[@]} | sed 's/ /\n/g'" + }, + "commands-description": { + "lint": "Execute shellcheck against all .sh files in project", + "list-sources": "Output package source files" } } diff --git a/lib/install/install.sh b/lib/install/install.sh index 20241f6a..e6e41335 100755 --- a/lib/install/install.sh +++ b/lib/install/install.sh @@ -1,31 +1,20 @@ #!/usr/bin/env bash -if ! type -f bpkg-realpath &>/dev/null; then - echo "error: bpkg-realpath not found, aborting" - exit 1 -else - # shellcheck disable=SC2230 - # shellcheck source=lib/realpath/realpath.sh - source "$(which bpkg-realpath)" -fi - if ! type -f bpkg-utils &>/dev/null; then echo "error: bpkg-utils not found, aborting" exit 1 -else - # shellcheck disable=SC2230 - # shellcheck source=lib/utils/utils.sh - source "$(which bpkg-utils)" fi -if ! type -f bpkg-getdeps &>/dev/null; then - echo "error: bpkg-getdeps not found, aborting" - exit 1 -else - # shellcheck disable=SC2230 - # shellcheck source=lib/getdeps/getdeps.sh +# shellcheck source=lib/utils/utils.sh +source "$(which bpkg-utils)" + +# shellcheck source=lib/realpath/realpath.sh +bpkg_exec_or_exit bpkg-realpath && + source "$(which bpkg-realpath)" + +# shellcheck source=lib/getdeps/getdeps.sh +bpkg_exec_or_exit bpkg-getdeps && source "$(which bpkg-getdeps)" -fi bpkg_initrc @@ -34,15 +23,6 @@ let install_dev=0 let force_actions=${BPKG_FORCE_ACTIONS:-0} let needs_global=0 -## check parameter consistency -validate_parameters () { - if [[ ${#BPKG_GIT_REMOTES[@]} -ne ${#BPKG_REMOTES[@]} ]]; then - error "$(printf 'BPKG_GIT_REMOTES[%d] differs in size from BPKG_REMOTES[%d] array' "${#BPKG_GIT_REMOTES[@]}" "${#BPKG_REMOTES[@]}")" - return 1 - fi - return 0 -} - ## output usage usage () { echo 'usage: bpkg-install [directory]' @@ -52,62 +32,6 @@ usage () { echo ' or: bpkg-install [-g|--global] [-f|--force] .../' } -## format and output message -message () { - if type -f bpkg-term > /dev/null 2>&1; then - bpkg-term color "$1" - fi - - shift - echo -n " $1" - shift - - if type -f bpkg-term > /dev/null 2>&1; then - bpkg-term reset - fi - - printf ': ' - - if type -f bpkg-term > /dev/null 2>&1; then - bpkg-term reset - bpkg-term bright - fi - - printf "%s\n" "$@" - - if type -f bpkg-term > /dev/null 2>&1; then - bpkg-term reset - fi -} - -## output error -error () { - message 'red' 'error' "$@" >&2 - - return 0 -} - -## output warning -warn () { - message 'yellow' 'warn' "$@" >&2 - - return 0 -} - -## output info -info () { - local title='info' - - if (( "$#" > 1 )); then - title="$1" - shift - fi - - message 'cyan' "$title" "$@" - - return 0 -} - save_remote_file () { local auth_param dirname path url @@ -209,7 +133,7 @@ bpkg_install () { pkgs+=("$opt") shift else - error "Unknown option \`$opt'" + bpkg_error "Unknown option \`$opt'" return 1 fi ;; @@ -249,7 +173,7 @@ bpkg_install () { did_fail=0 break elif [[ "$?" == '2' ]]; then - error 'fatal error occurred during install' + bpkg_error 'fatal error occurred during install' return 1 fi i=$((i+1)) @@ -257,7 +181,7 @@ bpkg_install () { done if (( did_fail == 1 )); then - error 'package not found on any remote' + bpkg_error 'package not found on any remote' return 1 fi @@ -309,7 +233,7 @@ bpkg_install_from_remote () { name="${pkg_parts[0]}" version="${pkg_parts[1]}" else - error 'Error parsing package version' + bpkg_error 'Error parsing package version' return 1 fi @@ -329,7 +253,7 @@ bpkg_install_from_remote () { user="${pkg_parts[0]}" name="${pkg_parts[1]}" else - error 'Unable to determine package name' + bpkg_error 'Unable to determine package name' return 1 fi @@ -340,7 +264,7 @@ bpkg_install_from_remote () { ## check to see if remote is raw with oauth (GHE) if [[ "${remote:0:10}" == "raw-oauth|" ]]; then - info 'Using OAUTH basic with content requests' + bpkg_info 'Using OAUTH basic with content requests' OLDIFS="$IFS" IFS="'|'" local remote_parts=("$remote") @@ -360,7 +284,7 @@ bpkg_install_from_remote () { ## clean up extra slashes in uri uri=${uri/\/\///} - info "Install $uri from remote $remote [$git_remote]" + bpkg_info "Install $uri from remote $remote [$git_remote]" ## Ensure remote is reachable ## If a remote is totally down, this will be considered a fatal @@ -368,7 +292,7 @@ bpkg_install_from_remote () { ## from the broken remote. { if ! url_exists "$remote" "$auth_param"; then - error "Remote unreachable: $remote" + bpkg_error "Remote unreachable: $remote" return 2 fi } @@ -392,7 +316,7 @@ bpkg_install_from_remote () { if (( 0 == has_pkg_json )); then ## check to see if there's a Makefile. If not, this is not a valid package if ! url_exists "$url/Makefile?$nonce" "$auth_param"; then - warn "Makefile not found, skipping remote: $url" + bpkg_warn "Makefile not found, skipping remote: $url" return 1 fi fi @@ -462,8 +386,8 @@ bpkg_install_from_remote () { fi if [[ -z "$build" ]]; then - warn 'Missing build script' - warn 'Trying "make install"...' + bpkg_warn 'Missing build script' + bpkg_warn 'Trying "make install"...' build='make install' fi @@ -483,7 +407,7 @@ bpkg_install_from_remote () { ( (( 0 == prevent_prune )) && rm -rf "$name-$version") ## shallow clone - info "Cloning $repo_url to $(pwd)/$name-$version" + bpkg_info "Cloning $repo_url to $(pwd)/$name-$version" (test -d "$name-$version" || git clone "$repo_url" "$name-$version" 2>/dev/null) && ( ## move into directory cd "$name-$version" && ( @@ -495,7 +419,7 @@ bpkg_install_from_remote () { ) ## build - info "Performing install: \`$build'" + bpkg_info "Performing install: \`$build'" mkdir -p "$PREFIX"/{bin,lib} build_output=$(eval "$build") echo "$build_output" @@ -518,7 +442,7 @@ bpkg_install_from_remote () { mkdir -p "$BPKG_PACKAGE_DEPS/bin" # install package dependencies - info "Install dependencies for $name" + bpkg_info "Install dependencies for $name" BPKG_DEPS_EXEC="bpkg_getdeps" if (( 1 == install_dev )); then @@ -533,19 +457,19 @@ bpkg_install_from_remote () { if [[ "$script" ]];then local scriptname="$(echo "$script" | xargs basename )" - info "fetch" "$url/$script" - warn "BPKG_PACKAGE_DEPS is '$BPKG_PACKAGE_DEPS'" - info "write" "$BPKG_PACKAGE_DEPS/$name/$script" + bpkg_info "fetch" "$url/$script" + bpkg_warn "BPKG_PACKAGE_DEPS is '$BPKG_PACKAGE_DEPS'" + bpkg_info "write" "$BPKG_PACKAGE_DEPS/$name/$script" save_remote_file "$url/$script" "$BPKG_PACKAGE_DEPS/$name/$script" "$auth_param" scriptname="${scriptname%.*}" - info "$scriptname to PATH" "$BPKG_PACKAGE_DEPS/bin/$scriptname" + bpkg_info "$scriptname to PATH" "$BPKG_PACKAGE_DEPS/bin/$scriptname" if (( force_actions == 1 )); then ln -sf "../$name/$script" "$BPKG_PACKAGE_DEPS/bin/$scriptname" else if test -f "$BPKG_PACKAGE_DEPS/bin/$scriptname"; then - warn "'$BPKG_PACKAGE_DEPS/bin/$scriptname' already exists. Overwrite? (yN)" + bpkg_warn "'$BPKG_PACKAGE_DEPS/bin/$scriptname' already exists. Overwrite? (yN)" read -r yn case $yn in Yy) rm -f "$BPKG_PACKAGE_DEPS/bin/$scriptname" ;; @@ -565,9 +489,9 @@ bpkg_install_from_remote () { for file in "${files[@]}"; do ( if [[ "$file" ]];then - info "fetch" "$url/$file" - warn "BPKG_PACKAGE_DEPS is '$BPKG_PACKAGE_DEPS'" - info "write" "$BPKG_PACKAGE_DEPS/$name/$file" + bpkg_info "fetch" "$url/$file" + bpkg_warn "BPKG_PACKAGE_DEPS is '$BPKG_PACKAGE_DEPS'" + bpkg_info "write" "$BPKG_PACKAGE_DEPS/$name/$file" save_remote_file "$url/$file" "$BPKG_PACKAGE_DEPS/$name/$file" "$auth_param" fi ) @@ -580,7 +504,7 @@ bpkg_install_from_remote () { ## Use as lib or perform install if [[ ${BASH_SOURCE[0]} != "$0" ]]; then export -f bpkg_install -elif validate_parameters; then +elif bpkg_validate; then bpkg_install "$@" exit $? else diff --git a/lib/list/list.sh b/lib/list/list.sh index a3f33e25..0df7c1a7 100755 --- a/lib/list/list.sh +++ b/lib/list/list.sh @@ -3,11 +3,11 @@ if ! type -f bpkg-utils &>/dev/null; then echo "error: bpkg-utils not found, aborting" exit 1 -else - # shellcheck source=lib/utils/utils.sh - source "$(which bpkg-utils)" fi +# shellcheck source=lib/utils/utils.sh +source "$(which bpkg-utils)" + bpkg_initrc usage () { diff --git a/lib/package/package.sh b/lib/package/package.sh index c63677f2..65065575 100755 --- a/lib/package/package.sh +++ b/lib/package/package.sh @@ -1,14 +1,17 @@ #!/usr/bin/env bash -if ! type -f bpkg-realpath &>/dev/null; then - echo "error: bpkg-realpath not found, aborting" +if ! type -f bpkg-utils &>/dev/null; then + echo "error: bpkg-utils not found, aborting" exit 1 -else - # shellcheck disable=SC2230 - # shellcheck source=lib/realpath/realpath.sh - source "$(which bpkg-realpath)" fi +# shellcheck source=lib/utils/utils.sh +source "$(which bpkg-utils)" + +# shellcheck source=lib/realpath/realpath.sh +bpkg_exec_or_exit bpkg-realpath && + source "$(which bpkg-realpath)" + BPKG_JSON="$(which bpkg-json)" if [ -z "$BPKG_JSON" ]; then diff --git a/lib/run/run.sh b/lib/run/run.sh index 936c69b8..371207a5 100755 --- a/lib/run/run.sh +++ b/lib/run/run.sh @@ -1,62 +1,81 @@ #!/usr/bin/env bash -if ! type -f bpkg-realpath &>/dev/null; then - echo "error: bpkg-realpath not found, aborting" - exit 1 -else - # shellcheck disable=SC2230 - # shellcheck source=lib/realpath/realpath.sh - source "$(which bpkg-realpath)" -fi - if ! type -f bpkg-utils &>/dev/null; then echo "error: bpkg-utils not found, aborting" exit 1 -else - # shellcheck source=lib/utils/utils.sh - source "$(which bpkg-utils)" fi -if ! type -f bpkg-env &>/dev/null; then - echo "error: bpkg-env not found, aborting" - exit 1 -else - # shellcheck disable=SC2230 - # shellcheck source=lib/env/env.sh - source "$(which bpkg-env)" -fi +# shellcheck source=lib/utils/utils.sh +source "$(which bpkg-utils)" -if ! type -f bpkg-install &>/dev/null; then - echo "error: bpkg-install not found, aborting" - exit 1 -else - # shellcheck source=lib/install/install.sh +# shellcheck source=lib/realpath/realpath.sh +bpkg_exec_or_exit bpkg-realpath && + source "$(which bpkg-realpath)" + +# shellcheck source=lib/install/install.sh +bpkg_exec_or_exit bpkg-install && source "$(which bpkg-install)" -fi -if ! type -f bpkg-package &>/dev/null; then - echo "error: bpkg-package not found, aborting" - exit 1 -else - # shellcheck source=lib/package/package.sh +# shellcheck source=lib/package/package.sh +bpkg_exec_or_exit bpkg-package && source "$(which bpkg-package)" -fi bpkg_initrc ## output usage usage () { echo 'usage: bpkg-run [-h|--help]' - echo ' or: bpkg-run [-h|--help] [command]' + echo ' or: bpkg-run [-l|--list]' echo ' or: bpkg-run [-s|--source] [command]' echo ' or: bpkg-run [-s|--source] / [command]' } -runner () { +bpkg_list_commands () { + local commands + local col_len + local description + + commands="$(bpkg_package 2>/dev/null | grep '\["commands"' | sed 's/\["commands","\([^"]*\).*/\1/')" + + col_len="$(wc -L <<< "${commands}")" + + if [ "${col_len}" -eq 0 ]; then + bpkg_error "No commands provided in BPKG package file." + return 1 + fi + + for command in ${commands}; do + description="$(bpkg_package commands-description "${command}")" + + if [ -z "${description}" ]; then + description="Runs the ${command} command as defined in BPKG configuration" + fi + printf " " + + bpkg_exec_exist bpkg-term && + bpkg-term color cyan + + printf "%-${col_len}s " "${command}" + + bpkg_exec_exist bpkg-term && { + bpkg-term reset + bpkg-term bright + } + + printf "%s\n" "${description}" + + bpkg_exec_exist bpkg-term && + bpkg-term reset + done + + return 0 +} + +bpkg_runner () { local cmd="$1" - shift - # shellcheck disable=SC2068 + eval "$cmd" + return $? } @@ -75,6 +94,11 @@ bpkg_run () { return 0 ;; + -l|--list) + bpkg_list_commands + return $? + ;; + -s|--source) should_source=1 shift @@ -137,8 +161,7 @@ bpkg_run () { done shift - # shellcheck disable=SC2068 - runner "$prefix ${args[*]}" $@ + bpkg_runner "$prefix ${args[*]}" return $? fi fi @@ -172,9 +195,9 @@ bpkg_run () { return 1 fi - local pkgname="$(bpkg_package name 2>/dev/null)" - if [ -n "$pkgname" ]; then - name="$pkgname" + local pkg_name="$(bpkg_package name 2>/dev/null)" + if [ -n "$pkg_name" ]; then + name="$pkg_name" fi if (( 1 == should_emit_source )); then @@ -218,8 +241,7 @@ bpkg_run () { done shift - # shellcheck disable=SC2068 - runner "$prefix ${args[*]}" $@ + bpkg_runner "$prefix ${args[*]}" fi # shellcheck disable=SC2068 diff --git a/lib/show/show.sh b/lib/show/show.sh index 1b223b0a..d9bfd251 100755 --- a/lib/show/show.sh +++ b/lib/show/show.sh @@ -3,19 +3,10 @@ if ! type -f bpkg-utils &>/dev/null; then echo "error: bpkg-utils not found, aborting" exit 1 -else - # shellcheck source=lib/utils/utils.sh - source "$(which bpkg-utils)" fi -if ! type -f bpkg-env &>/dev/null; then - echo "error: bpkg-env not found, aborting" - exit 1 -else - # shellcheck disable=SC2230 - # shellcheck source=lib/env/env.sh - source "$(which bpkg-env)" -fi +# shellcheck source=lib/utils/utils.sh +source "$(which bpkg-utils)" bpkg_initrc diff --git a/lib/source/source.sh b/lib/source/source.sh index 86eebb2b..f54c080f 100755 --- a/lib/source/source.sh +++ b/lib/source/source.sh @@ -1,13 +1,18 @@ #!/usr/bin/env bash -if ! type -f bpkg-run &>/dev/null; then - echo "error: bpkg-run not found, aborting" +if ! type -f bpkg-utils &>/dev/null; then + echo "error: bpkg-utils not found, aborting" exit 1 -else - # shellcheck source=lib/run/run.sh - source "$(which bpkg-run)" fi +# shellcheck source=lib/utils/utils.sh +source "$(which bpkg-utils)" + +# shellcheck source=lib/run/run.sh +bpkg_exec_or_exit bpkg-run && + source "$(which bpkg-run)" + + bpkg_source () { # shellcheck disable=SC2068 bpkg_run --emit-source --target "$1" ${@:2} diff --git a/lib/suggest/suggest.sh b/lib/suggest/suggest.sh index d805426a..1abd46c7 100755 --- a/lib/suggest/suggest.sh +++ b/lib/suggest/suggest.sh @@ -3,12 +3,11 @@ if ! type -f bpkg-utils &>/dev/null; then echo "error: bpkg-utils not found, aborting" exit 1 -else - # shellcheck disable=SC2230 - # shellcheck source=lib/utils/utils.sh - source "$(which bpkg-utils)" fi +# shellcheck source=lib/utils/utils.sh +source "$(which bpkg-utils)" + ## output usage usage () { echo "usage: bpkg-suggest [-h|--help] " diff --git a/lib/update/update.sh b/lib/update/update.sh index 18ae4dd6..83504b2f 100755 --- a/lib/update/update.sh +++ b/lib/update/update.sh @@ -3,11 +3,11 @@ if ! type -f bpkg-utils &>/dev/null; then echo "error: bpkg-utils not found, aborting" exit 1 -else - # shellcheck source=lib/utils/utils.sh - source "$(which bpkg-utils)" fi +# shellcheck source=lib/utils/utils.sh +source "$(which bpkg-utils)" + bpkg_initrc usage () { diff --git a/lib/utils/utils.sh b/lib/utils/utils.sh index febe113c..2b5c467b 100755 --- a/lib/utils/utils.sh +++ b/lib/utils/utils.sh @@ -1,161 +1,185 @@ #!/usr/bin/env bash -if ! type -f bpkg-env &>/dev/null; then - echo "error: bpkg-env not found, aborting" - exit 1 -else - # shellcheck disable=SC2230 - # shellcheck source=lib/env/env.sh - source "$(which bpkg-env)" -fi +if [ -z "${BPKG_UTILS}" ]; then + BPKG_UTILS=1 + + ## Collection of shared bpkg functions + + ## Init local config and set environmental defaults + bpkg_initrc () { + local global_config=${BPKG_GLOBAL_CONFIG:-"/etc/bpkgrc"} + # shellcheck disable=SC1090 + [ -f "$global_config" ] && source "$global_config" + local config=${BPKG_CONFIG:-"$HOME/.bpkgrc"} + # shellcheck disable=SC1090 + [ -f "$config" ] && source "$config" + ## set defaults + if [ ${#BPKG_REMOTES[@]} -eq 0 ]; then + BPKG_REMOTES[0]=${BPKG_REMOTE-https://raw.githubusercontent.com} + BPKG_GIT_REMOTES[0]=${BPKG_GIT_REMOTE-https://github.com} + + export BPKG_REMOTES + export BPKG_GIT_REMOTE + export BPKG_GIT_REMOTES + fi -## Collection of shared bpkg functions - -## Init local config and set environmental defaults -bpkg_initrc() { - local global_config=${BPKG_GLOBAL_CONFIG:-"/etc/bpkgrc"} - # shellcheck disable=SC1090 - [ -f "$global_config" ] && source "$global_config" - local config=${BPKG_CONFIG:-"$HOME/.bpkgrc"} - # shellcheck disable=SC1090 - [ -f "$config" ] && source "$config" - ## set defaults - if [ ${#BPKG_REMOTES[@]} -eq 0 ]; then - BPKG_REMOTES[0]=${BPKG_REMOTE-https://raw.githubusercontent.com} - BPKG_GIT_REMOTES[0]=${BPKG_GIT_REMOTE-https://github.com} - - export BPKG_REMOTES - export BPKG_GIT_REMOTE - export BPKG_GIT_REMOTES - fi - - export BPKG_PACKAGE_USER="${BPKG_PACKAGE_USER:-"bpkg"}" - export BPKG_INDEX=${BPKG_INDEX:-"$HOME/.bpkg/index"} - - bpkg_validate - - return $? -} - -## check parameter consistency -bpkg_validate () { - if [ ${#BPKG_GIT_REMOTES[@]} -ne ${#BPKG_REMOTES[@]} ]; then - bpkg_error "$(printf 'BPKG_GIT_REMOTES[%d] differs in size from BPKG_REMOTES[%d] array' "${#BPKG_GIT_REMOTES[@]}" "${#BPKG_REMOTES[@]}")" - return 1 - fi - return 0 -} - -## format and output message -bpkg_message () { - if type -f bpkg-term > /dev/null 2>&1; then - bpkg-term color "${1}" - fi - - shift - echo -n " ${1}" - shift - - if type -f bpkg-term > /dev/null 2>&1; then - bpkg-term reset - fi - - printf ": " - - if type -f bpkg-term > /dev/null 2>&1; then - bpkg-term reset - bpkg-term bright - fi - - printf "%s\n" "${@}" - - if type -f bpkg-term > /dev/null 2>&1; then - bpkg-term reset - fi -} - -## output error -bpkg_error () { - { - bpkg_message "red" "error" "${@}" - } >&2 -} - -## output warning -bpkg_warn () { - { - bpkg_message "yellow" "warn" "${@}" - } >&2 -} - -## output info -bpkg_info () { - local title="info" - if (( "${#}" > 1 )); then - title="${1}" + export BPKG_PACKAGE_USER="${BPKG_PACKAGE_USER:-"bpkg"}" + export BPKG_INDEX=${BPKG_INDEX:-"$HOME/.bpkg/index"} + + bpkg_validate + + return $? + } + + ## check parameter consistency + bpkg_validate () { + if [ ${#BPKG_GIT_REMOTES[@]} -ne ${#BPKG_REMOTES[@]} ]; then + bpkg_error "$(printf 'BPKG_GIT_REMOTES[%d] differs in size from BPKG_REMOTES[%d] array' "${#BPKG_GIT_REMOTES[@]}" "${#BPKG_REMOTES[@]}")" + return 1 + fi + return 0 + } + + + ## format and output message + bpkg_message () { + bpkg_exec_exist bpkg-term && + bpkg-term color "${1}" + shift + + echo -n " ${1}" shift - fi - bpkg_message "cyan" "${title}" "${@}" -} - -## takes a remote and git-remote and sets the globals: -## BPKG_REMOTE: raw remote URI -## BPKG_GIT_REMOTE: git remote for cloning -## BPKG_AUTH_GIT_REMOTE: git remote with oauth info embedded, -## BPKG_OAUTH_TOKEN: token for x-oauth-basic -## BPKG_CURL_AUTH_PARAM: auth arguments for raw curl requests -## BPKG_REMOTE_INDEX: location of local index for remote -bpkg_select_remote () { - local remote=$1 - local git_remote=$2 - export BPKG_REMOTE_HOST=$(echo "$git_remote" | sed 's/.*:\/\///' | sed 's/\/$//' | tr '/' '_') - export BPKG_REMOTE_INDEX="$BPKG_INDEX/$BPKG_REMOTE_HOST" - # shellcheck disable=SC2034 - export BPKG_REMOTE_INDEX_FILE="$BPKG_REMOTE_INDEX/index.txt" - export BPKG_OAUTH_TOKEN="" - export BPKG_CURL_AUTH_PARAM="" - export BPKG_GIT_REMOTE=$git_remote - export BPKG_AUTH_GIT_REMOTE=$git_remote - if [ "${remote:0:10}" == "raw-oauth|" ]; then - OLDIFS="${IFS}" - IFS="|" - # shellcheck disable=SC2206 - local remote_parts=($remote) - IFS="${OLDIFS}" - export BPKG_OAUTH_TOKEN=${remote_parts[1]} + + bpkg_exec_exist bpkg-term && + bpkg-term reset + + printf ": " + + bpkg_exec_exist bpkg-term && { + bpkg-term reset + bpkg-term bright + } + + printf "%s\n" "${@}" + + bpkg_exec_exist bpkg-term && + bpkg-term reset + } + + ## output error + bpkg_error () { + { + bpkg_message "red" "error" "${@}" + } >&2 + } + + ## output warning + bpkg_warn () { + { + bpkg_message "yellow" "warn" "${@}" + } >&2 + } + + ## output info + bpkg_info () { + local title="info" + if (( "${#}" > 1 )); then + title="${1}" + shift + fi + bpkg_message "cyan" "${title}" "${@}" + } + + + ## check if executable exists in path + bpkg_exec_exist () { + local exec_name="${1}" + + type -f "${exec_name}" > /dev/null 2>&1 + } + + ## executable exists in path or exit with message + bpkg_exec_or_exit () { + local exec_name="${1}" + local exit_error="${2:-1}" + + if ! bpkg_exec_exist "${exec_name}"; then + bpkg_error "${exec_name} not found, aborting" + exit "${exit_error}" + fi + } + + + ## takes a remote and git-remote and sets the globals: + ## BPKG_REMOTE: raw remote URI + ## BPKG_GIT_REMOTE: git remote for cloning + ## BPKG_AUTH_GIT_REMOTE: git remote with oauth info embedded, + ## BPKG_OAUTH_TOKEN: token for x-oauth-basic + ## BPKG_CURL_AUTH_PARAM: auth arguments for raw curl requests + ## BPKG_REMOTE_INDEX: location of local index for remote + bpkg_select_remote () { + local remote=$1 + local git_remote=$2 + export BPKG_REMOTE_HOST=$(echo "$git_remote" | sed 's/.*:\/\///' | sed 's/\/$//' | tr '/' '_') + export BPKG_REMOTE_INDEX="$BPKG_INDEX/$BPKG_REMOTE_HOST" # shellcheck disable=SC2034 - export BPKG_CURL_AUTH_PARAM="-u $BPKG_OAUTH_TOKEN:x-oauth-basic" - export BPKG_REMOTE=${remote_parts[2]} - if [[ "$git_remote" == https://* ]] && [[ "$git_remote" != *x-oauth-basic* ]] && [[ "$git_remote" != *${BPKG_OAUTH_TOKEN}* ]]; then + export BPKG_REMOTE_INDEX_FILE="$BPKG_REMOTE_INDEX/index.txt" + export BPKG_OAUTH_TOKEN="" + export BPKG_CURL_AUTH_PARAM="" + export BPKG_GIT_REMOTE=$git_remote + export BPKG_AUTH_GIT_REMOTE=$git_remote + if [ "${remote:0:10}" == "raw-oauth|" ]; then + OLDIFS="${IFS}" + IFS="|" + # shellcheck disable=SC2206 + local remote_parts=($remote) + IFS="${OLDIFS}" + export BPKG_OAUTH_TOKEN=${remote_parts[1]} # shellcheck disable=SC2034 - export BPKG_AUTH_GIT_REMOTE=${git_remote/https:\/\//https:\/\/$BPKG_OAUTH_TOKEN:x-oauth-basic@} + export BPKG_CURL_AUTH_PARAM="-u $BPKG_OAUTH_TOKEN:x-oauth-basic" + export BPKG_REMOTE=${remote_parts[2]} + if [[ "$git_remote" == https://* ]] && [[ "$git_remote" != *x-oauth-basic* ]] && [[ "$git_remote" != *${BPKG_OAUTH_TOKEN}* ]]; then + # shellcheck disable=SC2034 + export BPKG_AUTH_GIT_REMOTE=${git_remote/https:\/\//https:\/\/$BPKG_OAUTH_TOKEN:x-oauth-basic@} + fi + else + export BPKG_REMOTE="$remote" fi - else - export BPKG_REMOTE="$remote" - fi -} - -## given a user and name, sets BPKG_REMOTE_RAW_PATH using the available -## BPKG_REMOTE and BPKG_OAUTH_TOKEN details -bpkg_select_raw_path() { - local user=$1 - local name=$2 - if [ "$BPKG_OAUTH_TOKEN" == "" ]; then - export BPKG_REMOTE_RAW_PATH="$BPKG_REMOTE/$user/$name" - else - # shellcheck disable=SC2034 - Export BPKG_REMOTE_RAW_PATH="$BPKG_REMOTE/$user/$name/raw" - fi - return 0 -} + } + + ## given a user and name, sets BPKG_REMOTE_RAW_PATH using the available + ## BPKG_REMOTE and BPKG_OAUTH_TOKEN details + bpkg_select_raw_path () { + local user=$1 + local name=$2 + if [ "$BPKG_OAUTH_TOKEN" == "" ]; then + export BPKG_REMOTE_RAW_PATH="$BPKG_REMOTE/$user/$name" + else + # shellcheck disable=SC2034 + Export BPKG_REMOTE_RAW_PATH="$BPKG_REMOTE/$user/$name/raw" + fi + return 0 + } + -export -f bpkg_initrc -export -f bpkg_validate + bpkg_exec_or_exit bpkg-env + + # shellcheck disable=SC2230 + # shellcheck source=lib/env/env.sh + source "$(which bpkg-env)" -export -f bpkg_message -export -f bpkg_warn -export -f bpkg_error -export -f bpkg_info -export -f bpkg_select_remote -export -f bpkg_select_raw_path + export -f bpkg_initrc + export -f bpkg_validate + + export -f bpkg_message + export -f bpkg_warn + export -f bpkg_error + export -f bpkg_info + + export -f bpkg_exec_exist + export -f bpkg_exec_or_exit + + export -f bpkg_select_remote + export -f bpkg_select_raw_path +fi From 91ef3ff1c8f06b06f47f97185d3e6b71398dd478 Mon Sep 17 00:00:00 2001 From: Sam Likins Date: Sat, 17 Jun 2023 14:16:21 -0700 Subject: [PATCH 10/13] Fix run passing parameters to command. (#162) --- lib/run/run.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/run/run.sh b/lib/run/run.sh index 371207a5..381af279 100755 --- a/lib/run/run.sh +++ b/lib/run/run.sh @@ -73,6 +73,7 @@ bpkg_list_commands () { bpkg_runner () { local cmd="$1" + shift eval "$cmd" @@ -161,7 +162,7 @@ bpkg_run () { done shift - bpkg_runner "$prefix ${args[*]}" + bpkg_runner "$prefix ${args[*]}" "$@" return $? fi fi @@ -241,7 +242,7 @@ bpkg_run () { done shift - bpkg_runner "$prefix ${args[*]}" + bpkg_runner "$prefix ${args[*]}" "$@" fi # shellcheck disable=SC2068 From 9c34a8f0d881833f9c972d0bdc91717c5ff31ef6 Mon Sep 17 00:00:00 2001 From: Edwin Kofler Date: Tue, 15 Aug 2023 12:42:24 -0700 Subject: [PATCH 11/13] fix: Interpret most escape sequence within JSON strings --- lib/install/install.sh | 7 ++++--- lib/json/JSON.sh | 39 ++++++++++++++++++++++++++++++++++----- 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/lib/install/install.sh b/lib/install/install.sh index e6e41335..9b7c60ae 100755 --- a/lib/install/install.sh +++ b/lib/install/install.sh @@ -164,7 +164,7 @@ bpkg_install () { did_fail=0 continue fi - + ## Check each remote in order local i=0 for remote in "${BPKG_REMOTES[@]}"; do @@ -381,8 +381,9 @@ bpkg_install_from_remote () { if (( 1 == needs_global )); then if (( has_pkg_json > 0 )); then ## install bin if needed - build="$(echo -n "$json" | bpkg-json -b | grep '\["install"\]' | awk '{$1=""; print $0 }' | tr -d '\"')" - build="$(echo -n "$build" | sed -e 's/^ *//' -e 's/ *$//')" + build="$(echo -n "$json" | bpkg-json -b -f='"install"')" + build=${build#\"} + build=${build%\"} fi if [[ -z "$build" ]]; then diff --git a/lib/json/JSON.sh b/lib/json/JSON.sh index 1b5451b6..78a8f4c5 100755 --- a/lib/json/JSON.sh +++ b/lib/json/JSON.sh @@ -8,18 +8,36 @@ throw () { BRIEF=0 LEAFONLY=0 PRUNE=0 +FILTER= usage() { echo - echo "Usage: JSON.sh [-b] [-l] [-p] [-h]" + echo "Usage: JSON.sh [-b] [-l] [-p] [-f=] [-h]" echo echo "-p - Prune empty. Exclude fields with empty values." echo "-l - Leaf only. Only show leaf nodes, which stops data duplication." echo "-b - Brief. Combines 'Leaf only' and 'Prune empty' options." + echo "-f - Filter. Only print the values for the keys that match the specified filter" echo "-h - This help text." echo } +escape_string() { + local str=$1 + + str=${str//\\\"/\"} + str=${str//\\\\/\\} + str=${str//\\\//\/} + str=${str//\\b/$'\b'} + str=${str//\\f/$'\f'} + str=${str//\\n/$'\n'} + str=${str//\\r/$'\r'} + str=${str//\\t/$'\t'} + # TODO: unicode escaping + + REPLY=$str +} + parse_options() { set -- "$@" local ARGN=$# @@ -37,6 +55,8 @@ parse_options() { ;; -p) PRUNE=1 ;; + -f=*) FILTER=${1#-f=} + ;; ?*) echo "ERROR: Unknown option." usage exit 0 @@ -126,7 +146,7 @@ parse_object () { while : do case "$token" in - '"'*'"') key=$token ;; + '"'*'"') escape_string "$token"; key=$REPLY ;; *) throw "EXPECTED string GOT ${token:-EOF}" ;; esac read -r token @@ -158,7 +178,7 @@ parse_value () { '[') parse_array "$jpath" ;; # At this point, the only valid single-character tokens are digits. ''|[!0-9]) throw "EXPECTED value GOT ${token:-EOF}" ;; - *) value=$token + *) escape_string "$token"; value=$REPLY isleaf=1 [ "$value" = '""' ] && isempty=1 ;; @@ -169,8 +189,17 @@ parse_value () { [ "$LEAFONLY" -eq 0 ] && [ "$PRUNE" -eq 1 ] && [ "$isempty" -eq 0 ] && print=1 [ "$LEAFONLY" -eq 1 ] && [ "$isleaf" -eq 1 ] && \ [ $PRUNE -eq 1 ] && [ $isempty -eq 0 ] && print=1 - [ "$print" -eq 1 ] && printf "[%s]\t%s\n" "$jpath" "$value" - : + + if [ "$print" -eq 1 ]; then + # FILTER + if [ -n "$FILTER" ]; then + if [ "$FILTER" = "$jpath" ]; then + printf '%s\n' "$value" + fi + else + printf "[%s]\t%s\n" "$jpath" "$value" + fi + fi } parse () { From df95293fcdb6af1b4ab72f4edb05eae5e7d40de2 Mon Sep 17 00:00:00 2001 From: Edwin Kofler Date: Tue, 15 Aug 2023 12:55:48 -0700 Subject: [PATCH 12/13] fix: Improve message when installing no packages --- lib/install/install.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/install/install.sh b/lib/install/install.sh index 9b7c60ae..6c813ad2 100755 --- a/lib/install/install.sh +++ b/lib/install/install.sh @@ -180,6 +180,11 @@ bpkg_install () { done done + if ((${#pkgs[@]} == 0)); then + bpkg_error 'no packages supplied' + return 1 + fi + if (( did_fail == 1 )); then bpkg_error 'package not found on any remote' return 1 From c7f5a467ec53e61d2344f5d1ab5766949c3bffdf Mon Sep 17 00:00:00 2001 From: Edwin Kofler Date: Fri, 25 Aug 2023 06:18:53 -0700 Subject: [PATCH 13/13] fix: Improve error reporting on failed git clone --- setup.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/setup.sh b/setup.sh index 97bd7687..07e6bc42 100755 --- a/setup.sh +++ b/setup.sh @@ -52,7 +52,12 @@ setup () { rm -rf "$DEST" echo " info: Fetching 'bpkg@$BRANCH'..." - git clone --depth=1 --branch "$BRANCH" "$REMOTE" "$DEST" > /dev/null 2>&1 + if ! output=$(git clone --depth=1 --branch "$BRANCH" "$REMOTE" "$DEST" 2>&1); then + printf '%s\n' " error: Failed to clone repository." >&2 + printf '%s\n' "GIT ERROR OUTPUT:" + printf '%s\n' "$output" + exit 1 + fi cd "$DEST" || exit echo " info: Installing..."