2010-11-06 14:06:11 +00:00
|
|
|
#!/bin/bash
|
|
|
|
AUTO=0
|
2011-05-13 20:58:36 +00:00
|
|
|
AUTO_CL=0
|
2010-11-06 14:06:11 +00:00
|
|
|
|
2011-01-22 00:15:33 +00:00
|
|
|
# Prevent environment leakage to these vars.
|
|
|
|
unset TO
|
|
|
|
unset CC
|
2011-05-13 20:58:36 +00:00
|
|
|
unset AUTO_CC
|
2011-01-22 00:15:33 +00:00
|
|
|
|
2010-11-06 14:06:11 +00:00
|
|
|
usage()
|
|
|
|
{
|
|
|
|
cat <<EOM
|
2011-05-13 20:58:36 +00:00
|
|
|
Usage: $(basename $0) [-h] [-a] [-c] [[-t email]...] -p pull-dir
|
|
|
|
-a Send the cover letter to every recipient listed in Cc and
|
|
|
|
Signed-off-by lines found in the cover letter and the patches.
|
|
|
|
This option implies -c.
|
|
|
|
-c Expand the Cc list for the individual patches using the Cc and
|
|
|
|
Signed-off-by lines from the same patch.
|
2010-11-06 14:06:11 +00:00
|
|
|
-p pull-dir Directory containing summary and patch files
|
2011-05-13 20:58:36 +00:00
|
|
|
-t email Explicitly add email to the recipients
|
2010-11-06 14:06:11 +00:00
|
|
|
EOM
|
|
|
|
}
|
|
|
|
|
2011-05-13 20:58:36 +00:00
|
|
|
# Collect addresses from a patch into AUTO_CC
|
|
|
|
# $1: a patch file
|
2010-11-06 14:06:11 +00:00
|
|
|
harvest_recipients()
|
|
|
|
{
|
2011-05-13 20:58:36 +00:00
|
|
|
PATCH=$1
|
2011-05-13 17:36:03 +00:00
|
|
|
export IFS=$',\n'
|
2011-05-13 20:58:36 +00:00
|
|
|
for REGX in "^[Cc][Cc]: *" "^[Ss]igned-[Oo]ff-[Bb]y: *"; do
|
2011-05-13 17:36:03 +00:00
|
|
|
for EMAIL in $(sed '/^---$/q' $PATCH | grep -e "$REGX" | sed "s/$REGX//"); do
|
2011-05-13 20:58:36 +00:00
|
|
|
if [ "${AUTO_CC/$EMAIL/}" == "$AUTO_CC" ] && [ -n "$EMAIL" ]; then
|
|
|
|
if [ -z "$AUTO_CC" ]; then
|
|
|
|
AUTO_CC=$EMAIL;
|
|
|
|
else
|
|
|
|
AUTO_CC="$AUTO_CC,$EMAIL";
|
|
|
|
fi
|
2011-05-13 17:36:03 +00:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
done
|
|
|
|
unset IFS
|
2010-11-06 14:06:11 +00:00
|
|
|
}
|
|
|
|
|
2011-05-13 22:42:37 +00:00
|
|
|
check_git_sendemail_config()
|
|
|
|
{
|
|
|
|
GIT_SMTP=$(git config sendemail.smtpserver)
|
|
|
|
GIT_FROM=$(git config sendemail.from)
|
|
|
|
if [ -z "$GIT_SMTP" ] || [ -z "$GIT_FROM" ]; then
|
|
|
|
echo "ERROR: git sendemail is not configured."
|
|
|
|
echo "Please read GIT-SEND-EMAIL(1) and configure:"
|
|
|
|
echo " sendemail.smtpserver"
|
|
|
|
echo " sendemail.from"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
2010-11-06 14:06:11 +00:00
|
|
|
|
|
|
|
# Parse and verify arguments
|
2011-05-13 20:58:36 +00:00
|
|
|
while getopts "achp:t:" OPT; do
|
2011-05-13 17:36:03 +00:00
|
|
|
case $OPT in
|
|
|
|
a)
|
2011-05-13 20:58:36 +00:00
|
|
|
AUTO_CL=1
|
|
|
|
AUTO=1
|
|
|
|
;;
|
|
|
|
c)
|
2011-05-13 17:36:03 +00:00
|
|
|
AUTO=1
|
|
|
|
;;
|
|
|
|
h)
|
|
|
|
usage
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
p)
|
|
|
|
PDIR=${OPTARG%/}
|
|
|
|
if [ ! -d $PDIR ]; then
|
|
|
|
echo "ERROR: pull-dir \"$PDIR\" does not exist."
|
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
t)
|
|
|
|
if [ -n "$TO" ]; then
|
|
|
|
TO="$TO,$OPTARG"
|
|
|
|
else
|
|
|
|
TO="$OPTARG"
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
2010-11-06 14:06:11 +00:00
|
|
|
done
|
|
|
|
|
2011-05-13 22:42:37 +00:00
|
|
|
# Abort early if git-send-email is not properly configured
|
|
|
|
check_git_sendemail_config
|
|
|
|
|
2010-11-06 14:06:11 +00:00
|
|
|
if [ -z "$PDIR" ]; then
|
2011-05-13 17:36:03 +00:00
|
|
|
echo "ERROR: you must specify a pull-dir."
|
|
|
|
usage
|
|
|
|
exit 1
|
2010-11-06 14:06:11 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
# Verify the cover letter is complete and free of tokens
|
|
|
|
CL="$PDIR/0000-cover-letter.patch"
|
|
|
|
for TOKEN in SUBJECT BLURB; do
|
2011-05-13 17:36:03 +00:00
|
|
|
grep -q "*** $TOKEN HERE ***" "$CL"
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
echo "ERROR: Please edit $CL and try again (Look for '*** $TOKEN HERE ***')."
|
|
|
|
exit 1
|
|
|
|
fi
|
2010-11-06 14:06:11 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
|
2011-05-13 20:58:36 +00:00
|
|
|
# Harvest emails from the generated patches and populate AUTO_CC.
|
|
|
|
if [ $AUTO_CL -eq 1 ]; then
|
|
|
|
for PATCH in $PDIR/*.patch; do
|
|
|
|
harvest_recipients $PATCH
|
|
|
|
done
|
2010-11-06 14:06:11 +00:00
|
|
|
fi
|
|
|
|
|
2011-05-13 20:33:57 +00:00
|
|
|
AUTO_TO="$(git config sendemail.to)"
|
|
|
|
if [ -n "$AUTO_TO" ]; then
|
|
|
|
if [ -n "$TO" ]; then
|
|
|
|
TO="$TO,$AUTO_TO"
|
|
|
|
else
|
|
|
|
TO="$AUTO_TO"
|
2011-05-13 17:36:03 +00:00
|
|
|
fi
|
2011-05-13 20:33:57 +00:00
|
|
|
fi
|
2010-11-06 14:06:11 +00:00
|
|
|
|
2011-05-13 20:58:36 +00:00
|
|
|
if [ -z "$TO" ] && [ -z "$AUTO_CC" ]; then
|
2011-05-13 17:36:03 +00:00
|
|
|
echo "ERROR: you have not specified any recipients."
|
|
|
|
usage
|
|
|
|
exit 1
|
2011-03-12 15:07:12 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
2010-11-06 14:06:11 +00:00
|
|
|
# Generate report for the user and require confirmation before sending
|
|
|
|
cat <<EOM
|
|
|
|
The following patches:
|
|
|
|
$(for PATCH in $PDIR/*.patch; do echo " $PATCH"; done)
|
|
|
|
|
2011-05-13 20:58:36 +00:00
|
|
|
will now be sent via the git send-email command. Git will prompt you before
|
|
|
|
sending any email.
|
2010-11-06 14:06:11 +00:00
|
|
|
|
|
|
|
EOM
|
|
|
|
echo "Continue? [y/N] "
|
|
|
|
read cont
|
|
|
|
|
|
|
|
if [ "$cont" == "y" ] || [ "$cont" == "Y" ]; then
|
2011-05-13 17:36:03 +00:00
|
|
|
ERROR=0
|
2011-05-13 20:33:57 +00:00
|
|
|
export IFS=$','
|
|
|
|
GIT_TO=$(for R in $TO; do echo -n "--to='$R' "; done)
|
2011-05-13 20:58:36 +00:00
|
|
|
GIT_CC=$(for R in $AUTO_CC; do echo -n "--cc='$R' "; done)
|
2011-05-13 20:33:57 +00:00
|
|
|
unset IFS
|
|
|
|
for PATCH in $PDIR/*patch; do
|
2011-05-13 20:58:36 +00:00
|
|
|
if [ $AUTO -eq 1 ]; then
|
|
|
|
if [ $PATCH == "$CL" ] && [ $AUTO_CL -eq 1 ]; then
|
|
|
|
# Send the cover letter to every recipient, both
|
|
|
|
# specified as well as harvested.
|
|
|
|
eval "git send-email $GIT_TO $GIT_CC --confirm=always --no-chain-reply-to --suppress-cc=all $PATCH"
|
|
|
|
else
|
|
|
|
# Send the patch to the specified recipients and
|
|
|
|
# those git finds in this specific patch.
|
|
|
|
eval "git send-email $GIT_TO --confirm=always --no-chain-reply-to --signed-off-by-cc $PATCH"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
# Only send to the explicitly specified recipients
|
|
|
|
eval "git send-email $GIT_TO --confirm=always --no-chain-reply-to --suppress-cc=all $PATCH"
|
|
|
|
fi
|
2011-05-13 20:33:57 +00:00
|
|
|
if [ $? -eq 1 ]; then
|
|
|
|
ERROR=1
|
|
|
|
fi
|
|
|
|
done
|
2011-05-13 17:36:03 +00:00
|
|
|
|
|
|
|
if [ $ERROR -eq 1 ]; then
|
2011-05-13 20:33:57 +00:00
|
|
|
echo "ERROR: Failed to send one or more messages."
|
2011-05-13 17:36:03 +00:00
|
|
|
fi
|
2010-11-06 14:06:11 +00:00
|
|
|
else
|
2011-05-13 17:36:03 +00:00
|
|
|
echo "Send aborted."
|
2010-11-06 14:06:11 +00:00
|
|
|
fi
|
|
|
|
|