66 lines
1.4 KiB
Bash
Executable file
66 lines
1.4 KiB
Bash
Executable file
#!/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) -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}$" > /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
|
|
;;
|
|
*)
|
|
echo "Usage: portzap COMMAND [OPTIONS]"
|
|
;;
|
|
esac
|