sourcezap/bin/setup-srczap

37 lines
965 B
Bash
Executable file

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