2024-05-11 19:51:26 +02:00
|
|
|
#!/bin/sh
|
|
|
|
set -e
|
2024-04-08 01:27:18 +02:00
|
|
|
|
|
|
|
##
|
|
|
|
# variables
|
2024-05-23 02:42:15 +02:00
|
|
|
localbase="${LOCALBASE:-$(realpath $(dirname $0)/..)}"
|
|
|
|
libexec="${localbase}/libexec/portzap"
|
2024-04-15 21:48:06 +02:00
|
|
|
conf=$(cat "${localbase}"/share/portzap/doas.conf)
|
|
|
|
doas="${localbase}"/etc/doas.conf
|
2024-04-08 01:27:18 +02:00
|
|
|
|
2024-05-23 02:42:15 +02:00
|
|
|
##
|
|
|
|
# functions
|
|
|
|
printok() {
|
|
|
|
"${libexec}"/printok "$1"
|
|
|
|
}
|
|
|
|
|
|
|
|
printerr() {
|
|
|
|
"${libexec}"/printerr "$1"
|
|
|
|
}
|
|
|
|
|
2024-04-08 01:27:18 +02:00
|
|
|
##
|
|
|
|
# main
|
2024-04-19 10:49:49 +02:00
|
|
|
if [ "$(id -u)" != "0" ]; then
|
2024-05-23 02:42:15 +02:00
|
|
|
printerr "you must be root"
|
2024-04-19 10:49:49 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2024-04-17 12:10:26 +02:00
|
|
|
if id -u _portzap > /dev/null 2>&1; then
|
2024-05-23 02:42:15 +02:00
|
|
|
printok "_portzap user exists"
|
2024-04-17 12:10:26 +02:00
|
|
|
else
|
2024-04-08 01:27:18 +02:00
|
|
|
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"
|
2024-04-08 01:27:18 +02:00
|
|
|
fi
|
|
|
|
|
2024-04-17 12:10:26 +02:00
|
|
|
if grep -F "^${conf}$" "${doas}" > /dev/null 2>&1; then
|
2024-05-23 02:42:15 +02:00
|
|
|
printok "${doas} is up to date"
|
2024-04-17 12:10:26 +02:00
|
|
|
else
|
|
|
|
echo "$conf" >> "$doas"
|
2024-05-23 02:42:15 +02:00
|
|
|
printok "update ${doas} (note: review the update)"
|
2024-04-08 01:27:18 +02:00
|
|
|
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"
|