diff --git a/Makefile b/Makefile index ed65e3c..e024c6a 100644 --- a/Makefile +++ b/Makefile @@ -25,3 +25,4 @@ shellcheck: shellcheck bin/* shellcheck libexec/portzap/utils/* shellcheck libexec/portzap/commands/* + shellcheck libexec/portzap/setup/* diff --git a/bin/portzap b/bin/portzap index 2953e88..760a9f7 100755 --- a/bin/portzap +++ b/bin/portzap @@ -13,11 +13,13 @@ revfile="${installdir}"/.portzap ## # functions -printerr() { +printerr() +{ "${libexec}"/utils/printerr "$1" } -require_dependency() { +require_dependency() +{ deps=$1 for dep in $deps; do if ! which -s "$dep"; then diff --git a/bin/setup-portzap b/bin/setup-portzap index bdc875e..64b9578 100755 --- a/bin/setup-portzap +++ b/bin/setup-portzap @@ -4,16 +4,17 @@ set -e ## # variables localbase=${LOCALBASE:-$(realpath "$(dirname "$0")"/..)} -sharedir="${localbase}"/share/portzap libexec="${localbase}"/libexec/portzap ## # functions -printok() { +printok() +{ "${libexec}"/utils/printok "$1" } -printerr() { +printerr() +{ "${libexec}"/utils/printerr "$1" } @@ -37,5 +38,7 @@ fi "${libexec}"/setup/setup-doas "${libexec}"/setup/setup-cron -printf "\nAdd user(s) to the _portzap group:\n" -printf "root# pw groupmod -n _portzap -m user1,user2\n" +echo +echo "If you haven't already, add users to the _portzap group: " +echo "root@$(hostname)# pw groupmod -n _portzap -m user1,user2" +echo diff --git a/libexec/portzap/setup/setup-cron b/libexec/portzap/setup/setup-cron index 3b2db3d..f37ac39 100644 --- a/libexec/portzap/setup/setup-cron +++ b/libexec/portzap/setup/setup-cron @@ -4,29 +4,49 @@ set -e ## # variables user="_portzap" -localbase="$(realpath $(dirname $0)/../../..)" -libexec="${localbase}/libexec/portzap" -sharedir="${localbase}/share/portzap" +localbase=$(realpath "$(dirname "$0")"/../../..) +libexec="${localbase}"/libexec/portzap +sharedir="${localbase}"/share/portzap ## # functions -printok() { +printok() +{ "${libexec}"/utils/printok "$1" } -printerr() { +printerr() +{ "${libexec}"/utils/printerr "$1" } -verify_crontab() +verify_allowfile() { allowfile="/var/cron/allow" if [ -e "${allowfile}" ]; then - if ! grep "${user}" "${allowfile}" > /dev/null 2>&1; then - printerr "in order to use the portzap crontab, add ${user} to ${allowfile}" + if grep -Eqe "^${user}$" "${allowfile}"; then + printok "${user} found in ${allowfile}" + else + printerr "add ${user} to ${allowfile} in order to proceed" exit 1 fi - printok "${user} exists in ${allowfile}" + else + printok "${allowfile} not found" + fi +} + +verify_denyfile() +{ + denyfile="/var/cron/deny" + if [ -e "${denyfile}" ]; then + if grep -Eqe "^${user}$" "${denyfile}"; then + printerr "remove ${user} from ${denyfile} in order to proceed" + exit 1 + else + printok "${user} not found in ${denyfile}" + fi + else + printok "${denyfile} not found" fi } @@ -45,19 +65,20 @@ install_crontab() ## # main -printf "Do you want to run 'portzap pull' daily via cron(8) ? (yes|no) " +echo -n "configure portzap to run via cron(8) ? yes or no: " while read -r r; do case "${r}" in - y|Y|yes|YES) - verify_crontab + yes|YES) + verify_allowfile + verify_denyfile install_crontab break ;; - n|N|no|NO) + no|NO) break ;; *) - printf "Please answer yes or no: " + echo -n "yes or no: " ;; esac done diff --git a/libexec/portzap/setup/setup-doas b/libexec/portzap/setup/setup-doas index 639ccd2..e37c7cb 100644 --- a/libexec/portzap/setup/setup-doas +++ b/libexec/portzap/setup/setup-doas @@ -3,18 +3,19 @@ set -e ## # variables -user="_portzap" -localbase="$(realpath $(dirname $0)/../../..)" +localbase=$(realpath "$(dirname "$0")"/../../..) libexec="${localbase}/libexec/portzap" sharedir="${localbase}/share/portzap" ## # functions -printok() { +printok() +{ "${libexec}"/utils/printok "$1" } -printerr() { +printerr() +{ "${libexec}"/utils/printerr "$1" }