Add verify_denyfile, and other small fixes

This commit is contained in:
0x1eef 2024-06-30 04:37:15 -03:00
parent 69a66825ab
commit 8d8346d51f
5 changed files with 53 additions and 25 deletions

View file

@ -25,3 +25,4 @@ shellcheck:
shellcheck bin/*
shellcheck libexec/portzap/utils/*
shellcheck libexec/portzap/commands/*
shellcheck libexec/portzap/setup/*

View file

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

View file

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

View file

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

View file

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