#!/bin/sh set -e ## # Variables rootdir=$(dirname "$0") gitdir="/home/_portzap/ports" giturl="${PORTZAP_GITURL:-https://git.hardenedbsd.org/hardenedbsd/ports.git}" installdir="${PORTZAP_INSTALLDIR:-/usr/ports}" revision="${installdir}/.portzap" libexec=$(realpath "${rootdir}/../libexec/portzap") ## # Functions require_root() { if [ "$(id -u)" != "0" ]; then echo "This command requires root privileges." exit 1 fi } require_membership_of() { group=$1 if ! id -Gn | tr ' ' '\n' | grep -e "^${group}$" > /dev/null 2>&1; then echo "This command requires a user to be a member of ${group}." exit 1 fi } require_dependency() { deps=$1 for dep in $deps; do if ! which -s "$dep"; then echo "This command requires ${dep}, but it was not found." exit 1 fi done } ## # main case $1 in "clone") require_dependency git require_membership_of _portzap "${libexec}"/portzap-clone "${giturl}" "${gitdir}" ;; "pull") require_dependency git require_membership_of _portzap "${libexec}"/portzap-pull "${gitdir}" ;; "install") require_root require_dependency git "${libexec}"/portzap-install "${gitdir}" "${installdir}" "${revision}" ;; "adduser") require_root "${libexec}"/portzap-adduser ;; *) 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 " install Install the ports tree into /usr/ports.\n" printf " adduser Add the portzap user, group and home directory.\n" ;; esac