Add libexec/portzap/printok

This commit is contained in:
0x1eef 2024-05-22 21:42:15 -03:00
parent f495c3c62b
commit f14591d42b
9 changed files with 52 additions and 19 deletions

View file

@ -24,7 +24,7 @@ require_dependency() {
}
printerr() {
"${libexec}"/print-err "$1"
"${libexec}"/printerr "$1"
}
##

View file

@ -3,35 +3,45 @@ set -e
##
# variables
localbase="${LOCALBASE:-/usr/local}"
localbase="${LOCALBASE:-$(realpath $(dirname $0)/..)}"
libexec="${localbase}/libexec/portzap"
conf=$(cat "${localbase}"/share/portzap/doas.conf)
doas="${localbase}"/etc/doas.conf
##
# functions
printok() {
"${libexec}"/printok "$1"
}
printerr() {
"${libexec}"/printerr "$1"
}
##
# main
if [ "$(id -u)" != "0" ]; then
echo "ERR This command must be run by root"
printerr "you must be root"
exit 1
fi
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"
printok "_portzap user exists"
else
pw useradd -n _portzap \
-c "portzap user" \
-m \
-s /sbin/nologin
chmod u=rwX,g=rX,o= /home/_portzap/
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"
printok "create _portzap user"
fi
if grep -F "^${conf}$" "${doas}" > /dev/null 2>&1; then
echo "[-] No changes made to ${doas}"
printok "${doas} is up to date"
else
echo "$conf" >> "$doas"
echo "[-] ${doas} has been changed. Please review the changes"
printok "update ${doas} (note: review the update)"
fi
printf "Add user(s) to the _portzap group:\n"
printf "root# pw groupmod -n _portzap -m user1,user2\n"

View file

@ -19,7 +19,7 @@ gitexec()
}
printerr() {
"${libexec}"/print-err "$1"
"${libexec}"/printerr "$1"
}
##

View file

@ -19,8 +19,12 @@ gitexec()
/bin/sh -c "umask ${mode}; ${git} ${1}"
}
printok() {
"${libexec}"/printok "$1"
}
printerr() {
"${libexec}"/print-err "$1"
"${libexec}"/printerr "$1"
}
##
@ -45,6 +49,5 @@ gitexec "clone ${giturl} ${gitdir}"
cd "${gitdir}"
gitexec "config core.filemode off"
set +x
echo "[-] git checkout ${branch}"
gitexec "checkout -t origin/${branch} > /dev/null 2>&1"
echo "[-] Done"
gitexec "checkout -t origin/${branch}"
printok "clone complete"

View file

@ -57,8 +57,12 @@ run_install()
install -o root -g _portzap -m "${mode}" -v "$@"
}
printok() {
"${libexec}"/printok "$1"
}
printerr() {
"${libexec}"/print-err "$1"
"${libexec}"/printerr "$1"
}
##
@ -80,3 +84,4 @@ else
perform_install
fi
"${libexec}"/git-rev "${gitdir}" > "${revfile}"
printok "install complete"

View file

@ -17,8 +17,12 @@ gitexec()
/bin/sh -c "umask ${mode}; ${git} ${1}"
}
printok() {
"${libexec}"/printok "$1"
}
printerr() {
"${libexec}"/print-err "$1"
"${libexec}"/printerr "$1"
}
##
@ -42,3 +46,4 @@ set -x
cd "${gitdir}"
branch=$(gitexec "branch --show-current")
gitexec "pull --rebase origin ${branch}"
printok "pull complete"

View file

@ -24,7 +24,7 @@ erase()
}
printerr() {
"${libexec}"/print-err "$1"
"${libexec}"/printerr "$1"
}
##

10
libexec/portzap/printok Normal file
View file

@ -0,0 +1,10 @@
#!/bin/sh
set -e
##
# variables
msg="${1}"
##
# main
printf "ok: %s\n" "${msg}" > /dev/stdout