90 lines
2.5 KiB
Bash
Executable file
90 lines
2.5 KiB
Bash
Executable file
#!/bin/sh
|
|
set -e
|
|
|
|
##
|
|
# variables
|
|
localbase=${LOCALBASE:-$(realpath "$(dirname "$0")"/..)}
|
|
libexec="${localbase}"/libexec/portzap
|
|
gitdir="/home/_portzap/ports"
|
|
giturl="${PORTZAP_CLONEURL:-https://git.hardenedbsd.org/hardenedbsd/ports.git}"
|
|
installdir="${PORTZAP_INSTALLDIR:-/usr/ports}"
|
|
defaultbranch="hardenedbsd/main"
|
|
revfile="${installdir}"/.portzap
|
|
|
|
##
|
|
# functions
|
|
# shellcheck source=/dev/null
|
|
. "${libexec}"/functions/print.sh
|
|
|
|
require_dependency()
|
|
{
|
|
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 "_portzap_option=\$${i}"
|
|
# shellcheck disable=SC2154
|
|
if [ "${_portzap_option}" = "-v" ]; then
|
|
cat "${localbase}"/share/portzap/VERSION
|
|
exit 0
|
|
fi
|
|
# shellcheck disable=SC2003
|
|
i=$(expr "${i}" + 1);
|
|
done
|
|
|
|
case $1 in
|
|
"setup")
|
|
"${libexec}"/commands/portzap-setup
|
|
;;
|
|
"teardown")
|
|
"${libexec}"/commands/portzap-teardown
|
|
;;
|
|
"clone")
|
|
require_dependency git doas
|
|
"${libexec}"/commands/portzap-clone "${giturl}" "${gitdir}" "${defaultbranch}"
|
|
;;
|
|
"pull")
|
|
require_dependency git doas
|
|
"${libexec}"/commands/portzap-pull "${gitdir}"
|
|
;;
|
|
"checkout")
|
|
require_dependency git doas
|
|
"${libexec}"/commands/portzap-checkout "${gitdir}" "${2}"
|
|
;;
|
|
"sh")
|
|
require_dependency doas
|
|
"${libexec}"/commands/portzap-sh "${gitdir}"
|
|
;;
|
|
"rm")
|
|
"${libexec}"/commands/portzap-rm "${gitdir}" "${installdir}"
|
|
;;
|
|
"install")
|
|
require_dependency git doas
|
|
"${libexec}"/commands/portzap-install "${gitdir}" "${installdir}" "${revfile}"
|
|
;;
|
|
*)
|
|
printf "Usage: portzap COMMAND [OPTIONS]\n"
|
|
printf "\n"
|
|
printf "Setup\n"
|
|
printf " setup Setup portzap for the first time\n"
|
|
printf " teardown Reverse the changes made by 'portzap setup'\n"
|
|
printf "\n"
|
|
printf "General\n"
|
|
printf " clone Clone the hardenedbsd ports tree\n"
|
|
printf " pull Pull updates from the hardenedbsd ports tree\n"
|
|
printf " checkout Checkout a branch other than the default\n"
|
|
printf " sh Run /bin/sh within /home/_portzap/ports/\n"
|
|
printf " rm Remove /usr/ports/ and /home/_portzap/ports/\n"
|
|
printf " install Install the ports tree into /usr/ports/\n"
|
|
;;
|
|
esac
|