2024-05-11 19:51:26 +02:00
|
|
|
#!/bin/sh
|
|
|
|
set -e
|
2024-04-08 01:27:18 +02:00
|
|
|
|
|
|
|
##
|
|
|
|
# variables
|
2024-04-15 21:48:06 +02:00
|
|
|
localbase="${LOCALBASE:-/usr/local}"
|
|
|
|
conf=$(cat "${localbase}"/share/portzap/doas.conf)
|
|
|
|
doas="${localbase}"/etc/doas.conf
|
2024-04-08 01:27:18 +02:00
|
|
|
|
|
|
|
##
|
|
|
|
# main
|
2024-04-19 10:49:49 +02:00
|
|
|
if [ "$(id -u)" != "0" ]; then
|
2024-05-22 03:33:36 +02:00
|
|
|
echo "ERR This command must be run by 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
|
|
|
|
echo "[-] The _portzap user exists"
|
|
|
|
echo "[-] Add user(s) to the _portzap group:"
|
|
|
|
echo "root# pw groupmod -n _portzap -m user1,user2"
|
|
|
|
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-04-17 12:10:26 +02:00
|
|
|
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"
|
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
|
|
|
|
echo "[-] No changes made to ${doas}"
|
|
|
|
else
|
|
|
|
echo "$conf" >> "$doas"
|
|
|
|
echo "[-] ${doas} has been changed. Please review the changes"
|
2024-04-08 01:27:18 +02:00
|
|
|
fi
|