portzap/bin/portzap

62 lines
1.4 KiB
Bash
Executable file

#!/bin/sh
set -e
##
# Variables
rootdir=$(dirname "$0")
giturl="${PORTZAP_GITURL:-https://git.hardenedbsd.org/hardenedbsd/ports.git}"
gitdir="/home/_portzap/ports"
installdir="${PORTZAP_INSTALLDIR:-/usr/ports/}"
revision="${installdir}/.portzap"
libexec=$(realpath "${rootdir}/../libexec/portzap/")
##
# Functions
require_root() {
if [ $(id -u) -ne 0 ]; then
echo "This command requires root privileges."
exit 1
fi
}
require_membership_of() {
group=$1
if ! id -Gn | tr ' ' '\n' | grep -e "^${group}$"; 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
}
. "$libexec/functions/portzap-install"
case $1 in
"clone")
require_dependency git
require_membership_of _portzap
${libexec}/portzap/portzap-clone "${giturl}" "${gitdir}"
;;
"pull")
require_dependency git
require_membership_of _portzap
${libexec}/portzap/portzap-pull "${gitdir}"
;;
"install")
require_root
require_dependency git
portzap_install "$installdir" "$portzap_dir" "$libexec" "$portzap_file"
;;
*)
echo "Usage: portzap clone|pull|install"
;;
esac