Compare commits

..

1 Commits

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

@ -8,34 +8,29 @@ You can install shell scripts globally (on `${PREFIX:-/usr/local/bin}`) or use t
<!-- BEGIN-MARKDOWN-TOC -->
* [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)
* [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)
* [dependencies-dev (optional)](#dependencies-dev-optional)
* [commands (optional)](#commands-optional)
* [commands-description (optional)](#commands-description-optional)
* [name](#name)
* [version (optional)](#version-optional)
* [description](#description)
* [global](#global)
* [install](#install-1)
* [scripts](#scripts)
* [files](#files)
* [dependencies (optional)](#dependencies-optional)
* [Packaging best practices](#packaging-best-practices)
* [Package exports](#package-exports)
* [Package exports](#package-exports)
* [Sponsors](#sponsors)
* [Contributors](#contributors)
* [Backers](#backers)
* [License](#license)
<!-- END-MARKDOWN-TOC -->
## Install
@ -245,9 +240,9 @@ This is an array of scripts that will be installed into a project.
"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
"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
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
[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

@ -1,6 +1,6 @@
{
"name": "bpkg",
"version": "1.1.4",
"version": "1.1.3",
"description": "Lightweight bash package manager",
"global": true,
"repo": "bpkg/bpkg",
@ -8,9 +8,5 @@
"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"
}
}

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

@ -1,12 +1,9 @@
#!/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"
}
@ -21,11 +18,6 @@ bpkg_getdeps () {
usage
return 0
;;
-d|--dev)
shift
install_dev=1
;;
esac
## ensure there is a package to read
@ -38,17 +30,10 @@ 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
(

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

@ -8,36 +8,18 @@ throw () {
BRIEF=0
LEAFONLY=0
PRUNE=0
FILTER=
usage() {
echo
echo "Usage: JSON.sh [-b] [-l] [-p] [-f=<filter>] [-h]"
echo "Usage: JSON.sh [-b] [-l] [-p] [-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=$#
@ -55,8 +37,6 @@ parse_options() {
;;
-p) PRUNE=1
;;
-f=*) FILTER=${1#-f=}
;;
?*) echo "ERROR: Unknown option."
usage
exit 0
@ -146,7 +126,7 @@ parse_object () {
while :
do
case "$token" in
'"'*'"') escape_string "$token"; key=$REPLY ;;
'"'*'"') key=$token ;;
*) throw "EXPECTED string GOT ${token:-EOF}" ;;
esac
read -r token
@ -178,7 +158,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}" ;;
*) escape_string "$token"; value=$REPLY
*) value=$token
isleaf=1
[ "$value" = '""' ] && isempty=1
;;
@ -189,17 +169,8 @@ 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
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
[ "$print" -eq 1 ] && printf "[%s]\t%s\n" "$jpath" "$value"
:
}
parse () {

@ -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 () {

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

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

@ -3,10 +3,19 @@
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)"
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
bpkg_initrc

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

@ -3,11 +3,12 @@
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] <query>"

@ -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 () {

@ -1,185 +1,161 @@
#!/usr/bin/env bash
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
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
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
echo -n " ${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
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}"
shift
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"
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]}
# 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]}
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_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"
export BPKG_AUTH_GIT_REMOTE=${git_remote/https:\/\//https:\/\/$BPKG_OAUTH_TOKEN:x-oauth-basic@}
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
}
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
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
}
export -f bpkg_message
export -f bpkg_warn
export -f bpkg_error
export -f bpkg_info
export -f bpkg_initrc
export -f bpkg_validate
export -f bpkg_exec_exist
export -f bpkg_exec_or_exit
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
fi
export -f bpkg_select_remote
export -f bpkg_select_raw_path

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

Loading…
Cancel
Save