sourcezap/bin/setup-sourcezap

39 lines
807 B
Text
Raw Normal View History

2024-05-12 01:19:45 +02:00
#!/bin/sh
set -e
##
# variables
2024-06-01 05:50:47 +02:00
localbase=${LOCALBASE:-$(realpath "$(dirname "$0")"/..)}
libexec="${localbase}"/libexec/sourcezap
2024-05-12 01:19:45 +02:00
conf=$(cat "${localbase}"/share/sourcezap/doas.conf)
doas="${localbase}"/etc/doas.conf
2024-06-01 05:50:47 +02:00
##
# functions
2024-07-19 22:25:50 +02:00
. "${libexec}"/functions/print.sh
2024-06-01 05:50:47 +02:00
2024-05-12 01:19:45 +02:00
##
# main
if [ "$(id -u)" != "0" ]; then
2024-06-01 05:50:47 +02:00
printerr "you must be root"
2024-05-12 01:19:45 +02:00
exit 1
fi
if id -u _sourcezap > /dev/null 2>&1; then
2024-06-01 05:50:47 +02:00
printok "_sourcezap user exists"
2024-05-12 01:19:45 +02:00
else
pw useradd -n _sourcezap \
-c "sourcezap user" \
-m \
-s /sbin/nologin
chmod u=rwX,g=rX,o= /home/_sourcezap/
2024-06-01 05:50:47 +02:00
printok "create _sourcezap user"
2024-05-12 01:19:45 +02:00
fi
if grep -F "^${conf}$" "${doas}" > /dev/null 2>&1; then
2024-06-01 05:50:47 +02:00
printok "${doas} is up to date"
2024-05-12 01:19:45 +02:00
else
echo "$conf" >> "$doas"
2024-06-01 05:50:47 +02:00
printok "update ${doas} (note: review the update)"
2024-05-12 01:19:45 +02:00
fi