sourcezap/bin/sourcezap
2024-07-19 19:40:13 -03:00

73 lines
2 KiB
Bash
Executable file

#!/bin/sh
set -e
##
# variables
localbase=${LOCALBASE:-$(realpath "$(dirname "$0")"/..)}
libexec="${localbase}"/libexec/sourcezap
defaultbranch="hardened/14-stable/master"
gitdir="/home/_sourcezap/src"
giturl="${SOURCEZAP_CLONEURL:-https://git.hardenedbsd.org/hardenedbsd/HardenedBSD.git}"
installdir="${SOURCEZAP_INSTALLDIR:-/usr/src}"
revision="${installdir}"/.sourcezap
##
# functions
. "${libexec}"/functions/print.sh
require_dependency()
{
deps=$1
for dep in $deps; do
if ! which -s "$dep"; then
printerr "${dep} wasn't found on \$PATH"
exit 1
fi
done
}
##
# main
i=1
while [ "${i}" -le "$#" ]; do
eval "_sourcezap_option=\$${i}"
# shellcheck disable=SC2154
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"
"${libexec}"/commands/sourcezap-clone "${giturl}" "${gitdir}" "${defaultbranch}"
;;
"pull")
require_dependency "git doas"
"${libexec}"/commands/sourcezap-pull "${gitdir}"
;;
"checkout")
require_dependency "git doas"
"${libexec}"/commands/sourcezap-checkout "${gitdir}" "${2}"
;;
"rm")
"${libexec}"/commands/sourcezap-rm "${gitdir}" "${installdir}"
;;
"install")
require_dependency "git doas"
"${libexec}"/commands/sourcezap-install "${gitdir}" "${installdir}" "${revision}"
;;
*)
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"
printf " checkout Checkout a branch other than the default\n"
printf " install Install the source tree into /usr/src/\n"
printf " rm Remove /usr/src/ and /home/_sourcezap/src/\n"
;;
esac