portzap/bin/portzap
0x1eef dbd97d9562 Add 'portzap checkout'
A copy of the same sourcezap command ('sourcezap checkout')
2024-05-21 22:25:37 -03:00

70 lines
1.9 KiB
Bash
Executable file

#!/bin/sh
set -e
##
# variables
localbase="${LOCALBASE:-/usr/local}"
defaultbranch="hardenedbsd/main"
gitdir="/home/_portzap/ports"
giturl="${PORTZAP_GITURL:-https://git.hardenedbsd.org/hardenedbsd/ports.git}"
installdir="${PORTZAP_INSTALLDIR:-/usr/ports}"
revision="${installdir}"/.portzap
libexec="${localbase}"/libexec/portzap
##
# functions
require_dependency() {
deps=$1
for dep in $deps; do
if ! which -s "$dep"; then
echo "[x] This command requires ${dep}, but ${dep} wasn't found"
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}"/portzap-clone "${giturl}" "${gitdir}" "${defaultbranch}"
;;
"pull")
require_dependency "git doas"
"${libexec}"/portzap-pull "${gitdir}"
;;
"checkout")
require_dependency "git doas"
"${libexec}"/portzap-checkout "${gitdir}" "${2}"
;;
"rm")
"${libexec}"/portzap-rm "${gitdir}" "${installdir}"
;;
"install")
require_dependency "git doas"
"${libexec}"/portzap-install "${gitdir}" "${installdir}" "${revision}"
;;
*)
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