feat(): introduce 'bpkg-run'

pull/143/head
jwerle 2 years ago committed by Joseph Werle
parent c9ef8595ec
commit 9ea0f02b76

@ -2,3 +2,5 @@
disable=SC2034
## Allow declare and assign separately to avoid masking return values
disable=SC2155
## Double quote array expansions to avoid re-splitting elements.
disable=SC2068

@ -130,6 +130,10 @@ You can install a packages dependencies with the `bpkg getdeps` command. These w
_Note: There is no protection against circular dependencies, so be careful!_
### Running packages with `bpkg`
You can run a package script with `bpkg run` which will install your
package globally and execute it as a command
### Retrieving package info
@ -242,7 +246,6 @@ This is a hash of dependencies. The keys are the package names, and the values a
}
```
## Packaging best practices
These are guidelines that we strongly encourage developers to follow.
@ -295,15 +298,12 @@ Support this project by becoming a sponsor. Your logo will show up here with a l
This project exists thanks to all the people who contribute. [[Contribute](CONTRIBUTING.md)].
<a href="graphs/contributors"><img src="https://opencollective.com/bpkg/contributors.svg?width=890&button=false" /></a>
### Backers
Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/bpkg#backer)]
<a href="https://opencollective.com/bpkg#backers" target="_blank"><img src="https://opencollective.com/bpkg/backers.svg?width=890"></a>
## License
`bpkg` is released under the **MIT license**.

@ -0,0 +1 @@
lib/run/run.sh

@ -13,6 +13,8 @@ fi
BPKG_USER="${BPKG_USER:-bpkg}"
BPKG_DEPS="${BPKG_DEPS:-deps}"
let prevent_prune=0
## check parameter consistency
validate_parameters () {
if [[ ${#BPKG_GIT_REMOTES[@]} -ne ${#BPKG_REMOTES[@]} ]]; then
@ -175,6 +177,10 @@ bpkg_install () {
shift
needs_global=1
;;
--no-prune)
shift
prevent_prune=1
;;
*)
if [[ '-' = "${opt:0:1}" ]]; then
@ -410,10 +416,10 @@ bpkg_install_from_remote () {
## go to tmp dir
cd "$([[ -n "$TMPDIR" ]] && echo "$TMPDIR" || echo /tmp)" &&
## prune existing
rm -rf "$name-$version" &&
( (( 0 == prevent_prune )) && rm -rf "$name-$version" || true) &&
## shallow clone
info "Cloning $repo_url to $name-$version"
info "Cloning $repo_url to $(pwd)/$name-$version"
git clone "$repo_url" "$name-$version" && (
## move into directory
cd "$name-$version" && (
@ -432,7 +438,9 @@ bpkg_install_from_remote () {
)
## clean up
rm -rf "$name-$version"
if (( 0 == prevent_prune )); then
rm -rf "$name-$version"
fi
)}
## perform local install otherwise
else

@ -1,5 +1,13 @@
#!/bin/bash
BPKG_JSON="$(which bpkg-json)"
if [ -z "$BPKG_JSON" ]; then
BPKG_JSON="$(realpath "$0/../JSON/JSON.sh")"
else
BPKG_JSON="$(realpath "$BPKG_JSON")"
fi
## output usage
usage () {
echo "usage: bpkg-package [-h|--help]"
@ -30,11 +38,11 @@ bpkg_package () {
if [ -z "$prop" ]; then
## output all propertyies if property
## is ommited
cat "$pkg" | bpkg-json -b
cat "$pkg" | "$BPKG_JSON" -b
else
## show value for a specific property
## in 'bpkg.json' or 'package.json'
cat "$pkg" | bpkg-json -b | grep "$prop" | awk '{ $1=""; printf $0 }' | tr -d '"'
cat "$pkg" | "$BPKG_JSON" -b | grep "$prop" | awk '{ $1=""; printf $0 }' | tr -d '"' | sed 's/^ *//;s/ *$//'
echo
fi
@ -46,9 +54,13 @@ bpkg_package () {
return 1
}
if [[ ${BASH_SOURCE[0]} != "$0" ]]; then
export -f bpkg_package
if [ -z "$BPKG_JSON" ]; then
echo 1>&2 "error: Failed to load 'bpkg-json'"
else
bpkg_package "${@}"
exit $?
if [[ ${BASH_SOURCE[0]} != "$0" ]]; then
export -f bpkg_package
else
bpkg_package "${@}"
exit $?
fi
fi

@ -0,0 +1,106 @@
#!/bin/bash
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-install &>/dev/null; then
echo "error: bpkg-install not found, aborting"
exit 1
else
# shellcheck disable=SC2230
# shellcheck source=lib/install/install.sh
source "$(which bpkg-install)"
fi
if ! type -f bpkg-package &>/dev/null; then
echo "error: bpkg-package not found, aborting"
exit 1
else
# shellcheck disable=SC2230
# shellcheck source=lib/package/package.sh
source "$(which bpkg-package)"
fi
bpkg_initrc
## outut usage
usage () {
echo 'usage: bpkg-run [-h|--help]'
echo ' or: bpkg-run [-s|--source] <package>'
echo ' or: bpkg-run [-s|--source] <user>/<package>'
}
bpkg_run () {
pushd . >/dev/null || return $?
local ignore_args=0
local needs_name=0
local package=''
local name=''
for opt in "$@"; do
case "$opt" in
-h|--help)
if (( 0 == ignore_args )); then
usage
return 0
fi
;;
-s|--source)
if (( 0 == ignore_args )); then
# shellcheck disable=SC1090
source "$(which "$name")"
return $?
fi
;;
-t|--target|--name)
if (( 0 == ignore_args )); then
shift
needs_name=1
fi
;;
*)
ignore_args=1
if (( 1 == needs_name )); then
name="$opt"
shift
needs_name=0
fi
;;
esac
done
local dest=$(bpkg_install --no-prune -g "$1" 2>/dev/null | grep 'info: Cloning' | sed 's/.* to //g' | xargs echo)
if [ -z "$dest" ]; then return $?; fi
cd "$dest" || return $?
if [ -z "$name" ]; then
name="$(bpkg_package name)"
fi
shift
popd >/dev/null || return $?
eval "$(which "$name")" $@
return $?
}
## Use as lib or perform install
if [[ ${BASH_SOURCE[0]} != "$0" ]]; then
export -f bpkg_run
elif validate_parameters; then
bpkg_run "$@"
exit $?
else
#param validation failed
exit $?
fi

@ -43,13 +43,13 @@ setup () {
## build
{
echo
cd "${TMPDIR}"
cd "${TMPDIR}" || exit
echo " info: Creating temporary files..."
test -d "${DEST}" && { echo " warn: Already exists: '${DEST}'"; }
rm -rf "${DEST}"
echo " info: Fetching latest 'bpkg'..."
git clone --depth=1 "${REMOTE}" "${DEST}" > /dev/null 2>&1
cd "${DEST}"
cd "${DEST}" || exit
echo " info: Installing..."
echo
make_install
@ -69,7 +69,7 @@ if [ -z "$PREFIX" ]; then
fi
# All 'bpkg' supported commands
CMDS="json install package term suggest init utils update list show getdeps"
CMDS="json install package term suggest init utils update list show getdeps run"
make_install () {
local source

Loading…
Cancel
Save