sourcezap/bin/sourcezap

80 lines
2.2 KiB
Text
Raw Normal View History

2024-05-11 21:43:59 +02:00
#!/bin/sh
set -e
##
# variables
2024-06-01 05:50:47 +02:00
localbase=${LOCALBASE:-$(realpath "$(dirname "$0")"/..)}
libexec="${localbase}"/libexec/sourcezap
defaultbranch="hardened/14-stable/master"
2024-05-12 01:19:45 +02:00
gitdir="/home/_sourcezap/src"
giturl="${SOURCEZAP_CLONEURL:-https://git.hardenedbsd.org/hardenedbsd/HardenedBSD.git}"
2024-05-12 01:51:33 +02:00
installdir="${SOURCEZAP_INSTALLDIR:-/usr/src}"
2024-05-12 01:19:45 +02:00
revision="${installdir}"/.sourcezap
##
# functions
# shellcheck source=/dev/null
2024-07-20 00:40:13 +02:00
. "${libexec}"/functions/print.sh
2024-06-01 05:50:47 +02:00
require_dependency()
{
deps=$1
for dep in $deps; do
if ! which -s "$dep"; then
2024-06-01 05:50:47 +02:00
printerr "${dep} wasn't found on \$PATH"
exit 1
fi
done
}
##
# main
i=1
while [ "${i}" -le "$#" ]; do
2024-05-12 01:19:45 +02:00
eval "_sourcezap_option=\$${i}"
# shellcheck disable=SC2154
2024-05-12 01:19:45 +02:00
if [ "${_sourcezap_option}" = "-v" ]; then
cat "${localbase}"/share/sourcezap/VERSION
exit 0
fi
# shellcheck disable=SC2003
i=$(expr "${i}" + 1);
done
case $1 in
"clone")
require_dependency "git doas"
2024-06-01 05:50:47 +02:00
"${libexec}"/commands/sourcezap-clone "${giturl}" "${gitdir}" "${defaultbranch}"
;;
"pull")
require_dependency "git doas"
2024-06-01 05:50:47 +02:00
"${libexec}"/commands/sourcezap-pull "${gitdir}"
;;
2024-05-12 04:32:08 +02:00
"checkout")
require_dependency "git doas"
2024-06-01 05:50:47 +02:00
"${libexec}"/commands/sourcezap-checkout "${gitdir}" "${2}"
;;
2024-08-07 08:45:25 +02:00
"sh")
require_dependency "doas"
"${libexec}"/commands/sourcezap-sh "${gitdir}"
;;
2024-05-12 04:55:58 +02:00
"rm")
2024-06-01 05:50:47 +02:00
"${libexec}"/commands/sourcezap-rm "${gitdir}" "${installdir}"
;;
"install")
require_dependency "git doas"
2024-06-01 05:50:47 +02:00
"${libexec}"/commands/sourcezap-install "${gitdir}" "${installdir}" "${revision}"
;;
*)
2024-05-12 01:19:45 +02:00
printf "Usage: sourcezap COMMAND [OPTIONS]\n"
printf "\n"
printf "Commands:\n"
printf " clone Clone the HardenedBSD source tree\n"
printf " pull Pull source tree updates\n"
2024-05-12 04:32:08 +02:00
printf " checkout Checkout a branch other than the default\n"
2024-08-07 08:45:25 +02:00
printf " sh Run /bin/sh within /home/_sourcezap/src/\n"
2024-05-12 04:55:58 +02:00
printf " rm Remove /usr/src/ and /home/_sourcezap/src/\n"
2024-08-07 08:45:25 +02:00
printf " install Install the source tree into /usr/src/\n"
;;
esac