diff options
author | bill-auger <mr.j.spam.me@gmail.com> | 2023-11-20 02:43:22 -0500 |
---|---|---|
committer | bill-auger <mr.j.spam.me@gmail.com> | 2024-01-01 20:33:08 -0500 |
commit | 74359af210bd1c2a7b31375ad268b8db90934be0 (patch) | |
tree | d91b658d8ba5851b923551881d5dfdd6a355b256 | |
parent | 31e4474fd50e118c9979c12c67c9f18371c59742 (diff) |
split pbot notification out to separate file
-rwxr-xr-x | src/abslibre-tools/librerelease | 32 | ||||
-rw-r--r-- | src/lib/notifications.sh | 31 |
2 files changed, 37 insertions, 26 deletions
diff --git a/src/abslibre-tools/librerelease b/src/abslibre-tools/librerelease index c77eba9..995ec2b 100755 --- a/src/abslibre-tools/librerelease +++ b/src/abslibre-tools/librerelease @@ -40,8 +40,9 @@ set -euE -source "$(librelib conf)" -source "$(librelib messages)" +source "$(librelib conf )" +source "$(librelib messages )" +source "$(librelib notifications)" setup_traps @@ -322,31 +323,10 @@ release_packages() { fi - ## notify pbot of the excellent work that we have done today ## - - local login=${REPODEST_userinfo:-somebody} ; login=${login%%:*} ; - local select_pkgs_rx='\.pkg\.tar\.[^\.]+$' - local reject_pkgs_rx='-debug-' - # (repo ) (pkgname)(pkgver) (arch ) - local pkgname_rx='s|.*([^/]+)/[^/]+/([^/-]+)-([^/-]+)-[^/-]+-([^/-\.]+)\.[^\.]+$|[\4/\1]/\2-\3|' - local pbotsay_fmt="which pbot-say && pbot-say %s just published: %s" - local filename - local packages=( - $( - while read -r -d '' - do filename="$REPLY" - [[ "${filename}" =~ ${select_pkgs_rx} ]] || continue - [[ "${filename}" =~ ${reject_pkgs_rx} ]] && continue || : - - sed -E "${pkgname_rx}" <<<${filename} || : - done < ${file_list} | sort -u | xargs || : - ) - ) - if (( ${#packages[@]} )); then - local pbotsay_cmd="$(printf "${pbotsay_fmt}" "${login}" "${packages[@]}")" + # notify pbot of the excellent work that we have done today + local ssh_cmd="ssh ${REPODEST_port:+-p $REPODEST_port} ${REPODEST_userhost}" + notify_pbot "$ssh_cmd" < $file_list - ssh ${tier0_port} "${tier0_host}" "${pbotsay_cmd}" &> /dev/null || : - fi return $EXIT_SUCCESS } diff --git a/src/lib/notifications.sh b/src/lib/notifications.sh new file mode 100644 index 0000000..e71b04e --- /dev/null +++ b/src/lib/notifications.sh @@ -0,0 +1,31 @@ +# process librerelease::$file_list via STDIN +notify_pbot() # ( "ssh_cmd" ) file_list->STDIN +{ + local ssh_cmd="$1" + local repo_user=${REPOUSER:-${LIBREUSER:-somebody}} + local select_rx='\.pkg\.tar\.[^\.]+$' + local reject_rx='-debug-' + # example "selected" $file_list entry, to be fed through $filename_rx: + # libre/gst-plugins-bad-1.22.8-1.parabola1-x86_64.pkg.tar.zst + # (repo )/(pkgname )-(pkgver )- -(arch ) + local filename_rx="^([a-z]+)/([0-9A-Za-z\._@\+\-]+)-([0-9A-Za-z\._]+)-[^/-]+-([0-9a-z_]+)${select_rx}$" + # example $filename_subst, sent to pbot: + # (gst-plugins-bad 1.22.8)->libre/x86_64 + local filename_subst='(\2 \3)->\1/\4' + local filename_sed="s|${filename_rx}|${filename_subst}|" + local filename + local releases=( $(while read -r -d '' # process librerelease::$file_list via STDIN + do filename="$REPLY" + [[ "${filename}" =~ ${select_rx} ]] || continue + [[ "${filename}" =~ ${reject_rx} ]] && continue || : + + sed -E "${filename_sed}" <<<${filename} || : + done | sort -u | xargs || :) ) + local pbotsay_msg="$(printf "$(_ "%s just published:")" ${repo_user}) ${releases[@]}" + local pbotsay_cmd="which pbot-say &> /dev/null && pbot-say '${pbotsay_msg}'" + + if (( ${#releases[@]} )); then + msg2 "Notifying pbot:" ; print " ${pbotsay_msg}" ; + ${ssh_cmd} "${pbotsay_cmd}" &> /dev/null || : + fi +} |