91 lines
2.6 KiB
Bash
Executable file
91 lines
2.6 KiB
Bash
Executable file
#!/bin/sh
|
|
set -e
|
|
|
|
##
|
|
# variables
|
|
localbase=${LOCALBASE:-$(realpath "$(dirname "$0")"/..)}
|
|
libexec="${localbase}"/libexec/sourcezap
|
|
repodir="/home/_sourcezap/src"
|
|
repourl="${SOURCEZAP_CLONEURL:-https://git.hardenedbsd.org/hardenedbsd/hardenedbsd.git}"
|
|
installdir="${SOURCEZAP_INSTALLDIR:-/usr/src}"
|
|
defaultbranch="hardenedbsd/main"
|
|
commitfile="${installdir}"/.sourcezap
|
|
|
|
##
|
|
# functions
|
|
# shellcheck source=/dev/null
|
|
. "${libexec}"/functions/print.sh
|
|
|
|
require_dependency()
|
|
{
|
|
# shellcheck disable=SC3043
|
|
local dep
|
|
for i in $(seq 1 ${#}); do
|
|
eval "dep=\$${i}"
|
|
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
|
|
"setup")
|
|
"${libexec}"/commands/sourcezap-setup
|
|
;;
|
|
"teardown")
|
|
"${libexec}"/commands/sourcezap-teardown
|
|
;;
|
|
"clone")
|
|
require_dependency git doas
|
|
"${libexec}"/commands/sourcezap-clone "${repourl}" "${repodir}" "${defaultbranch}"
|
|
;;
|
|
"pull")
|
|
require_dependency git doas
|
|
"${libexec}"/commands/sourcezap-pull "${repodir}"
|
|
;;
|
|
"checkout")
|
|
require_dependency git doas
|
|
"${libexec}"/commands/sourcezap-checkout "${repodir}" "${2}"
|
|
;;
|
|
"sh")
|
|
require_dependency doas
|
|
"${libexec}"/commands/sourcezap-sh "${repodir}"
|
|
;;
|
|
"rm")
|
|
"${libexec}"/commands/sourcezap-rm "${repodir}" "${installdir}"
|
|
;;
|
|
"install")
|
|
require_dependency git doas
|
|
"${libexec}"/commands/sourcezap-install "${repodir}" "${installdir}" "${commitfile}"
|
|
;;
|
|
*)
|
|
printf "Usage: sourcezap COMMAND [OPTIONS]\n"
|
|
printf "\n"
|
|
printf "Setup\n"
|
|
printf " setup Setup sourcezap for the first time\n"
|
|
printf " teardown Reverse the changes made by 'sourcezap setup'\n"
|
|
printf "\n"
|
|
printf "General\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 " sh Run /bin/sh within /home/_sourcezap/src/\n"
|
|
printf " rm Remove /usr/src/ and /home/_sourcezap/src/\n"
|
|
printf " install Install the source tree into /usr/src/\n"
|
|
;;
|
|
esac
|