Add verify_denyfile, and other small fixes
This commit is contained in:
parent
69a66825ab
commit
8d8346d51f
5 changed files with 53 additions and 25 deletions
1
Makefile
1
Makefile
|
@ -25,3 +25,4 @@ shellcheck:
|
||||||
shellcheck bin/*
|
shellcheck bin/*
|
||||||
shellcheck libexec/portzap/utils/*
|
shellcheck libexec/portzap/utils/*
|
||||||
shellcheck libexec/portzap/commands/*
|
shellcheck libexec/portzap/commands/*
|
||||||
|
shellcheck libexec/portzap/setup/*
|
||||||
|
|
|
@ -13,11 +13,13 @@ revfile="${installdir}"/.portzap
|
||||||
|
|
||||||
##
|
##
|
||||||
# functions
|
# functions
|
||||||
printerr() {
|
printerr()
|
||||||
|
{
|
||||||
"${libexec}"/utils/printerr "$1"
|
"${libexec}"/utils/printerr "$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
require_dependency() {
|
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
|
||||||
|
|
|
@ -4,16 +4,17 @@ set -e
|
||||||
##
|
##
|
||||||
# variables
|
# variables
|
||||||
localbase=${LOCALBASE:-$(realpath "$(dirname "$0")"/..)}
|
localbase=${LOCALBASE:-$(realpath "$(dirname "$0")"/..)}
|
||||||
sharedir="${localbase}"/share/portzap
|
|
||||||
libexec="${localbase}"/libexec/portzap
|
libexec="${localbase}"/libexec/portzap
|
||||||
|
|
||||||
##
|
##
|
||||||
# functions
|
# functions
|
||||||
printok() {
|
printok()
|
||||||
|
{
|
||||||
"${libexec}"/utils/printok "$1"
|
"${libexec}"/utils/printok "$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
printerr() {
|
printerr()
|
||||||
|
{
|
||||||
"${libexec}"/utils/printerr "$1"
|
"${libexec}"/utils/printerr "$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,5 +38,7 @@ fi
|
||||||
|
|
||||||
"${libexec}"/setup/setup-doas
|
"${libexec}"/setup/setup-doas
|
||||||
"${libexec}"/setup/setup-cron
|
"${libexec}"/setup/setup-cron
|
||||||
printf "\nAdd user(s) to the _portzap group:\n"
|
echo
|
||||||
printf "root# pw groupmod -n _portzap -m user1,user2\n"
|
echo "If you haven't already, add users to the _portzap group: "
|
||||||
|
echo "root@$(hostname)# pw groupmod -n _portzap -m user1,user2"
|
||||||
|
echo
|
||||||
|
|
|
@ -4,29 +4,49 @@ set -e
|
||||||
##
|
##
|
||||||
# variables
|
# variables
|
||||||
user="_portzap"
|
user="_portzap"
|
||||||
localbase="$(realpath $(dirname $0)/../../..)"
|
localbase=$(realpath "$(dirname "$0")"/../../..)
|
||||||
libexec="${localbase}/libexec/portzap"
|
libexec="${localbase}"/libexec/portzap
|
||||||
sharedir="${localbase}/share/portzap"
|
sharedir="${localbase}"/share/portzap
|
||||||
|
|
||||||
##
|
##
|
||||||
# functions
|
# functions
|
||||||
printok() {
|
printok()
|
||||||
|
{
|
||||||
"${libexec}"/utils/printok "$1"
|
"${libexec}"/utils/printok "$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
printerr() {
|
printerr()
|
||||||
|
{
|
||||||
"${libexec}"/utils/printerr "$1"
|
"${libexec}"/utils/printerr "$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
verify_crontab()
|
verify_allowfile()
|
||||||
{
|
{
|
||||||
allowfile="/var/cron/allow"
|
allowfile="/var/cron/allow"
|
||||||
if [ -e "${allowfile}" ]; then
|
if [ -e "${allowfile}" ]; then
|
||||||
if ! grep "${user}" "${allowfile}" > /dev/null 2>&1; then
|
if grep -Eqe "^${user}$" "${allowfile}"; then
|
||||||
printerr "in order to use the portzap crontab, add ${user} to ${allowfile}"
|
printok "${user} found in ${allowfile}"
|
||||||
|
else
|
||||||
|
printerr "add ${user} to ${allowfile} in order to proceed"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
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
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,19 +65,20 @@ install_crontab()
|
||||||
|
|
||||||
##
|
##
|
||||||
# main
|
# 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
|
while read -r r; do
|
||||||
case "${r}" in
|
case "${r}" in
|
||||||
y|Y|yes|YES)
|
yes|YES)
|
||||||
verify_crontab
|
verify_allowfile
|
||||||
|
verify_denyfile
|
||||||
install_crontab
|
install_crontab
|
||||||
break
|
break
|
||||||
;;
|
;;
|
||||||
n|N|no|NO)
|
no|NO)
|
||||||
break
|
break
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
printf "Please answer yes or no: "
|
echo -n "yes or no: "
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
|
@ -3,18 +3,19 @@ set -e
|
||||||
|
|
||||||
##
|
##
|
||||||
# variables
|
# variables
|
||||||
user="_portzap"
|
localbase=$(realpath "$(dirname "$0")"/../../..)
|
||||||
localbase="$(realpath $(dirname $0)/../../..)"
|
|
||||||
libexec="${localbase}/libexec/portzap"
|
libexec="${localbase}/libexec/portzap"
|
||||||
sharedir="${localbase}/share/portzap"
|
sharedir="${localbase}/share/portzap"
|
||||||
|
|
||||||
##
|
##
|
||||||
# functions
|
# functions
|
||||||
printok() {
|
printok()
|
||||||
|
{
|
||||||
"${libexec}"/utils/printok "$1"
|
"${libexec}"/utils/printok "$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
printerr() {
|
printerr()
|
||||||
|
{
|
||||||
"${libexec}"/utils/printerr "$1"
|
"${libexec}"/utils/printerr "$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue