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() { printerr() {
"${libexec}"/print-err "$1" "${libexec}"/printerr "$1"
} }
## ##

View file

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

View file

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

View file

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

View file

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

View file

@ -24,7 +24,7 @@ erase()
} }
printerr() { 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