Add libexec/sourcezap/setup/

This commit is contained in:
0x1eef 2024-07-25 07:22:04 -03:00
parent c97b48bc0d
commit 36cb7591ee
2 changed files with 41 additions and 21 deletions

View file

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

View file

@ -0,0 +1,28 @@
#!/bin/sh
set -e
##
# variables
localbase=$(realpath "$(dirname "$0")"/../../..)
libexec="${localbase}"/libexec/sourcezap
sharedir="${localbase}"/share/sourcezap
##
# functions
. "${libexec}"/functions/print.sh
install_doasconf()
{
src="${sharedir}"/doas.conf
dest="${localbase}"/etc/doas.conf
if grep -Fq "$(cat "${src}")" "${dest}"; then
printok "doas.conf is up to date"
else
cat "${src}" >> "${dest}"
printok "${dest} updated"
fi
}
##
# main
install_doasconf