2
0
mirror of https://github.com/bpkg/bpkg synced 2024-11-11 13:10:52 +00:00
bpkg/setup.sh

134 lines
2.5 KiB
Bash
Raw Normal View History

2014-05-25 19:32:14 +00:00
#!/bin/bash
#
# # #
# #mmm mmmm # m mmmm
# #" "# #" "# # m" #" "#
# # # # # #"# # #
# ##m#" ##m#" # "m "#m"#
# # m #
# " ""
# bash package manager
2014-05-25 19:32:14 +00:00
REMOTE=${REMOTE:-https://github.com/bpkg/bpkg.git}
TMPDIR=${TMPDIR:-/tmp}
DEST=${DEST:-${TMPDIR}/bpkg-master}
## test if command exists
ftest () {
echo " info: Checking for ${1}..."
2014-05-25 19:35:44 +00:00
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
2014-05-25 20:34:13 +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 () {
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
2022-03-18 18:27:22 +00:00
cd "${TMPDIR}" || exit
echo " info: Creating temporary files..."
2014-10-19 19:47:29 +00:00
test -d "${DEST}" && { echo " warn: Already exists: '${DEST}'"; }
rm -rf "${DEST}"
echo " info: Fetching latest 'bpkg'..."
2014-10-19 19:47:29 +00:00
git clone --depth=1 "${REMOTE}" "${DEST}" > /dev/null 2>&1
2022-03-18 18:27:22 +00:00
cd "${DEST}" || exit
echo " info: Installing..."
2014-05-25 19:32:14 +00:00
echo
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 $?
}
## make targets
BIN="bpkg"
if [ -z "$PREFIX" ]; then
if [ "$USER" == "root" ]; then
PREFIX="/usr/local"
else
PREFIX="$HOME/.local"
fi
fi
# All 'bpkg' supported commands
2022-03-24 17:04:16 +00:00
CMDS="json install package term suggest init utils update list show getdeps run source env"
make_install () {
2021-01-10 09:47:12 +00:00
local source
## do 'make uninstall'
make_uninstall
echo " info: Installing $PREFIX/bin/$BIN..."
install -d "$PREFIX/bin"
2021-01-10 09:47:12 +00:00
source=$(<$BIN)
if [ -f "$source" ]; then
install "$source" "$PREFIX/bin/$BIN"
else
install "$BIN" "$PREFIX/bin"
fi
for cmd in $CMDS; do
2021-01-09 20:51:01 +00:00
source=$(<"$BIN-$cmd")
if [ -f "$source" ]; then
install "$source" "$PREFIX/bin/$BIN-$cmd"
else
install "$BIN-$cmd" "$PREFIX/bin"
fi
done
return $?
}
make_uninstall () {
echo " info: Uninstalling $PREFIX/bin/$BIN..."
rm -f "$PREFIX/bin/$BIN"
for cmd in $CMDS; do
rm -f "$PREFIX/bin/$BIN-$cmd"
done
return $?
}
make_link () {
make_uninstall
echo " info: Linking $PREFIX/bin/$BIN..."
ln -s "$PWD/$BIN" "$PREFIX/bin/$BIN"
for cmd in $CMDS; do
ln -s "$PWD/$BIN-$cmd" "$PREFIX/bin"
done
return $?
}
make_unlink () {
make_uninstall
}
## 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 $?