Update error logging

Few notable changes:
  - Write error messages to stderr
  - Keep the error messages brief
  - Centralize error logging via libexec/portzap/print-err
This commit is contained in:
0x1eef 2024-05-22 14:42:24 -03:00
parent b94c97006d
commit f125413729
7 changed files with 45 additions and 14 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

10
libexec/portzap/print-err Normal file
View file

@ -0,0 +1,10 @@
#!/bin/sh
set -e
##
# variables
err="${1}"
##
# main
printf "error: %s\n" "${err}" > /dev/stderr