[PATCH cygport] Add customization support for announce command
Christian Franke
Christian.Franke@t-online.de
Fri Feb 23 11:23:54 GMT 2024
Christian Franke wrote:
> The email generated by the cygport announce command is useful, but
> actual use cases are somewhat limited due to the hard-coded email
> submission.
>
> The attached patch adds more flexibility. The patch is on top of the
> "Use correct wording if only one package is announced" patch.
Slightly changed patch attached. Also adjusted to new version of "Use
correct wording if only one package is announced" patch.
>
> Examples for cygport.conf settings:
>
> ANNOUNCE_EDITOR='printf "\\nRegards,\\n$PN package maintainer\\n" >>"$1"'
>
> ANNOUNCE_EDITOR='
> n=$(wc -l <"$1") && cat >>"$1" <<EOF &&
>
> >>> This is an update to the latest upstream release.
> >>> This is a bugfix release.
> <<< PLEASE EDIT >>>
>
> Regards,
> $PN package maintainer
> EOF
> vim +$((n+2)) "$1" && ! grep -E "<<<|>>>" "$1"
> '
>
> ANNOUNCE_TO_CMD='cat "$1" >/dev/clipboard'
>
> ANNOUNCE_TO_CMD='
> sed "1,/^\$/d" "$1" >$PF-announcement.txt &&
> echo "Announcement placed here: $(pwd)/$PF-announcement.txt"
> '
>
> ANNOUNCE_TO_CMD='
> /usr/local/sbin/custom-mailer \
> --sender="$SMTP_SENDER" \
> --smarthost="$SMTP_SERVER" \
> ...more...options... \
> cygwin-announce@cygwin.com <"$1"
> '
>
Possible (better?) alternative names for the new settings:
ANNOUNCEMENT_EDITOR
ANNOUNCEMENT_MAILER
-------------- next part --------------
From 14709f0a1ed19c7d00588fb2a1fa7273d47e00fd Mon Sep 17 00:00:00 2001
From: Christian Franke <christian.franke@t-online.de>
Date: Fri, 23 Feb 2024 12:04:17 +0100
Subject: [PATCH] Add customization support for announce command
Two new configuration settings allow to override the launch of
a text editor (ANNOUNCE_EDITOR) and the builtin email submission
(ANNOUNCE_TO_CMD).
---
data/cygport.conf | 23 +++++++++++++++++
lib/pkg_upload.cygpart | 56 +++++++++++++++++++++++++++++++++++++-----
2 files changed, 73 insertions(+), 6 deletions(-)
diff --git a/data/cygport.conf b/data/cygport.conf
index 34ccd291..48dc7bfe 100644
--- a/data/cygport.conf
+++ b/data/cygport.conf
@@ -101,6 +101,29 @@
#PAGER=
+#****v* Configuration/ANNOUNCE_EDITOR
+# DESCRIPTION
+# Shell command string to process the email message created by cygport's
+# announce command before sending the email. If undefined, a text editor
+# will be run, see EDITOR setting above. If empty, nothing will be run.
+# If not empty, '/bin/bash' will be launched with the command string passed
+# with '-c' option and the path of the temporary email message file as '$1'.
+# The working directory of the shell will be the directory of the cygport
+# file. The specified command string will be prepended by shell assignments
+# of the cygport variables P, PF, PN, PR and PV and all SMTP_* settings
+# described below.
+#ANNOUNCE_EDITOR=
+
+#****v* Configuration/ANNOUNCE_TO_CMD
+# DESCRIPTION
+# Shell command string to process the email message created by cygport's
+# announce command after editing. If undefined, the email will be sent
+# using the builtin perl-based SMTP support. If empty, nothing will be run.
+# If not empty, the command string will be handled similar to ANNOUNCE_EDITOR
+# described above.
+#ANNOUNCE_TO_CMD=
+
+
#****v* Configuration/SMTP_SENDER
# DESCRIPTION
# Name and email address, in the form of "First Last <user@domain>" to be used
diff --git a/lib/pkg_upload.cygpart b/lib/pkg_upload.cygpart
index 37bc2d63..d38ea8b6 100644
--- a/lib/pkg_upload.cygpart
+++ b/lib/pkg_upload.cygpart
@@ -168,6 +168,33 @@ EOF
echo "Upload complete."
}
+__pkg_announce_run_cmd_on_msg() {
+ local cmdvar=$1
+ local msg=$2
+ local cmd
+
+ eval cmd="\${${cmdvar}}"
+
+ if [ "${cmd:+y}" != "y" ]
+ then
+ inform "\${${cmdvar}} is empty"
+ return 0
+ fi
+ echo
+ inform "Launching '\${${cmdvar}} ${msg}'"
+
+ /bin/bash -c "cd ${top} || exit 1
+P=${P@Q}; PF=${PF@Q}; PN=${PN@Q}; PR=${PR@Q}; PV=(${PV[*]@Q})
+${SMTP_SENDER+SMTP_SENDER=${SMTP_SENDER@Q}}
+${SMTP_SERVER+SMTP_SERVER=${SMTP_SERVER@Q}}
+${SMTP_SERVER_PORT+SMTP_SERVER_PORT=${SMTP_SERVER_PORT@Q}}
+${SMTP_ENCRYPTION+SMTP_ENCRYPTION=${SMTP_ENCRYPTION@Q}}
+${SMTP_USER+SMTP_USER=${SMTP_USER@Q}}
+${SMTP_PASS+SMTP_PASS=${SMTP_PASS@Q}}
+${cmd}
+" $0 ${msg} || error "Command '\${${cmdvar}} ${msg}' (cwd=${top}) failed"
+}
+
__pkg_announce() {
local msg=$(mktemp -t cygwin-announce-${PF}.XXXXXX)
local msgat=$(date +@%s)
@@ -178,10 +205,10 @@ __pkg_announce() {
cat > ${msg} <<_EOF
From cygwin-announce-${PF} $(date '+%a %b %d %H:%M:%S %Y' --date=${msgat})
-From: ${SMTP_SENDER}
-To: cygwin-announce@cygwin.com
+${SMTP_SENDER:+From: ${SMTP_SENDER}
+}To: cygwin-announce@cygwin.com
Date: $(date -R --date=${msgat})
-Message-Id: <$(date "+%Y%m%d%H%M%S.$$" --date=${msgat})-1-$(echo ${SMTP_SENDER} | sed 's|.*<\(.*\)>.*|\1|')>
+Message-Id: <$(date "+%Y%m%d%H%M%S.$$" --date=${msgat})-1-$(echo ${SMTP_SENDER:-cygport} | sed 's|.*<\(.*\)>.*|\1|')>
Subject: ${NAME} ${PVR}
The following package${s_have} been uploaded to the Cygwin distribution:
@@ -199,7 +226,24 @@ _EOF
${DESCRIPTION}
_EOF
- ${EDITOR:-vi} $msg || error "Editor exited abormally, aborting annoucement"
+ if [ "${ANNOUNCE_EDITOR+y}" = "y" ]
+ then
+ __pkg_announce_run_cmd_on_msg ANNOUNCE_EDITOR ${msg}
+ else
+ ${EDITOR:-vi} ${msg} || error "Editor exited abnormally, aborting announcement"
+ fi
+
+ if [ "${ANNOUNCE_TO_CMD+y}" = "y" ]
+ then
+ __pkg_announce_run_cmd_on_msg ANNOUNCE_TO_CMD ${msg}
+ else
+ __pkg_announce_to_smtp ${msg}
+ fi
+ rm ${msg}
+}
+
+__pkg_announce_to_smtp() {
+ local msg=$1
perl <(cat <<EOF
use strict;
@@ -242,8 +286,8 @@ if (defined \$smtp_user) {
\$smtp->quit();
print "Announcement sent\n";
EOF
-) && rm $msg || error "Sending announcement failed, mbox is $msg"
+) || error "Sending announcement failed, mbox is $msg"
}
# protect functions
-readonly -f __pkg_upload __pkg_announce
+readonly -f __pkg_upload __pkg_announce __pkg_announce_run_cmd_on_msg __pkg_announce_to_smtp
--
2.43.0
More information about the Cygwin-apps
mailing list