portzap/bin/setup-portzap

36 lines
972 B
Bash
Executable file

#!/bin/sh -e
##
# variables
localbase="${LOCALBASE:-/usr/local}"
conf=$(cat "${localbase}"/share/portzap/doas.conf)
doas="${localbase}"/etc/doas.conf
##
# main
if [ "$(id -u)" != "0" ]; then
echo "[-] This command must be run as root"
exit 1
fi
if id -u _portzap > /dev/null 2>&1; then
echo "[-] The _portzap user exists"
echo "[-] Add user(s) to the _portzap group:"
echo "root# pw groupmod -n _portzap -m user1,user2"
else
pw useradd -n _portzap \
-c "portzap user" \
-m \
-s /sbin/nologin
chmod u=rwX,g=rX,o= /home/_portzap/
echo "[-] The _portzap user, group and home directory have been created."
echo "[-] Add user(s) to the _portzap group:"
echo "root# pw groupmod -n _portzap -m user1,user2"
fi
if grep -F "^${conf}$" "${doas}" > /dev/null 2>&1; then
echo "[-] No changes made to ${doas}"
else
echo "$conf" >> "$doas"
echo "[-] ${doas} has been changed. Please review the changes"
fi