sourcezap/bin/setup-sourcezap

37 lines
998 B
Bash
Executable file

#!/bin/sh
set -e
##
# variables
localbase="${LOCALBASE:-/usr/local}"
conf=$(cat "${localbase}"/share/sourcezap/doas.conf)
doas="${localbase}"/etc/doas.conf
##
# main
if [ "$(id -u)" != "0" ]; then
echo "[x] This command must be run by root"
exit 1
fi
if id -u _sourcezap > /dev/null 2>&1; then
echo "[-] The _sourcezap user exists"
echo "[-] Add user(s) to the _sourcezap group:"
echo "root# pw groupmod -n _sourcezap -m user1,user2"
else
pw useradd -n _sourcezap \
-c "sourcezap user" \
-m \
-s /sbin/nologin
chmod u=rwX,g=rX,o= /home/_sourcezap/
echo "[-] The _sourcezap user, group and home directory have been created."
echo "[-] Add user(s) to the _sourcezap group:"
echo "root# pw groupmod -n _sourcezap -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