2024-05-11 19:51:26 +02:00
|
|
|
#!/bin/sh
|
|
|
|
set -e
|
2023-06-10 01:47:34 +02:00
|
|
|
|
2024-04-02 01:24:02 +02:00
|
|
|
##
|
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}"
|
2024-04-02 04:41:53 +02:00
|
|
|
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
|
2023-01-17 00:54:03 +01:00
|
|
|
|
2024-04-02 01:24:02 +02:00
|
|
|
##
|
2024-04-03 17:49:53 +02:00
|
|
|
# functions
|
2024-07-27 03:26:07 +02:00
|
|
|
# shellcheck source=/dev/null
|
2024-07-22 02:41:12 +02:00
|
|
|
. "${libexec}"/functions/print.sh
|
2024-05-23 05:34:21 +02:00
|
|
|
|
2024-06-30 09:37:15 +02:00
|
|
|
require_dependency()
|
|
|
|
{
|
2024-08-20 05:42:40 +02:00
|
|
|
# shellcheck disable=SC3043
|
2024-08-20 05:39:29 +02:00
|
|
|
local dep
|
|
|
|
for i in $(seq 1 ${#}); do
|
|
|
|
eval "dep=\$${i}"
|
2024-04-02 01:24:02 +02:00
|
|
|
if ! which -s "$dep"; then
|
2024-05-22 19:42:24 +02:00
|
|
|
printerr "${dep} wasn't found on \$PATH"
|
2024-04-02 01:24:02 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2024-04-02 04:41:53 +02:00
|
|
|
##
|
|
|
|
# main
|
2024-04-19 01:19:54 +02:00
|
|
|
i=1
|
|
|
|
while [ "${i}" -le "$#" ]; do
|
|
|
|
eval "_portzap_option=\$${i}"
|
2024-04-19 09:45:11 +02:00
|
|
|
# shellcheck disable=SC2154
|
2024-04-19 01:19:54 +02:00
|
|
|
if [ "${_portzap_option}" = "-v" ]; then
|
2024-04-19 09:56:39 +02:00
|
|
|
cat "${localbase}"/share/portzap/VERSION
|
2024-04-19 01:19:54 +02:00
|
|
|
exit 0
|
|
|
|
fi
|
2024-04-19 09:45:11 +02:00
|
|
|
# shellcheck disable=SC2003
|
2024-04-19 01:19:54 +02:00
|
|
|
i=$(expr "${i}" + 1);
|
|
|
|
done
|
|
|
|
|
2023-01-14 18:30:29 +01:00
|
|
|
case $1 in
|
2024-08-17 22:15:30 +02:00
|
|
|
"setup")
|
2024-08-17 23:34:39 +02:00
|
|
|
"${libexec}"/commands/portzap-setup
|
|
|
|
;;
|
2024-08-17 22:15:30 +02:00
|
|
|
"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}"
|
2024-05-22 03:24:36 +02:00
|
|
|
;;
|
|
|
|
"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}"
|
2024-04-18 01:21:34 +02:00
|
|
|
;;
|
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}"
|
2024-04-02 04:41:53 +02:00
|
|
|
;;
|
2023-01-14 18:30:29 +01:00
|
|
|
*)
|
2024-04-02 18:56:49 +02:00
|
|
|
printf "Usage: portzap COMMAND [OPTIONS]\n"
|
|
|
|
printf "\n"
|
2024-08-17 22:15:30 +02:00
|
|
|
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"
|
2024-05-22 03:24:36 +02:00
|
|
|
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"
|
2024-05-22 03:24:36 +02:00
|
|
|
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
|
|
|
;;
|
2024-04-02 04:41:53 +02:00
|
|
|
esac
|