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:
parent
b94c97006d
commit
f125413729
7 changed files with 45 additions and 14 deletions
|
@ -9,7 +9,7 @@ gitdir="/home/_portzap/ports"
|
||||||
giturl="${PORTZAP_GITURL:-https://git.hardenedbsd.org/hardenedbsd/ports.git}"
|
giturl="${PORTZAP_GITURL:-https://git.hardenedbsd.org/hardenedbsd/ports.git}"
|
||||||
installdir="${PORTZAP_INSTALLDIR:-/usr/ports}"
|
installdir="${PORTZAP_INSTALLDIR:-/usr/ports}"
|
||||||
revision="${installdir}"/.portzap
|
revision="${installdir}"/.portzap
|
||||||
libexec="${localbase}"/libexec/portzap
|
libexec=$(realpath "$(dirname "$0")")/../libexec/portzap
|
||||||
|
|
||||||
##
|
##
|
||||||
# functions
|
# functions
|
||||||
|
@ -17,12 +17,16 @@ require_dependency() {
|
||||||
deps=$1
|
deps=$1
|
||||||
for dep in $deps; do
|
for dep in $deps; do
|
||||||
if ! which -s "$dep"; then
|
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
|
exit 1
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
printerr() {
|
||||||
|
"${libexec}"/print-err "$1"
|
||||||
|
}
|
||||||
|
|
||||||
##
|
##
|
||||||
# main
|
# main
|
||||||
i=1
|
i=1
|
||||||
|
|
|
@ -18,16 +18,19 @@ gitexec()
|
||||||
/bin/sh -c "umask ${mode}; ${git} ${1}"
|
/bin/sh -c "umask ${mode}; ${git} ${1}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
printerr() {
|
||||||
|
"${libexec}"/print-err "$1"
|
||||||
|
}
|
||||||
|
|
||||||
##
|
##
|
||||||
# main
|
# main
|
||||||
if ! "${libexec}"/isportzap-member; then
|
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
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -e "${gitdir}/.git" ]; then
|
if [ ! -e "${gitdir}/.git" ]; then
|
||||||
echo "ERR ${gitdir} is not a valid git repository."
|
printerr "try 'portzap clone' instead"
|
||||||
echo "ERR Try: portzap clone"
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
@ -19,16 +19,19 @@ gitexec()
|
||||||
/bin/sh -c "umask ${mode}; ${git} ${1}"
|
/bin/sh -c "umask ${mode}; ${git} ${1}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
printerr() {
|
||||||
|
"${libexec}"/print-err "$1"
|
||||||
|
}
|
||||||
|
|
||||||
##
|
##
|
||||||
# main
|
# main
|
||||||
if ! "${libexec}"/isportzap-member; then
|
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
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -e "${gitdir}/.git" ]; then
|
if [ -e "${gitdir}/.git" ]; then
|
||||||
echo "ERR ${gitdir} exists."
|
printerr "try 'portzap pull' instead"
|
||||||
echo "ERR Try: portzap pull"
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
@ -57,10 +57,14 @@ run_install()
|
||||||
install -o root -g _portzap -m "${mode}" -v "$@"
|
install -o root -g _portzap -m "${mode}" -v "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
printerr() {
|
||||||
|
"${libexec}"/print-err "$1"
|
||||||
|
}
|
||||||
|
|
||||||
##
|
##
|
||||||
# main
|
# main
|
||||||
if [ "$(id -u)" != "0" ]; then
|
if [ "$(id -u)" != "0" ]; then
|
||||||
echo "ERR This command must be run by root"
|
printerr "you must be root"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
@ -17,17 +17,19 @@ gitexec()
|
||||||
/bin/sh -c "umask ${mode}; ${git} ${1}"
|
/bin/sh -c "umask ${mode}; ${git} ${1}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
printerr() {
|
||||||
|
"${libexec}"/print-err "$1"
|
||||||
|
}
|
||||||
|
|
||||||
##
|
##
|
||||||
# main
|
# main
|
||||||
if ! "${libexec}"/isportzap-member; then
|
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
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -e "${gitdir}/.git" ]; then
|
if [ ! -e "${gitdir}/.git" ]; then
|
||||||
set +x
|
printerr "try 'portzap clone' instead"
|
||||||
echo "ERR ${gitdir} is not a valid git repository."
|
|
||||||
echo "ERR Try: portzap clone"
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ set -e
|
||||||
|
|
||||||
##
|
##
|
||||||
# variables
|
# variables
|
||||||
|
libexec=$(dirname "$0")
|
||||||
gitdir=$1
|
gitdir=$1
|
||||||
installdir=$2
|
installdir=$2
|
||||||
|
|
||||||
|
@ -22,10 +23,14 @@ erase()
|
||||||
echo
|
echo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
printerr() {
|
||||||
|
"${libexec}"/print-err "$1"
|
||||||
|
}
|
||||||
|
|
||||||
##
|
##
|
||||||
# main
|
# main
|
||||||
if [ "$(id -u)" != "0" ]; then
|
if [ "$(id -u)" != "0" ]; then
|
||||||
echo "ERR This command must be run by root"
|
printerr "you must be root"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
10
libexec/portzap/print-err
Normal file
10
libexec/portzap/print-err
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
#!/bin/sh
|
||||||
|
set -e
|
||||||
|
|
||||||
|
##
|
||||||
|
# variables
|
||||||
|
err="${1}"
|
||||||
|
|
||||||
|
##
|
||||||
|
# main
|
||||||
|
printf "error: %s\n" "${err}" > /dev/stderr
|
Loading…
Reference in a new issue