portzap/bin/setup-portzap
0x1eef 69a66825ab Add setup-cron
Add a setup script that adds a crontab entry that
runs 'portzap pull' everyday at 12AM localtime
2024-06-30 04:25:23 -03:00

41 lines
795 B
Bash
Executable file

#!/bin/sh
set -e
##
# variables
localbase=${LOCALBASE:-$(realpath "$(dirname "$0")"/..)}
sharedir="${localbase}"/share/portzap
libexec="${localbase}"/libexec/portzap
##
# functions
printok() {
"${libexec}"/utils/printok "$1"
}
printerr() {
"${libexec}"/utils/printerr "$1"
}
##
# main
if [ "$(id -u)" != "0" ]; then
printerr "you must be root"
exit 1
fi
if id -u _portzap > /dev/null 2>&1; then
printok "_portzap user exists"
else
pw useradd -n _portzap \
-c "portzap user" \
-m \
-s /sbin/nologin
chmod u=rwX,g=rX,o= /home/_portzap/
printok "_portzap user created"
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"