portzap/bin/portzap
0x1eef e5975b2b67
Some checks are pending
portzap / shellcheck (push) Waiting to run
Default to a "stable" clone URL
2024-09-10 21:56:35 -03:00

91 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://github.com/hardenedbsd/ports}"
installdir="${PORTZAP_INSTALLDIR:-/usr/ports}"
defaultbranch="hardenedbsd/main"
commitfile="${installdir}"/.portzap
##
# 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 "_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}" "${commitfile}"
;;
*)
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 ports tree updates\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