From f14591d42bb8f8057f4915bfe3eeed494a7219b1 Mon Sep 17 00:00:00 2001 From: 0x1eef <0x1eef@protonmail.com> Date: Wed, 22 May 2024 21:42:15 -0300 Subject: [PATCH] Add libexec/portzap/printok --- bin/portzap | 2 +- bin/setup-portzap | 30 ++++++++++++++++--------- libexec/portzap/portzap-checkout | 2 +- libexec/portzap/portzap-clone | 11 +++++---- libexec/portzap/portzap-install | 7 +++++- libexec/portzap/portzap-pull | 7 +++++- libexec/portzap/portzap-rm | 2 +- libexec/portzap/{print-err => printerr} | 0 libexec/portzap/printok | 10 +++++++++ 9 files changed, 52 insertions(+), 19 deletions(-) rename libexec/portzap/{print-err => printerr} (100%) create mode 100644 libexec/portzap/printok diff --git a/bin/portzap b/bin/portzap index f1282e8..6b38656 100755 --- a/bin/portzap +++ b/bin/portzap @@ -24,7 +24,7 @@ require_dependency() { } printerr() { - "${libexec}"/print-err "$1" + "${libexec}"/printerr "$1" } ## diff --git a/bin/setup-portzap b/bin/setup-portzap index 8412225..92bd72e 100755 --- a/bin/setup-portzap +++ b/bin/setup-portzap @@ -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" diff --git a/libexec/portzap/portzap-checkout b/libexec/portzap/portzap-checkout index 4210d32..8fade8a 100644 --- a/libexec/portzap/portzap-checkout +++ b/libexec/portzap/portzap-checkout @@ -19,7 +19,7 @@ gitexec() } printerr() { - "${libexec}"/print-err "$1" + "${libexec}"/printerr "$1" } ## diff --git a/libexec/portzap/portzap-clone b/libexec/portzap/portzap-clone index 67a2464..ad8511d 100755 --- a/libexec/portzap/portzap-clone +++ b/libexec/portzap/portzap-clone @@ -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" diff --git a/libexec/portzap/portzap-install b/libexec/portzap/portzap-install index 2c347d5..32bcd49 100755 --- a/libexec/portzap/portzap-install +++ b/libexec/portzap/portzap-install @@ -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" diff --git a/libexec/portzap/portzap-pull b/libexec/portzap/portzap-pull index ce4e134..fc55a66 100755 --- a/libexec/portzap/portzap-pull +++ b/libexec/portzap/portzap-pull @@ -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" diff --git a/libexec/portzap/portzap-rm b/libexec/portzap/portzap-rm index b82138f..18c869e 100644 --- a/libexec/portzap/portzap-rm +++ b/libexec/portzap/portzap-rm @@ -24,7 +24,7 @@ erase() } printerr() { - "${libexec}"/print-err "$1" + "${libexec}"/printerr "$1" } ## diff --git a/libexec/portzap/print-err b/libexec/portzap/printerr similarity index 100% rename from libexec/portzap/print-err rename to libexec/portzap/printerr diff --git a/libexec/portzap/printok b/libexec/portzap/printok new file mode 100644 index 0000000..315f891 --- /dev/null +++ b/libexec/portzap/printok @@ -0,0 +1,10 @@ +#!/bin/sh +set -e + +## +# variables +msg="${1}" + +## +# main +printf "ok: %s\n" "${msg}" > /dev/stdout