| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | #!/bin/bash | 
 | 2 | # | 
 | 3 | # Copyright (c) 2010-2011,  Intel Corporation. | 
 | 4 | # All Rights Reserved | 
 | 5 | #  | 
 | 6 | # This program is free software;  you can redistribute it and/or modify | 
 | 7 | # it under the terms of the GNU General Public License as published by | 
 | 8 | # the Free Software Foundation; either version 2 of the License, or | 
 | 9 | # (at your option) any later version. | 
 | 10 | # | 
 | 11 | # This program is distributed in the hope that it will be useful, | 
 | 12 | # but WITHOUT ANY WARRANTY;  without even the implied warranty of | 
 | 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See | 
 | 14 | # the GNU General Public License for more details. | 
 | 15 | # | 
 | 16 | # You should have received a copy of the GNU General Public License | 
 | 17 | # along with this program;  if not, write to the Free Software | 
 | 18 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 
 | 19 | # | 
 | 20 |  | 
 | 21 | # | 
 | 22 | # This script is intended to be used to send a patch series prepared by the | 
 | 23 | # create-pull-request script to Open Embedded and The Yocto Project, as well | 
 | 24 | # as to related projects and layers. | 
 | 25 | # | 
 | 26 |  | 
 | 27 | AUTO=0 | 
 | 28 | AUTO_CL=0 | 
 | 29 | GITSOBCC="--suppress-cc=all" | 
 | 30 |  | 
 | 31 | # Prevent environment leakage to these vars. | 
 | 32 | unset TO | 
 | 33 | unset CC | 
 | 34 | unset AUTO_CC | 
 | 35 | unset EXTRA_CC | 
 | 36 |  | 
 | 37 | usage() | 
 | 38 | { | 
 | 39 | cat <<EOM | 
 | 40 | Usage: $(basename $0) [-h] [-a] [-c] [[-t email]...] -p pull-dir  | 
 | 41 |   -a           Send the cover letter to every recipient listed in Cc and | 
 | 42 |                Signed-off-by lines found in the cover letter and the patches. | 
 | 43 | 	       This option implies -c. | 
 | 44 |   -c           Expand the Cc list for the individual patches using the Cc and | 
 | 45 |                Signed-off-by lines from the same patch. | 
 | 46 |   -C           Add extra CC to each email sent. | 
 | 47 |   -p pull-dir  Directory containing summary and patch files | 
 | 48 |   -t email     Explicitly add email to the recipients | 
 | 49 | EOM | 
 | 50 | } | 
 | 51 |  | 
 | 52 | # Collect addresses from a patch into AUTO_CC | 
 | 53 | # $1: a patch file | 
 | 54 | harvest_recipients() | 
 | 55 | { | 
 | 56 | 	PATCH=$1 | 
 | 57 | 	export IFS=$',\n' | 
 | 58 | 	for REGX in "^[Cc][Cc]: *" "^[Ss]igned-[Oo]ff-[Bb]y: *"; do | 
 | 59 | 		for EMAIL in $(sed '/^---$/q' $PATCH | grep -e "$REGX" | sed "s/$REGX//"); do | 
 | 60 | 			if [ "${AUTO_CC/$EMAIL/}" == "$AUTO_CC" ] && [ -n "$EMAIL" ]; then | 
 | 61 | 				if [ -z "$AUTO_CC" ]; then | 
 | 62 | 					AUTO_CC=$EMAIL; | 
 | 63 | 				else | 
 | 64 | 					AUTO_CC="$AUTO_CC,$EMAIL"; | 
 | 65 | 				fi | 
 | 66 | 			fi | 
 | 67 | 		done | 
 | 68 | 	done | 
 | 69 | 	unset IFS | 
 | 70 | } | 
 | 71 |  | 
 | 72 | # Parse and verify arguments | 
 | 73 | while getopts "acC:hp:t:" OPT; do | 
 | 74 | 	case $OPT in | 
 | 75 | 	a) | 
 | 76 | 		AUTO=1 | 
 | 77 | 		GITSOBCC="--signed-off-by-cc" | 
 | 78 | 		AUTO_CL=1 | 
 | 79 | 		;; | 
 | 80 | 	c) | 
 | 81 | 		AUTO=1 | 
 | 82 | 		GITSOBCC="--signed-off-by-cc" | 
 | 83 | 		;; | 
 | 84 | 	C) | 
 | 85 | 		EXTRA_CC="$OPTARG" | 
 | 86 | 		;; | 
 | 87 | 	h) | 
 | 88 | 		usage | 
 | 89 | 		exit 0 | 
 | 90 | 		;; | 
 | 91 | 	p) | 
 | 92 | 		PDIR=${OPTARG%/} | 
 | 93 | 		if [ ! -d $PDIR ]; then | 
 | 94 | 			echo "ERROR: pull-dir \"$PDIR\" does not exist." | 
 | 95 | 			usage | 
 | 96 | 			exit 1 | 
 | 97 | 		fi | 
 | 98 | 		;; | 
 | 99 | 	t) | 
 | 100 | 		if [ -n "$TO" ]; then | 
 | 101 | 			TO="$TO,$OPTARG" | 
 | 102 | 		else | 
 | 103 | 			TO="$OPTARG" | 
 | 104 | 		fi | 
 | 105 | 		;; | 
 | 106 | 	esac | 
 | 107 | done | 
 | 108 |  | 
 | 109 | if [ -z "$PDIR" ]; then | 
 | 110 | 	echo "ERROR: you must specify a pull-dir." | 
 | 111 | 	usage | 
 | 112 | 	exit 1 | 
 | 113 | fi | 
 | 114 |  | 
 | 115 |  | 
 | 116 | # Verify the cover letter is complete and free of tokens | 
 | 117 | if [ -e $PDIR/0000-cover-letter.patch ]; then | 
 | 118 | 	CL="$PDIR/0000-cover-letter.patch" | 
 | 119 | 	for TOKEN in SUBJECT BLURB; do | 
 | 120 | 		grep -q "*** $TOKEN HERE ***" "$CL" | 
 | 121 | 		if [ $? -eq 0 ]; then | 
 | 122 | 			echo "ERROR: Please edit $CL and try again (Look for '*** $TOKEN HERE ***')." | 
 | 123 | 			exit 1 | 
 | 124 | 		fi | 
 | 125 | 	done | 
 | 126 | else | 
 | 127 | 	echo "WARNING: No cover letter will be sent." | 
 | 128 | fi | 
 | 129 |  | 
 | 130 | # Harvest emails from the generated patches and populate AUTO_CC. | 
 | 131 | if [ $AUTO_CL -eq 1 ]; then | 
 | 132 | 	for PATCH in $PDIR/*.patch; do | 
 | 133 | 		harvest_recipients $PATCH | 
 | 134 | 	done | 
 | 135 | fi | 
 | 136 |  | 
 | 137 | AUTO_TO="$(git config sendemail.to)" | 
 | 138 | if [ -n "$AUTO_TO" ]; then | 
 | 139 | 	if [ -n "$TO" ]; then | 
 | 140 | 		TO="$TO,$AUTO_TO" | 
 | 141 | 	else | 
 | 142 | 		TO="$AUTO_TO" | 
 | 143 | 	fi | 
 | 144 | fi | 
 | 145 |  | 
 | 146 | if [ -z "$TO" ] && [ -z "$AUTO_CC" ]; then | 
 | 147 | 	echo "ERROR: you have not specified any recipients." | 
 | 148 | 	usage | 
 | 149 | 	exit 1 | 
 | 150 | fi | 
 | 151 |  | 
 | 152 |  | 
 | 153 | # Convert the collected addresses into git-send-email argument strings | 
 | 154 | export IFS=$',' | 
 | 155 | GIT_TO=$(for R in $TO; do echo -n "--to='$R' "; done) | 
 | 156 | GIT_CC=$(for R in $AUTO_CC; do echo -n "--cc='$R' "; done) | 
 | 157 | GIT_EXTRA_CC=$(for R in $EXTRA_CC; do echo -n "--cc='$R' "; done) | 
 | 158 | unset IFS | 
 | 159 |  | 
 | 160 | # Handoff to git-send-email. It will perform the send confirmation. | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 161 | # Mail threading was already handled by git-format-patch in | 
 | 162 | # create-pull-request, so we must not allow git-send-email to | 
 | 163 | # add In-Reply-To and References headers again. | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 164 | PATCHES=$(echo $PDIR/*.patch) | 
 | 165 | if [ $AUTO_CL -eq 1 ]; then | 
 | 166 | 	# Send the cover letter to every recipient, both specified as well as | 
 | 167 | 	# harvested. Then remove it from the patches list. | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 168 | 	# --no-thread is redundant here (only sending a single message) and | 
 | 169 | 	# merely added for the sake of consistency. | 
 | 170 | 	eval "git send-email $GIT_TO $GIT_CC $GIT_EXTRA_CC --confirm=always --no-thread --suppress-cc=all $CL" | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 171 | 	if [ $? -eq 1 ]; then | 
 | 172 | 		echo "ERROR: failed to send cover-letter with automatic recipients." | 
 | 173 | 		exit 1 | 
 | 174 | 	fi | 
 | 175 | 	PATCHES=${PATCHES/"$CL"/} | 
 | 176 | fi | 
 | 177 |  | 
 | 178 | # Send the patch to the specified recipients and, if -c was specified, those git | 
 | 179 | # finds in this specific patch. | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 180 | eval "git send-email $GIT_TO $GIT_EXTRA_CC --confirm=always --no-thread $GITSOBCC $PATCHES" | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 181 | if [ $? -eq 1 ]; then | 
 | 182 | 	echo "ERROR: failed to send patches." | 
 | 183 | 	exit 1 | 
 | 184 | fi |