diff --git a/bin/portzap b/bin/portzap index 9473421..f1282e8 100755 --- a/bin/portzap +++ b/bin/portzap @@ -9,7 +9,7 @@ gitdir="/home/_portzap/ports" giturl="${PORTZAP_GITURL:-https://git.hardenedbsd.org/hardenedbsd/ports.git}" installdir="${PORTZAP_INSTALLDIR:-/usr/ports}" revision="${installdir}"/.portzap -libexec="${localbase}"/libexec/portzap +libexec=$(realpath "$(dirname "$0")")/../libexec/portzap ## # functions @@ -17,12 +17,16 @@ require_dependency() { deps=$1 for dep in $deps; do if ! which -s "$dep"; then - echo "ERR This command requires ${dep}, but ${dep} wasn't found" + printerr "${dep} wasn't found on \$PATH" exit 1 fi done } +printerr() { + "${libexec}"/print-err "$1" +} + ## # main i=1 diff --git a/libexec/portzap/portzap-checkout b/libexec/portzap/portzap-checkout index 99b96ea..b183a72 100644 --- a/libexec/portzap/portzap-checkout +++ b/libexec/portzap/portzap-checkout @@ -18,16 +18,19 @@ gitexec() /bin/sh -c "umask ${mode}; ${git} ${1}" } +printerr() { + "${libexec}"/print-err "$1" +} + ## # main if ! "${libexec}"/isportzap-member; then - echo "ERR This command must be run by a member of the '_portzap' group" + printerr "$(id -un) is not a member of _portzap" exit 1 fi if [ ! -e "${gitdir}/.git" ]; then - echo "ERR ${gitdir} is not a valid git repository." - echo "ERR Try: portzap clone" + printerr "try 'portzap clone' instead" exit 1 fi diff --git a/libexec/portzap/portzap-clone b/libexec/portzap/portzap-clone index 37e46e6..64e9b25 100755 --- a/libexec/portzap/portzap-clone +++ b/libexec/portzap/portzap-clone @@ -19,16 +19,19 @@ gitexec() /bin/sh -c "umask ${mode}; ${git} ${1}" } +printerr() { + "${libexec}"/print-err "$1" +} + ## # main if ! "${libexec}"/isportzap-member; then - echo "ERR This command must be run by a member of the '_portzap' group" + printerr "$(id -un) is not a member of _portzap" exit 1 fi if [ -e "${gitdir}/.git" ]; then - echo "ERR ${gitdir} exists." - echo "ERR Try: portzap pull" + printerr "try 'portzap pull' instead" exit 1 fi diff --git a/libexec/portzap/portzap-install b/libexec/portzap/portzap-install index 8519cbb..2c347d5 100755 --- a/libexec/portzap/portzap-install +++ b/libexec/portzap/portzap-install @@ -57,10 +57,14 @@ run_install() install -o root -g _portzap -m "${mode}" -v "$@" } +printerr() { + "${libexec}"/print-err "$1" +} + ## # main if [ "$(id -u)" != "0" ]; then - echo "ERR This command must be run by root" + printerr "you must be root" exit 1 fi diff --git a/libexec/portzap/portzap-pull b/libexec/portzap/portzap-pull index 326e939..f3f0e67 100755 --- a/libexec/portzap/portzap-pull +++ b/libexec/portzap/portzap-pull @@ -17,17 +17,19 @@ gitexec() /bin/sh -c "umask ${mode}; ${git} ${1}" } +printerr() { + "${libexec}"/print-err "$1" +} + ## # main if ! "${libexec}"/isportzap-member; then - echo "ERR This command must be run by a member of the '_portzap' group" + printerr "$(id -un) is not a member of _portzap" exit 1 fi if [ ! -e "${gitdir}/.git" ]; then - set +x - echo "ERR ${gitdir} is not a valid git repository." - echo "ERR Try: portzap clone" + printerr "try 'portzap clone' instead" exit 1 fi diff --git a/libexec/portzap/portzap-rm b/libexec/portzap/portzap-rm index 49c853f..b82138f 100644 --- a/libexec/portzap/portzap-rm +++ b/libexec/portzap/portzap-rm @@ -3,6 +3,7 @@ set -e ## # variables +libexec=$(dirname "$0") gitdir=$1 installdir=$2 @@ -22,10 +23,14 @@ erase() echo } +printerr() { + "${libexec}"/print-err "$1" +} + ## # main if [ "$(id -u)" != "0" ]; then - echo "ERR This command must be run by root" + printerr "you must be root" exit 1 fi diff --git a/libexec/portzap/print-err b/libexec/portzap/print-err new file mode 100644 index 0000000..8fdbff6 --- /dev/null +++ b/libexec/portzap/print-err @@ -0,0 +1,10 @@ +#!/bin/sh +set -e + +## +# variables +err="${1}" + +## +# main +printf "error: %s\n" "${err}" > /dev/stderr