Compare commits

..

1 Commits

Author SHA1 Message Date
Joseph Werle bb7f11effb chore(): 1.1.3 2 years ago

@ -15,7 +15,6 @@ You can install shell scripts globally (on `${PREFIX:-/usr/local/bin}`) or use t
* [Usage](#usage) * [Usage](#usage)
* [Installing packages](#installing-packages) * [Installing packages](#installing-packages)
* [Packages With Dependencies](#packages-with-dependencies) * [Packages With Dependencies](#packages-with-dependencies)
* [Running packages with `bpkg`](#running-packages-with-bpkg)
* [Retrieving package info](#retrieving-package-info) * [Retrieving package info](#retrieving-package-info)
* [Package details](#package-details) * [Package details](#package-details)
* [bpkg.json](#bpkgjson) * [bpkg.json](#bpkgjson)
@ -25,17 +24,13 @@ You can install shell scripts globally (on `${PREFIX:-/usr/local/bin}`) or use t
* [global](#global) * [global](#global)
* [install](#install-1) * [install](#install-1)
* [scripts](#scripts) * [scripts](#scripts)
* [files (optional)](#files-optional) * [files](#files)
* [dependencies (optional)](#dependencies-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) * [Packaging best practices](#packaging-best-practices)
* [Package exports](#package-exports) * [Package exports](#package-exports)
* [Sponsors](#sponsors) * [Sponsors](#sponsors)
* [Contributors](#contributors)
* [Backers](#backers)
* [License](#license) * [License](#license)
<!-- END-MARKDOWN-TOC --> <!-- END-MARKDOWN-TOC -->
## Install ## Install
@ -245,9 +240,9 @@ This is an array of scripts that will be installed into a project.
"scripts": ["script.sh"] "scripts": ["script.sh"]
``` ```
### files (optional) ### files
This is an array of non-script files that will be installed into a project. This is an array of files that will be installed into a project.
```json ```json
"files": ["bar.txt", "foo.txt"] "files": ["bar.txt", "foo.txt"]
@ -263,43 +258,6 @@ 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.
```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
```
### 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 ## Packaging best practices
These are guidelines that we strongly encourage developers to follow. These are guidelines that we strongly encourage developers to follow.
@ -369,6 +327,3 @@ See file `LICENSE` for a more detailed description of its terms.
[clib]: https://github.com/clibs/clib [clib]: https://github.com/clibs/clib
[term]: https://github.com/bpkg/term [term]: https://github.com/bpkg/term
[json]: http://json.org/example [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

@ -1,6 +1,6 @@
{ {
"name": "bpkg", "name": "bpkg",
"version": "1.1.4", "version": "1.1.3",
"description": "Lightweight bash package manager", "description": "Lightweight bash package manager",
"global": true, "global": true,
"repo": "bpkg/bpkg", "repo": "bpkg/bpkg",
@ -8,9 +8,5 @@
"commands": { "commands": {
"lint": "command shellcheck **/*.sh", "lint": "command shellcheck **/*.sh",
"list-sources": "echo ${BPKG_PACKAGE_SOURCES[@]} | sed 's/ /\n/g'" "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"
} }
} }

@ -7,7 +7,7 @@ if [[ ${BASH_SOURCE[0]} != "$0" ]]; then
fi fi
## bpkg version ## bpkg version
VERSION="1.1.4" VERSION="1.1.3"
## output error to stderr ## output error to stderr
error () { error () {

@ -1,12 +1,9 @@
#!/usr/bin/env bash #!/usr/bin/env bash
let install_dev=0
## output usage ## output usage
usage () { usage () {
echo "Installs dependencies for a package." echo "Installs dependencies for a package."
echo "usage: bpkg-getdeps [-h|--help]" echo "usage: bpkg-getdeps [-h|--help]"
echo " or: bpkg-getdeps [-d|--dev]"
echo " or: bpkg-getdeps" echo " or: bpkg-getdeps"
} }
@ -21,11 +18,6 @@ bpkg_getdeps () {
usage usage
return 0 return 0
;; ;;
-d|--dev)
shift
install_dev=1
;;
esac esac
## ensure there is a package to read ## ensure there is a package to read
@ -38,17 +30,10 @@ bpkg_getdeps () {
fi fi
# shellcheck disable=SC2002 # 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 # shellcheck disable=SC2206
dependencies=(${dependencies[@]}) 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 ## run bpkg install for each dependency
for (( i = 0; i < ${#dependencies[@]} ; ++i )); do for (( i = 0; i < ${#dependencies[@]} ; ++i )); do
( (

@ -1,37 +1,111 @@
#!/usr/bin/env bash #!/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 if ! type -f bpkg-utils &>/dev/null; then
echo "error: bpkg-utils not found, aborting" echo "error: bpkg-utils not found, aborting"
exit 1 exit 1
else
# shellcheck disable=SC2230
# shellcheck source=lib/utils/utils.sh
source "$(which bpkg-utils)"
fi fi
# shellcheck source=lib/utils/utils.sh if ! type -f bpkg-getdeps &>/dev/null; then
source "$(which bpkg-utils)" echo "error: bpkg-getdeps not found, aborting"
exit 1
# shellcheck source=lib/realpath/realpath.sh else
bpkg_exec_or_exit bpkg-realpath && # shellcheck disable=SC2230
source "$(which bpkg-realpath)" # shellcheck source=lib/getdeps/getdeps.sh
# shellcheck source=lib/getdeps/getdeps.sh
bpkg_exec_or_exit bpkg-getdeps &&
source "$(which bpkg-getdeps)" source "$(which bpkg-getdeps)"
fi
bpkg_initrc bpkg_initrc
let prevent_prune=0 let prevent_prune=0
let install_dev=0
let force_actions=${BPKG_FORCE_ACTIONS:-0} let force_actions=${BPKG_FORCE_ACTIONS:-0}
let needs_global=0 let needs_global=0
## output usage ## 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
}
## outut usage
usage () { usage () {
echo 'usage: bpkg-install [directory]' echo 'usage: bpkg-install [directory]'
echo ' or: bpkg-install [-h|--help]' echo ' or: bpkg-install [-h|--help]'
echo ' or: bpkg-install [-d|--dev]'
echo ' or: bpkg-install [-g|--global] [-f|--force] ...<package>' echo ' or: bpkg-install [-g|--global] [-f|--force] ...<package>'
echo ' or: bpkg-install [-g|--global] [-f|--force] ...<user>/<package>' echo ' or: bpkg-install [-g|--global] [-f|--force] ...<user>/<package>'
} }
## 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 () { save_remote_file () {
local auth_param dirname path url local auth_param dirname path url
@ -118,11 +192,6 @@ bpkg_install () {
force_actions=1 force_actions=1
;; ;;
-d|--dev)
shift
install_dev=1
;;
--no-prune) --no-prune)
shift shift
prevent_prune=1 prevent_prune=1
@ -133,7 +202,7 @@ bpkg_install () {
pkgs+=("$opt") pkgs+=("$opt")
shift shift
else else
bpkg_error "Unknown option \`$opt'" error "Unknown option \`$opt'"
return 1 return 1
fi fi
;; ;;
@ -142,14 +211,9 @@ bpkg_install () {
export BPKG_FORCE_ACTIONS=$force_actions 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 ## ensure there is a package to install
if (( ${#pkgs[@]} == 0 )); then if (( ${#pkgs[@]} == 0 )); then
${BPKG_DEPS_EXEC} bpkg_getdeps
return $? return $?
fi fi
@ -157,7 +221,7 @@ bpkg_install () {
for pkg in "${pkgs[@]}"; do for pkg in "${pkgs[@]}"; do
if test -d "$(bpkg_realpath "$pkg" 2>/dev/null)"; then if test -d "$(bpkg_realpath "$pkg" 2>/dev/null)"; then
if ! (cd "$pkg" && ${BPKG_DEPS_EXEC}); then if ! (cd "$pkg" && bpkg_getdeps); then
return 1 return 1
fi fi
@ -169,24 +233,19 @@ bpkg_install () {
local i=0 local i=0
for remote in "${BPKG_REMOTES[@]}"; do for remote in "${BPKG_REMOTES[@]}"; do
local git_remote=${BPKG_GIT_REMOTES[$i]} local git_remote=${BPKG_GIT_REMOTES[$i]}
if bpkg_install_from_remote "$pkg" "$remote" "$git_remote" $needs_global $install_dev; then if bpkg_install_from_remote "$pkg" "$remote" "$git_remote" $needs_global; then
did_fail=0 did_fail=0
break break
elif [[ "$?" == '2' ]]; then elif [[ "$?" == '2' ]]; then
bpkg_error 'fatal error occurred during install' error 'fatal error occurred during install'
return 1 return 1
fi fi
i=$((i+1)) i=$((i+1))
done done
done done
if ((${#pkgs[@]} == 0)); then
bpkg_error 'no packages supplied'
return 1
fi
if (( did_fail == 1 )); then if (( did_fail == 1 )); then
bpkg_error 'package not found on any remote' error 'package not found on any remote'
return 1 return 1
fi fi
@ -203,7 +262,6 @@ bpkg_install_from_remote () {
local remote=$2 local remote=$2
local git_remote=$3 local git_remote=$3
local needs_global=$4 local needs_global=$4
local install_dev=$5
local url='' local url=''
local uri='' local uri=''
@ -238,7 +296,7 @@ bpkg_install_from_remote () {
name="${pkg_parts[0]}" name="${pkg_parts[0]}"
version="${pkg_parts[1]}" version="${pkg_parts[1]}"
else else
bpkg_error 'Error parsing package version' error 'Error parsing package version'
return 1 return 1
fi fi
@ -258,7 +316,7 @@ bpkg_install_from_remote () {
user="${pkg_parts[0]}" user="${pkg_parts[0]}"
name="${pkg_parts[1]}" name="${pkg_parts[1]}"
else else
bpkg_error 'Unable to determine package name' error 'Unable to determine package name'
return 1 return 1
fi fi
@ -269,7 +327,7 @@ bpkg_install_from_remote () {
## check to see if remote is raw with oauth (GHE) ## check to see if remote is raw with oauth (GHE)
if [[ "${remote:0:10}" == "raw-oauth|" ]]; then if [[ "${remote:0:10}" == "raw-oauth|" ]]; then
bpkg_info 'Using OAUTH basic with content requests' info 'Using OAUTH basic with content requests'
OLDIFS="$IFS" OLDIFS="$IFS"
IFS="'|'" IFS="'|'"
local remote_parts=("$remote") local remote_parts=("$remote")
@ -289,7 +347,7 @@ bpkg_install_from_remote () {
## clean up extra slashes in uri ## clean up extra slashes in uri
uri=${uri/\/\///} uri=${uri/\/\///}
bpkg_info "Install $uri from remote $remote [$git_remote]" info "Install $uri from remote $remote [$git_remote]"
## Ensure remote is reachable ## Ensure remote is reachable
## If a remote is totally down, this will be considered a fatal ## If a remote is totally down, this will be considered a fatal
@ -297,7 +355,7 @@ bpkg_install_from_remote () {
## from the broken remote. ## from the broken remote.
{ {
if ! url_exists "$remote" "$auth_param"; then if ! url_exists "$remote" "$auth_param"; then
bpkg_error "Remote unreachable: $remote" error "Remote unreachable: $remote"
return 2 return 2
fi fi
} }
@ -321,7 +379,7 @@ bpkg_install_from_remote () {
if (( 0 == has_pkg_json )); then if (( 0 == has_pkg_json )); then
## check to see if there's a Makefile. If not, this is not a valid package ## 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 if ! url_exists "$url/Makefile?$nonce" "$auth_param"; then
bpkg_warn "Makefile not found, skipping remote: $url" warn "Makefile not found, skipping remote: $url"
return 1 return 1
fi fi
fi fi
@ -386,14 +444,13 @@ bpkg_install_from_remote () {
if (( 1 == needs_global )); then if (( 1 == needs_global )); then
if (( has_pkg_json > 0 )); then if (( has_pkg_json > 0 )); then
## install bin if needed ## install bin if needed
build="$(echo -n "$json" | bpkg-json -b -f='"install"')" build="$(echo -n "$json" | bpkg-json -b | grep '\["install"\]' | awk '{$1=""; print $0 }' | tr -d '\"')"
build=${build#\"} build="$(echo -n "$build" | sed -e 's/^ *//' -e 's/ *$//')"
build=${build%\"}
fi fi
if [[ -z "$build" ]]; then if [[ -z "$build" ]]; then
bpkg_warn 'Missing build script' warn 'Missing build script'
bpkg_warn 'Trying "make install"...' warn 'Trying "make install"...'
build='make install' build='make install'
fi fi
@ -413,7 +470,7 @@ bpkg_install_from_remote () {
( (( 0 == prevent_prune )) && rm -rf "$name-$version") ( (( 0 == prevent_prune )) && rm -rf "$name-$version")
## shallow clone ## shallow clone
bpkg_info "Cloning $repo_url to $(pwd)/$name-$version" info "Cloning $repo_url to $(pwd)/$name-$version"
(test -d "$name-$version" || git clone "$repo_url" "$name-$version" 2>/dev/null) && ( (test -d "$name-$version" || git clone "$repo_url" "$name-$version" 2>/dev/null) && (
## move into directory ## move into directory
cd "$name-$version" && ( cd "$name-$version" && (
@ -425,7 +482,7 @@ bpkg_install_from_remote () {
) )
## build ## build
bpkg_info "Performing install: \`$build'" info "Performing install: \`$build'"
mkdir -p "$PREFIX"/{bin,lib} mkdir -p "$PREFIX"/{bin,lib}
build_output=$(eval "$build") build_output=$(eval "$build")
echo "$build_output" echo "$build_output"
@ -448,14 +505,8 @@ bpkg_install_from_remote () {
mkdir -p "$BPKG_PACKAGE_DEPS/bin" mkdir -p "$BPKG_PACKAGE_DEPS/bin"
# install package dependencies # install package dependencies
bpkg_info "Install dependencies for $name" 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 ## grab each script and place in deps directory
for script in "${scripts[@]}"; do for script in "${scripts[@]}"; do
@ -463,19 +514,19 @@ bpkg_install_from_remote () {
if [[ "$script" ]];then if [[ "$script" ]];then
local scriptname="$(echo "$script" | xargs basename )" local scriptname="$(echo "$script" | xargs basename )"
bpkg_info "fetch" "$url/$script" info "fetch" "$url/$script"
bpkg_warn "BPKG_PACKAGE_DEPS is '$BPKG_PACKAGE_DEPS'" warn "BPKG_PACKAGE_DEPS is '$BPKG_PACKAGE_DEPS'"
bpkg_info "write" "$BPKG_PACKAGE_DEPS/$name/$script" info "write" "$BPKG_PACKAGE_DEPS/$name/$script"
save_remote_file "$url/$script" "$BPKG_PACKAGE_DEPS/$name/$script" "$auth_param" save_remote_file "$url/$script" "$BPKG_PACKAGE_DEPS/$name/$script" "$auth_param"
scriptname="${scriptname%.*}" scriptname="${scriptname%.*}"
bpkg_info "$scriptname to PATH" "$BPKG_PACKAGE_DEPS/bin/$scriptname" info "$scriptname to PATH" "$BPKG_PACKAGE_DEPS/bin/$scriptname"
if (( force_actions == 1 )); then if (( force_actions == 1 )); then
ln -sf "../$name/$script" "$BPKG_PACKAGE_DEPS/bin/$scriptname" ln -sf "$BPKG_PACKAGE_DEPS/$name/$script" "$BPKG_PACKAGE_DEPS/bin/$scriptname"
else else
if test -f "$BPKG_PACKAGE_DEPS/bin/$scriptname"; then if test -f "$BPKG_PACKAGE_DEPS/bin/$scriptname"; then
bpkg_warn "'$BPKG_PACKAGE_DEPS/bin/$scriptname' already exists. Overwrite? (yN)" warn "'$BPKG_PACKAGE_DEPS/bin/$scriptname' already exists. Overwrite? (yN)"
read -r yn read -r yn
case $yn in case $yn in
Yy) rm -f "$BPKG_PACKAGE_DEPS/bin/$scriptname" ;; Yy) rm -f "$BPKG_PACKAGE_DEPS/bin/$scriptname" ;;
@ -483,7 +534,7 @@ bpkg_install_from_remote () {
esac esac
fi fi
ln -s "../$name/$script" "$BPKG_PACKAGE_DEPS/bin/$scriptname" ln -s "$BPKG_PACKAGE_DEPS/$name/$script" "$BPKG_PACKAGE_DEPS/bin/$scriptname"
fi fi
chmod u+x "$BPKG_PACKAGE_DEPS/bin/$scriptname" chmod u+x "$BPKG_PACKAGE_DEPS/bin/$scriptname"
fi fi
@ -495,9 +546,9 @@ bpkg_install_from_remote () {
for file in "${files[@]}"; do for file in "${files[@]}"; do
( (
if [[ "$file" ]];then if [[ "$file" ]];then
bpkg_info "fetch" "$url/$file" info "fetch" "$url/$file"
bpkg_warn "BPKG_PACKAGE_DEPS is '$BPKG_PACKAGE_DEPS'" warn "BPKG_PACKAGE_DEPS is '$BPKG_PACKAGE_DEPS'"
bpkg_info "write" "$BPKG_PACKAGE_DEPS/$name/$file" info "write" "$BPKG_PACKAGE_DEPS/$name/$file"
save_remote_file "$url/$file" "$BPKG_PACKAGE_DEPS/$name/$file" "$auth_param" save_remote_file "$url/$file" "$BPKG_PACKAGE_DEPS/$name/$file" "$auth_param"
fi fi
) )
@ -510,7 +561,7 @@ bpkg_install_from_remote () {
## Use as lib or perform install ## Use as lib or perform install
if [[ ${BASH_SOURCE[0]} != "$0" ]]; then if [[ ${BASH_SOURCE[0]} != "$0" ]]; then
export -f bpkg_install export -f bpkg_install
elif bpkg_validate; then elif validate_parameters; then
bpkg_install "$@" bpkg_install "$@"
exit $? exit $?
else else

@ -8,36 +8,18 @@ throw () {
BRIEF=0 BRIEF=0
LEAFONLY=0 LEAFONLY=0
PRUNE=0 PRUNE=0
FILTER=
usage() { usage() {
echo echo
echo "Usage: JSON.sh [-b] [-l] [-p] [-f=<filter>] [-h]" echo "Usage: JSON.sh [-b] [-l] [-p] [-h]"
echo echo
echo "-p - Prune empty. Exclude fields with empty values." echo "-p - Prune empty. Exclude fields with empty values."
echo "-l - Leaf only. Only show leaf nodes, which stops data duplication." echo "-l - Leaf only. Only show leaf nodes, which stops data duplication."
echo "-b - Brief. Combines 'Leaf only' and 'Prune empty' options." 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 "-h - This help text."
echo 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() { parse_options() {
set -- "$@" set -- "$@"
local ARGN=$# local ARGN=$#
@ -55,8 +37,6 @@ parse_options() {
;; ;;
-p) PRUNE=1 -p) PRUNE=1
;; ;;
-f=*) FILTER=${1#-f=}
;;
?*) echo "ERROR: Unknown option." ?*) echo "ERROR: Unknown option."
usage usage
exit 0 exit 0
@ -146,7 +126,7 @@ parse_object () {
while : while :
do do
case "$token" in case "$token" in
'"'*'"') escape_string "$token"; key=$REPLY ;; '"'*'"') key=$token ;;
*) throw "EXPECTED string GOT ${token:-EOF}" ;; *) throw "EXPECTED string GOT ${token:-EOF}" ;;
esac esac
read -r token read -r token
@ -178,7 +158,7 @@ parse_value () {
'[') parse_array "$jpath" ;; '[') parse_array "$jpath" ;;
# At this point, the only valid single-character tokens are digits. # At this point, the only valid single-character tokens are digits.
''|[!0-9]) throw "EXPECTED value GOT ${token:-EOF}" ;; ''|[!0-9]) throw "EXPECTED value GOT ${token:-EOF}" ;;
*) escape_string "$token"; value=$REPLY *) value=$token
isleaf=1 isleaf=1
[ "$value" = '""' ] && isempty=1 [ "$value" = '""' ] && isempty=1
;; ;;
@ -189,17 +169,8 @@ parse_value () {
[ "$LEAFONLY" -eq 0 ] && [ "$PRUNE" -eq 1 ] && [ "$isempty" -eq 0 ] && print=1 [ "$LEAFONLY" -eq 0 ] && [ "$PRUNE" -eq 1 ] && [ "$isempty" -eq 0 ] && print=1
[ "$LEAFONLY" -eq 1 ] && [ "$isleaf" -eq 1 ] && \ [ "$LEAFONLY" -eq 1 ] && [ "$isleaf" -eq 1 ] && \
[ $PRUNE -eq 1 ] && [ $isempty -eq 0 ] && print=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 () { parse () {

@ -3,11 +3,11 @@
if ! type -f bpkg-utils &>/dev/null; then if ! type -f bpkg-utils &>/dev/null; then
echo "error: bpkg-utils not found, aborting" echo "error: bpkg-utils not found, aborting"
exit 1 exit 1
else
# shellcheck source=lib/utils/utils.sh
source "$(which bpkg-utils)"
fi fi
# shellcheck source=lib/utils/utils.sh
source "$(which bpkg-utils)"
bpkg_initrc bpkg_initrc
usage () { usage () {

@ -1,16 +1,13 @@
#!/usr/bin/env bash #!/usr/bin/env bash
if ! type -f bpkg-utils &>/dev/null; then if ! type -f bpkg-realpath &>/dev/null; then
echo "error: bpkg-utils not found, aborting" echo "error: bpkg-realpath not found, aborting"
exit 1 exit 1
fi else
# shellcheck disable=SC2230
# shellcheck source=lib/utils/utils.sh # shellcheck source=lib/realpath/realpath.sh
source "$(which bpkg-utils)"
# shellcheck source=lib/realpath/realpath.sh
bpkg_exec_or_exit bpkg-realpath &&
source "$(which bpkg-realpath)" source "$(which bpkg-realpath)"
fi
BPKG_JSON="$(which bpkg-json)" BPKG_JSON="$(which bpkg-json)"

@ -1,82 +1,62 @@
#!/usr/bin/env bash #!/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 if ! type -f bpkg-utils &>/dev/null; then
echo "error: bpkg-utils not found, aborting" echo "error: bpkg-utils not found, aborting"
exit 1 exit 1
else
# shellcheck source=lib/utils/utils.sh
source "$(which bpkg-utils)"
fi fi
# shellcheck source=lib/utils/utils.sh if ! type -f bpkg-env &>/dev/null; then
source "$(which bpkg-utils)" echo "error: bpkg-env not found, aborting"
exit 1
# shellcheck source=lib/realpath/realpath.sh else
bpkg_exec_or_exit bpkg-realpath && # shellcheck disable=SC2230
source "$(which bpkg-realpath)" # shellcheck source=lib/env/env.sh
source "$(which bpkg-env)"
fi
# shellcheck source=lib/install/install.sh if ! type -f bpkg-install &>/dev/null; then
bpkg_exec_or_exit bpkg-install && echo "error: bpkg-install not found, aborting"
exit 1
else
# shellcheck source=lib/install/install.sh
source "$(which bpkg-install)" source "$(which bpkg-install)"
fi
# shellcheck source=lib/package/package.sh if ! type -f bpkg-package &>/dev/null; then
bpkg_exec_or_exit bpkg-package && echo "error: bpkg-package not found, aborting"
exit 1
else
# shellcheck source=lib/package/package.sh
source "$(which bpkg-package)" source "$(which bpkg-package)"
fi
bpkg_initrc bpkg_initrc
## output usage ## output usage
usage () { usage () {
echo 'usage: bpkg-run [-h|--help]' echo 'usage: bpkg-run [-h|--help]'
echo ' or: bpkg-run [-l|--list]' echo ' or: bpkg-run [-h|--help] [command]'
echo ' or: bpkg-run [-s|--source] <package> [command]' echo ' or: bpkg-run [-s|--source] <package> [command]'
echo ' or: bpkg-run [-s|--source] <user>/<package> [command]' echo ' or: bpkg-run [-s|--source] <user>/<package> [command]'
} }
bpkg_list_commands () { runner () {
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" local cmd="$1"
shift shift
# shellcheck disable=SC2068
eval "$cmd" eval "$cmd"
return $? return $?
} }
@ -95,11 +75,6 @@ bpkg_run () {
return 0 return 0
;; ;;
-l|--list)
bpkg_list_commands
return $?
;;
-s|--source) -s|--source)
should_source=1 should_source=1
shift shift
@ -162,7 +137,8 @@ bpkg_run () {
done done
shift shift
bpkg_runner "$prefix ${args[*]}" "$@" # shellcheck disable=SC2068
runner "$prefix ${args[*]}" $@
return $? return $?
fi fi
fi fi
@ -196,9 +172,9 @@ bpkg_run () {
return 1 return 1
fi fi
local pkg_name="$(bpkg_package name 2>/dev/null)" local pkgname="$(bpkg_package name 2>/dev/null)"
if [ -n "$pkg_name" ]; then if [ -n "$pkgname" ]; then
name="$pkg_name" name="$pkgname"
fi fi
if (( 1 == should_emit_source )); then if (( 1 == should_emit_source )); then
@ -242,7 +218,8 @@ bpkg_run () {
done done
shift shift
bpkg_runner "$prefix ${args[*]}" "$@" # shellcheck disable=SC2068
runner "$prefix ${args[*]}" $@
fi fi
# shellcheck disable=SC2068 # shellcheck disable=SC2068

@ -3,10 +3,19 @@
if ! type -f bpkg-utils &>/dev/null; then if ! type -f bpkg-utils &>/dev/null; then
echo "error: bpkg-utils not found, aborting" echo "error: bpkg-utils not found, aborting"
exit 1 exit 1
else
# shellcheck source=lib/utils/utils.sh
source "$(which bpkg-utils)"
fi fi
# shellcheck source=lib/utils/utils.sh if ! type -f bpkg-env &>/dev/null; then
source "$(which bpkg-utils)" echo "error: bpkg-env not found, aborting"
exit 1
else
# shellcheck disable=SC2230
# shellcheck source=lib/env/env.sh
source "$(which bpkg-env)"
fi
bpkg_initrc bpkg_initrc

@ -1,17 +1,12 @@
#!/usr/bin/env bash #!/usr/bin/env bash
if ! type -f bpkg-utils &>/dev/null; then if ! type -f bpkg-run &>/dev/null; then
echo "error: bpkg-utils not found, aborting" echo "error: bpkg-run not found, aborting"
exit 1 exit 1
fi else
# shellcheck source=lib/run/run.sh
# 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)" source "$(which bpkg-run)"
fi
bpkg_source () { bpkg_source () {
# shellcheck disable=SC2068 # shellcheck disable=SC2068

@ -3,11 +3,12 @@
if ! type -f bpkg-utils &>/dev/null; then if ! type -f bpkg-utils &>/dev/null; then
echo "error: bpkg-utils not found, aborting" echo "error: bpkg-utils not found, aborting"
exit 1 exit 1
else
# shellcheck disable=SC2230
# shellcheck source=lib/utils/utils.sh
source "$(which bpkg-utils)"
fi fi
# shellcheck source=lib/utils/utils.sh
source "$(which bpkg-utils)"
## output usage ## output usage
usage () { usage () {
echo "usage: bpkg-suggest [-h|--help] <query>" echo "usage: bpkg-suggest [-h|--help] <query>"

@ -3,11 +3,11 @@
if ! type -f bpkg-utils &>/dev/null; then if ! type -f bpkg-utils &>/dev/null; then
echo "error: bpkg-utils not found, aborting" echo "error: bpkg-utils not found, aborting"
exit 1 exit 1
else
# shellcheck source=lib/utils/utils.sh
source "$(which bpkg-utils)"
fi fi
# shellcheck source=lib/utils/utils.sh
source "$(which bpkg-utils)"
bpkg_initrc bpkg_initrc
usage () { usage () {

@ -1,12 +1,18 @@
#!/usr/bin/env bash #!/usr/bin/env bash
if [ -z "${BPKG_UTILS}" ]; then if ! type -f bpkg-env &>/dev/null; then
BPKG_UTILS=1 echo "error: bpkg-env not found, aborting"
exit 1
else
# shellcheck disable=SC2230
# shellcheck source=lib/env/env.sh
source "$(which bpkg-env)"
fi
## Collection of shared bpkg functions ## Collection of shared bpkg functions
## Init local config and set environmental defaults ## Init local config and set environmental defaults
bpkg_initrc () { bpkg_initrc() {
local global_config=${BPKG_GLOBAL_CONFIG:-"/etc/bpkgrc"} local global_config=${BPKG_GLOBAL_CONFIG:-"/etc/bpkgrc"}
# shellcheck disable=SC1090 # shellcheck disable=SC1090
[ -f "$global_config" ] && source "$global_config" [ -f "$global_config" ] && source "$global_config"
@ -29,95 +35,77 @@ if [ -z "${BPKG_UTILS}" ]; then
bpkg_validate bpkg_validate
return $? return $?
} }
## check parameter consistency ## check parameter consistency
bpkg_validate () { bpkg_validate () {
if [ ${#BPKG_GIT_REMOTES[@]} -ne ${#BPKG_REMOTES[@]} ]; then 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[@]}")" bpkg_error "$(printf 'BPKG_GIT_REMOTES[%d] differs in size from BPKG_REMOTES[%d] array' "${#BPKG_GIT_REMOTES[@]}" "${#BPKG_REMOTES[@]}")"
return 1 return 1
fi fi
return 0 return 0
} }
## format and output message
## format and output message bpkg_message () {
bpkg_message () { if type -f bpkg-term > /dev/null 2>&1; then
bpkg_exec_exist bpkg-term &&
bpkg-term color "${1}" bpkg-term color "${1}"
shift fi
shift
echo -n " ${1}" echo -n " ${1}"
shift shift
bpkg_exec_exist bpkg-term && if type -f bpkg-term > /dev/null 2>&1; then
bpkg-term reset bpkg-term reset
fi
printf ": " printf ": "
bpkg_exec_exist bpkg-term && { if type -f bpkg-term > /dev/null 2>&1; then
bpkg-term reset bpkg-term reset
bpkg-term bright bpkg-term bright
} fi
printf "%s\n" "${@}" printf "%s\n" "${@}"
bpkg_exec_exist bpkg-term && if type -f bpkg-term > /dev/null 2>&1; then
bpkg-term reset bpkg-term reset
} fi
}
## output error ## output error
bpkg_error () { bpkg_error () {
{ {
bpkg_message "red" "error" "${@}" bpkg_message "red" "error" "${@}"
} >&2 } >&2
} }
## output warning ## output warning
bpkg_warn () { bpkg_warn () {
{ {
bpkg_message "yellow" "warn" "${@}" bpkg_message "yellow" "warn" "${@}"
} >&2 } >&2
} }
## output info ## output info
bpkg_info () { bpkg_info () {
local title="info" local title="info"
if (( "${#}" > 1 )); then if (( "${#}" > 1 )); then
title="${1}" title="${1}"
shift shift
fi fi
bpkg_message "cyan" "${title}" "${@}" bpkg_message "cyan" "${title}" "${@}"
} }
## takes a remote and git-remote and sets the globals:
## check if executable exists in path ## BPKG_REMOTE: raw remote URI
bpkg_exec_exist () { ## BPKG_GIT_REMOTE: git remote for cloning
local exec_name="${1}" ## BPKG_AUTH_GIT_REMOTE: git remote with oauth info embedded,
## BPKG_OAUTH_TOKEN: token for x-oauth-basic
type -f "${exec_name}" > /dev/null 2>&1 ## BPKG_CURL_AUTH_PARAM: auth arguments for raw curl requests
} ## BPKG_REMOTE_INDEX: location of local index for remote
bpkg_select_remote () {
## 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 remote=$1
local git_remote=$2 local git_remote=$2
export BPKG_REMOTE_HOST=$(echo "$git_remote" | sed 's/.*:\/\///' | sed 's/\/$//' | tr '/' '_') export BPKG_REMOTE_HOST=$(echo "$git_remote" | sed 's/.*:\/\///' | sed 's/\/$//' | tr '/' '_')
@ -145,11 +133,11 @@ if [ -z "${BPKG_UTILS}" ]; then
else else
export BPKG_REMOTE="$remote" export BPKG_REMOTE="$remote"
fi fi
} }
## given a user and name, sets BPKG_REMOTE_RAW_PATH using the available ## given a user and name, sets BPKG_REMOTE_RAW_PATH using the available
## BPKG_REMOTE and BPKG_OAUTH_TOKEN details ## BPKG_REMOTE and BPKG_OAUTH_TOKEN details
bpkg_select_raw_path () { bpkg_select_raw_path() {
local user=$1 local user=$1
local name=$2 local name=$2
if [ "$BPKG_OAUTH_TOKEN" == "" ]; then if [ "$BPKG_OAUTH_TOKEN" == "" ]; then
@ -159,27 +147,15 @@ if [ -z "${BPKG_UTILS}" ]; then
Export BPKG_REMOTE_RAW_PATH="$BPKG_REMOTE/$user/$name/raw" Export BPKG_REMOTE_RAW_PATH="$BPKG_REMOTE/$user/$name/raw"
fi fi
return 0 return 0
} }
bpkg_exec_or_exit bpkg-env
# shellcheck disable=SC2230
# shellcheck source=lib/env/env.sh
source "$(which bpkg-env)"
export -f bpkg_initrc
export -f bpkg_validate
export -f bpkg_initrc export -f bpkg_message
export -f bpkg_validate export -f bpkg_warn
export -f bpkg_error
export -f bpkg_info
export -f bpkg_message export -f bpkg_select_remote
export -f bpkg_warn export -f bpkg_select_raw_path
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

@ -1,13 +0,0 @@
#!/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

@ -9,7 +9,7 @@
# " "" # " ""
# bash package manager # bash package manager
VERSION="1.1.4" VERSION="1.1.3"
TAG=${TAG:-$VERSION} TAG=${TAG:-$VERSION}
BRANCH=${BRANCH:-$TAG} BRANCH=${BRANCH:-$TAG}
REMOTE=${REMOTE:-https://github.com/bpkg/bpkg.git} REMOTE=${REMOTE:-https://github.com/bpkg/bpkg.git}
@ -52,12 +52,7 @@ setup () {
rm -rf "$DEST" rm -rf "$DEST"
echo " info: Fetching 'bpkg@$BRANCH'..." echo " info: Fetching 'bpkg@$BRANCH'..."
if ! output=$(git clone --depth=1 --branch "$BRANCH" "$REMOTE" "$DEST" 2>&1); then git clone --depth=1 --branch "$BRANCH" "$REMOTE" "$DEST" > /dev/null 2>&1
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 cd "$DEST" || exit
echo " info: Installing..." echo " info: Installing..."

Loading…
Cancel
Save