2016-01-30 20:47:10 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
## output usage
|
|
|
|
usage () {
|
|
|
|
echo "Installs dependencies for a package."
|
|
|
|
echo "usage: bpkg-getdeps [-h|--help]"
|
|
|
|
echo " or: bpkg-getdeps"
|
|
|
|
}
|
|
|
|
|
|
|
|
## Read a package property
|
|
|
|
bpkg_getdeps () {
|
2021-01-10 09:47:12 +00:00
|
|
|
local cwd pkg
|
|
|
|
|
|
|
|
cwd="$(pwd)"
|
2021-01-03 20:24:17 +00:00
|
|
|
pkg="${cwd}/bpkg.json"
|
2021-01-10 09:47:12 +00:00
|
|
|
|
2021-01-03 20:24:17 +00:00
|
|
|
if ! test -f "${pkg}"; then
|
|
|
|
pkg="${cwd}/package.json"
|
|
|
|
fi
|
2016-01-30 20:47:10 +00:00
|
|
|
|
2021-01-10 09:47:12 +00:00
|
|
|
|
2016-01-30 20:47:10 +00:00
|
|
|
## parse flags
|
|
|
|
case "$1" in
|
|
|
|
-h|--help)
|
|
|
|
usage
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
## ensure there is a package to read
|
|
|
|
if ! test -f "${pkg}"; then
|
2021-01-03 20:24:17 +00:00
|
|
|
echo 2>&1 "error: Unable to find 'bpkg.json' or 'package.json' in $(pwd)"
|
2016-01-30 20:47:10 +00:00
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
dependencies=$(cat "${pkg}" | bpkg-json -b | grep '\[\"dependencies' | sed "s/\[\"dependencies\",//" | sed "s/\"\]$(printf '\t')\"/@/" | tr -d '"')
|
|
|
|
dependencies=($(echo ${dependencies[@]}))
|
|
|
|
|
|
|
|
## run bpkg install for each dependency
|
|
|
|
for (( i = 0; i < ${#dependencies[@]} ; ++i )); do
|
|
|
|
(
|
|
|
|
local package=${dependencies[$i]}
|
2021-01-09 20:51:01 +00:00
|
|
|
bpkg install "${package}"
|
2016-01-30 20:47:10 +00:00
|
|
|
)
|
|
|
|
done
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2021-01-09 19:15:19 +00:00
|
|
|
if [[ ${BASH_SOURCE[0]} != "$0" ]]; then
|
2016-01-30 20:47:10 +00:00
|
|
|
export -f bpkg_getdeps
|
|
|
|
else
|
|
|
|
bpkg_getdeps "${@}"
|
|
|
|
exit $?
|
|
|
|
fi
|