portzap/bin/setup-portzap

48 lines
961 B
Text
Raw Normal View History

#!/bin/sh
set -e
##
# variables
2024-05-23 02:42:15 +02:00
localbase="${LOCALBASE:-$(realpath $(dirname $0)/..)}"
2024-05-23 03:37:34 +02:00
libexec="${localbase}"/libexec/portzap
conf=$(cat "${localbase}"/share/portzap/doas.conf)
doas="${localbase}"/etc/doas.conf
2024-05-23 02:42:15 +02:00
##
# functions
printok() {
2024-05-23 04:52:41 +02:00
"${libexec}"/utils/printok "$1"
2024-05-23 02:42:15 +02:00
}
printerr() {
2024-05-23 04:52:41 +02:00
"${libexec}"/utils/printerr "$1"
2024-05-23 02:42:15 +02:00
}
##
# main
if [ "$(id -u)" != "0" ]; then
2024-05-23 02:42:15 +02:00
printerr "you must be root"
exit 1
fi
if id -u _portzap > /dev/null 2>&1; then
2024-05-23 02:42:15 +02:00
printok "_portzap user exists"
else
pw useradd -n _portzap \
-c "portzap user" \
-m \
-s /sbin/nologin
chmod u=rwX,g=rX,o= /home/_portzap/
2024-05-23 02:42:15 +02:00
printok "create _portzap user"
fi
if grep -F "^${conf}$" "${doas}" > /dev/null 2>&1; then
2024-05-23 02:42:15 +02:00
printok "${doas} is up to date"
else
echo "$conf" >> "$doas"
2024-05-23 02:42:15 +02:00
printok "update ${doas} (note: review the update)"
fi
2024-05-23 02:42:15 +02:00
printf "Add user(s) to the _portzap group:\n"
printf "root# pw groupmod -n _portzap -m user1,user2\n"