2022-03-25 13:35:52 +00:00
|
|
|
#!/usr/bin/env bash
|
2014-06-17 06:31:17 +00:00
|
|
|
#
|
|
|
|
# # #
|
|
|
|
# #mmm mmmm # m mmmm
|
|
|
|
# #" "# #" "# # m" #" "#
|
|
|
|
# # # # # #"# # #
|
|
|
|
# ##m#" ##m#" # "m "#m"#
|
|
|
|
# # m #
|
|
|
|
# " ""
|
|
|
|
# bash package manager
|
2014-05-25 19:32:14 +00:00
|
|
|
|
2022-03-30 13:58:38 +00:00
|
|
|
VERSION="1.0.15"
|
|
|
|
TAG=${TAG:-$VERSION}
|
|
|
|
BRANCH=${BRANCH:-$TAG}
|
2014-05-25 19:32:14 +00:00
|
|
|
REMOTE=${REMOTE:-https://github.com/bpkg/bpkg.git}
|
|
|
|
TMPDIR=${TMPDIR:-/tmp}
|
2022-03-30 13:58:38 +00:00
|
|
|
DEST=${DEST:-$TMPDIR/bpkg-$BRANCH}
|
2014-05-25 19:32:14 +00:00
|
|
|
|
|
|
|
## test if command exists
|
|
|
|
ftest () {
|
2022-03-30 13:58:38 +00:00
|
|
|
echo " info: Checking for $1..."
|
|
|
|
if ! type -f "$1" > /dev/null 2>&1; then
|
2014-05-25 19:32:14 +00:00
|
|
|
return 1
|
|
|
|
else
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
## feature tests
|
|
|
|
features () {
|
|
|
|
for f in "${@}"; do
|
2022-03-30 13:58:38 +00:00
|
|
|
ftest "$f" || {
|
|
|
|
echo >&2 " error: Missing \`$f'! Make sure it exists and try again."
|
2014-05-25 19:32:14 +00:00
|
|
|
return 1
|
|
|
|
}
|
|
|
|
done
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
## main setup
|
|
|
|
setup () {
|
2014-06-17 06:31:17 +00:00
|
|
|
echo " info: Welcome to the 'bpkg' installer!"
|
2014-05-25 19:32:14 +00:00
|
|
|
## test for require features
|
2014-05-25 20:34:13 +00:00
|
|
|
features git || return $?
|
2014-05-25 19:32:14 +00:00
|
|
|
|
2014-05-25 19:35:44 +00:00
|
|
|
## build
|
|
|
|
{
|
2014-05-25 19:32:14 +00:00
|
|
|
echo
|
2014-06-17 06:31:17 +00:00
|
|
|
echo " info: Creating temporary files..."
|
2022-03-30 13:58:38 +00:00
|
|
|
cd "$TMPDIR" || exit
|
|
|
|
test -d "$DEST" && { echo " warn: Already exists: '$DEST'"; }
|
|
|
|
rm -rf "$DEST"
|
|
|
|
|
|
|
|
echo " info: Fetching 'bpkg@$BRANCH'..."
|
|
|
|
git clone --depth=1 --branch "$BRANCH" "$REMOTE" "$DEST" > /dev/null 2>&1
|
|
|
|
cd "$DEST" || exit
|
|
|
|
|
2014-06-17 06:31:17 +00:00
|
|
|
echo " info: Installing..."
|
2014-05-25 19:32:14 +00:00
|
|
|
echo
|
2015-06-25 13:15:14 +00:00
|
|
|
make_install
|
2014-09-23 00:04:40 +00:00
|
|
|
echo " info: Done!"
|
2014-05-25 19:35:44 +00:00
|
|
|
} >&2
|
2014-05-25 19:32:14 +00:00
|
|
|
return $?
|
|
|
|
}
|
|
|
|
|
2015-06-25 13:15:14 +00:00
|
|
|
## make targets
|
|
|
|
BIN="bpkg"
|
2019-12-05 13:25:19 +00:00
|
|
|
if [ -z "$PREFIX" ]; then
|
2020-01-15 20:28:32 +00:00
|
|
|
if [ "$USER" == "root" ]; then
|
2019-12-05 13:25:19 +00:00
|
|
|
PREFIX="/usr/local"
|
|
|
|
else
|
|
|
|
PREFIX="$HOME/.local"
|
|
|
|
fi
|
|
|
|
fi
|
2015-06-25 13:15:14 +00:00
|
|
|
|
|
|
|
# All 'bpkg' supported commands
|
2022-03-25 13:44:55 +00:00
|
|
|
declare -a CMDS=()
|
|
|
|
CMDS+=("env")
|
|
|
|
CMDS+=("getdeps")
|
|
|
|
CMDS+=("init")
|
|
|
|
CMDS+=("install")
|
|
|
|
CMDS+=("json")
|
|
|
|
CMDS+=("list")
|
|
|
|
CMDS+=("package")
|
|
|
|
CMDS+=("run")
|
|
|
|
CMDS+=("show")
|
|
|
|
CMDS+=("source")
|
|
|
|
CMDS+=("suggest")
|
|
|
|
CMDS+=("term")
|
|
|
|
CMDS+=("update")
|
|
|
|
CMDS+=("utils")
|
2015-06-25 13:15:14 +00:00
|
|
|
|
|
|
|
make_install () {
|
2021-01-10 09:47:12 +00:00
|
|
|
local source
|
|
|
|
|
2022-03-23 18:11:02 +00:00
|
|
|
## do 'make uninstall'
|
2015-06-25 13:15:14 +00:00
|
|
|
make_uninstall
|
2022-03-23 18:11:02 +00:00
|
|
|
|
2015-06-25 13:15:14 +00:00
|
|
|
echo " info: Installing $PREFIX/bin/$BIN..."
|
2015-06-25 13:39:39 +00:00
|
|
|
install -d "$PREFIX/bin"
|
2021-01-10 09:47:12 +00:00
|
|
|
source=$(<$BIN)
|
2022-03-23 18:11:02 +00:00
|
|
|
|
|
|
|
if [ -f "$source" ]; then
|
|
|
|
install "$source" "$PREFIX/bin/$BIN"
|
|
|
|
else
|
|
|
|
install "$BIN" "$PREFIX/bin"
|
|
|
|
fi
|
|
|
|
|
2022-03-25 13:44:55 +00:00
|
|
|
for cmd in "${CMDS[@]}"; do
|
2021-01-09 20:51:01 +00:00
|
|
|
source=$(<"$BIN-$cmd")
|
2022-03-23 18:11:02 +00:00
|
|
|
|
|
|
|
if [ -f "$source" ]; then
|
|
|
|
install "$source" "$PREFIX/bin/$BIN-$cmd"
|
|
|
|
else
|
|
|
|
install "$BIN-$cmd" "$PREFIX/bin"
|
|
|
|
fi
|
|
|
|
|
2015-06-25 13:15:14 +00:00
|
|
|
done
|
|
|
|
return $?
|
|
|
|
}
|
|
|
|
|
|
|
|
make_uninstall () {
|
2022-03-28 22:07:04 +00:00
|
|
|
echo " info: Uninstalling $PREFIX/bin/$BIN*"
|
|
|
|
echo " rm: $PREFIX/bin/$BIN'"
|
2015-06-25 13:15:14 +00:00
|
|
|
rm -f "$PREFIX/bin/$BIN"
|
2022-03-25 13:44:55 +00:00
|
|
|
for cmd in "${CMDS[@]}"; do
|
2022-03-28 22:07:04 +00:00
|
|
|
echo " rm: $PREFIX/bin/$BIN-$cmd'"
|
2015-06-25 13:15:14 +00:00
|
|
|
rm -f "$PREFIX/bin/$BIN-$cmd"
|
|
|
|
done
|
|
|
|
return $?
|
|
|
|
}
|
|
|
|
|
|
|
|
make_link () {
|
|
|
|
make_uninstall
|
2022-03-28 22:07:04 +00:00
|
|
|
echo " info: Linking $PREFIX/bin/$BIN*"
|
|
|
|
echo " link: '$PWD/$BIN' -> '$PREFIX/bin/$BIN'"
|
2015-06-25 13:35:50 +00:00
|
|
|
ln -s "$PWD/$BIN" "$PREFIX/bin/$BIN"
|
2022-03-25 13:44:55 +00:00
|
|
|
for cmd in "${CMDS[@]}"; do
|
2022-03-28 22:07:04 +00:00
|
|
|
echo " link: '$PWD/$BIN-$cmd' -> '$PREFIX/bin/$BIN-$cmd'"
|
|
|
|
ln -s "$PWD/$BIN-$cmd" "$PREFIX/bin/$BIN-$cmd"
|
2015-06-25 13:15:14 +00:00
|
|
|
done
|
|
|
|
return $?
|
|
|
|
}
|
|
|
|
|
|
|
|
make_unlink () {
|
|
|
|
make_uninstall
|
|
|
|
}
|
|
|
|
|
2022-03-23 18:11:02 +00:00
|
|
|
## do setup or `make_{install|uninstall|link|unlink}` command
|
|
|
|
if [ $# -eq 0 ]; then
|
|
|
|
setup
|
|
|
|
else
|
|
|
|
"make_$1"
|
|
|
|
fi
|
|
|
|
|
2014-05-25 19:32:14 +00:00
|
|
|
exit $?
|