73 lines
2 KiB
Bash
Executable file
73 lines
2 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
|
|
. "${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 "_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
|
|
"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}"
|
|
;;
|
|
"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 "Commands:\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 " rm Remove /usr/ports/ and /home/_portzap/ports/\n"
|
|
printf " install Install the ports tree into /usr/ports/\n"
|
|
;;
|
|
esac
|