portzap/bin/portzap

92 lines
2.5 KiB
Text
Raw Normal View History

#!/bin/sh
set -e
##
2024-04-03 17:49:53 +02:00
# variables
2024-05-23 06:03:45 +02:00
localbase=${LOCALBASE:-$(realpath "$(dirname "$0")"/..)}
libexec="${localbase}"/libexec/portzap
2024-04-01 16:02:16 +02:00
gitdir="/home/_portzap/ports"
2024-09-11 02:56:35 +02:00
giturl="${PORTZAP_CLONEURL:-https://github.com/hardenedbsd/ports}"
installdir="${PORTZAP_INSTALLDIR:-/usr/ports}"
2024-05-23 06:03:45 +02:00
defaultbranch="hardenedbsd/main"
2024-08-20 07:17:05 +02:00
commitfile="${installdir}"/.portzap
##
2024-04-03 17:49:53 +02:00
# functions
# shellcheck source=/dev/null
. "${libexec}"/functions/print.sh
require_dependency()
{
# shellcheck disable=SC3043
2024-08-20 05:39:29 +02:00
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}"
2024-04-19 09:45:11 +02:00
# shellcheck disable=SC2154
if [ "${_portzap_option}" = "-v" ]; then
2024-04-19 09:56:39 +02:00
cat "${localbase}"/share/portzap/VERSION
exit 0
fi
2024-04-19 09:45:11 +02:00
# shellcheck disable=SC2003
i=$(expr "${i}" + 1);
done
2023-01-14 18:30:29 +01:00
case $1 in
"setup")
2024-08-17 23:34:39 +02:00
"${libexec}"/commands/portzap-setup
;;
"teardown")
2024-08-17 23:34:39 +02:00
"${libexec}"/commands/portzap-teardown
;;
2023-01-14 18:30:29 +01:00
"clone")
2024-08-20 05:39:29 +02:00
require_dependency git doas
2024-05-23 04:52:41 +02:00
"${libexec}"/commands/portzap-clone "${giturl}" "${gitdir}" "${defaultbranch}"
2023-01-14 18:30:29 +01:00
;;
"pull")
2024-08-20 05:39:29 +02:00
require_dependency git doas
2024-05-23 04:52:41 +02:00
"${libexec}"/commands/portzap-pull "${gitdir}"
;;
"checkout")
2024-08-20 05:39:29 +02:00
require_dependency git doas
2024-05-23 04:52:41 +02:00
"${libexec}"/commands/portzap-checkout "${gitdir}" "${2}"
2023-01-14 18:30:29 +01:00
;;
2024-08-07 07:08:54 +02:00
"sh")
2024-08-20 05:39:29 +02:00
require_dependency doas
2024-08-07 07:08:54 +02:00
"${libexec}"/commands/portzap-sh "${gitdir}"
;;
2024-05-22 02:22:39 +02:00
"rm")
2024-05-23 04:52:41 +02:00
"${libexec}"/commands/portzap-rm "${gitdir}" "${installdir}"
;;
2023-01-19 14:23:27 +01:00
"install")
2024-08-20 05:39:29 +02:00
require_dependency git doas
2024-08-20 07:17:05 +02:00
"${libexec}"/commands/portzap-install "${gitdir}" "${installdir}" "${commitfile}"
;;
2023-01-14 18:30:29 +01:00
*)
2024-04-02 18:56:49 +02:00
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"
2024-08-20 05:58:32 +02:00
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"
2024-08-07 07:08:54 +02:00
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"
2023-01-14 18:30:29 +01:00
;;
esac