blob: 8c8b0cf139e8239032a05ef9036002b6703da1a0 [file] [log] [blame]
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
STABLE_VERSION=""
EMAIL_ADDRESS='<gregkh@linuxfoundation.org>'
REAL_SCRIPT=$(realpath -e "${BASH_SOURCE[0]}")
SCRIPT_TOP="${SCRIPT_TOP:-$(dirname "${REAL_SCRIPT}")}"
txtund=$(tput sgr 0 1) # Underline
txtbld=$(tput bold) # Bold
txtred=$(tput setaf 1) # Red
txtgrn=$(tput setaf 2) # Green
txtylw=$(tput setaf 3) # Yellow
txtblu=$(tput setaf 4) # Blue
txtpur=$(tput setaf 5) # Purple
txtcyn=$(tput setaf 6) # Cyan
txtwht=$(tput setaf 7) # White
txtrst=$(tput sgr0) # Text reset
extract_addr()
{
read l
read l
read l
read l
a=$(echo "$l" | sed -n -e 's/.*<\(.*@[^>]*\).*/\1/p')
echo $a
}
if [ x"$EMAIL_ADDRESS" = x ]
then
echo "You must set the EMAIL_ADDRESS environment variable to your email address"
exit 1
fi
FROM=$EMAIL_ADDRESS
TO=""
CC=""
STABLE='<stable@vger.kernel.org>'
STABLE_COMMITS='<stable-commits@vger.kernel.org>'
author()
{
first_author=""
TXT=$2
if [ ! -f $TXT ]
then
echo "$TXT is missing"
exit 1
fi
author=""
while read l
do
# skip the Message-ID: line so we don't send email to the wrong place
#echo "$l"
reply=$(echo "$l" | grep -i Message-ID:)
if [ x"$reply" != x ]
then
continue
fi
# if this is the start of the diff, then it's time to stop looking
diff=$(echo "$l" | grep "^--- ")
if [ x"$diff" != x ]
then
#echo "diffstart!!!!!"
break
fi
for x in $l
do
a=$(echo "$x" | sed -n -e 's/.*<\(.*@[^>]*\).*/\1/p')
if [ x"$a" != x ]
then
if [ x"$author" == x ]
then
author=$a
first_author=$a
else
author="$author $a"
fi
fi
done
done < $TXT
author=$(echo "$author" | tr ' ' '\n' | grep -v "$first_author" |
sort | uniq)
author="$first_author $author"
eval $1=$(echo $author | sed -e 's/ /,/g')
if [ x"$3" != x ]
then
eval $3=$first_author
fi
}
reply()
{
PATCH=$1
# patch_name=$(stripit $1)
# PATCH=$P/patches/$patch_name.patch
# TXT=$P/txt/$patch_name.txt
# if [ ! -f $TXT ]
# then
# echo $TXT is missing
# exit 1
# fi
#echo "PATCH=$PATCH"
# SUBJECT=`grep "Subject:" $PATCH`
SUBJECT=`grep "Subject:" $PATCH | sed s/Subject\:\ //`
# SUBJECT=$(head -n 2 $PATCH | tail -n 1)
MESSAGE_ID=`grep -i "^Message-ID:" $PATCH | cut -f 2 -d ' ' | cut -f 2 -d '<' | cut -f 1 -d '>'`
author AUTHOR $1 FIRST_AUTHOR
#echo "author said $AUTHOR"
#echo "first_author said $FIRST_AUTHOR"
if [ x"$AUTHOR" == "x" ]
then
echo "nobody to notify"
exit 0
fi
to=""
for i in $(echo "$AUTHOR" | sed -e 's/,/ /g')
do
if ! echo "$TO" | grep "$i"
then
to=$to" -to $i"
fi
done
if [ x"$cc" != x ]
then
cc="-cc $cc"
fi
CHARSET=$(guess-charset "$PATCH")
if test "x$CHARSET" = "ANSI_X3.4-1968"; then
CHARSET=
else
CHARCMD="-charset=$CHARSET"
fi
ID=`make_message_id`
#echo "makemail -to $AUTHOR -from=$FROM -subject=\"patch $PATCH added to gregkh tree\" -date=\"$(date -R)\" -message=$ID $CHARCMD"
echo "sending to $AUTHOR"
(
echo
echo "The patch below does not apply to the $STABLE_VERSION-stable tree."
echo "If someone wants it applied there, or to any other stable or longterm"
echo "tree, then please email the backport, including the original git commit"
echo "id to <stable@vger.kernel.org>."
echo
echo "To reproduce the conflict and resubmit, you may use the following commands:"
echo
echo "git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-$STABLE_VERSION.y"
echo "git checkout FETCH_HEAD"
echo "git cherry-pick -x $git_id"
echo "# <resolve conflicts, build, test, etc.>"
echo "git commit -s"
echo "git send-email --to '$STABLE' --in-reply-to '$ID' --subject-prefix 'PATCH $STABLE_VERSION.y' HEAD^.."
echo
echo "Possible dependencies:"
echo
echo "$(curl --fail --silent https://git.kernel.org/pub/scm/linux/kernel/git/sashal/deps.git/plain/v$STABLE_VERSION/$git_id)"
echo
echo "thanks,"
echo
echo "greg k-h"
echo
echo "------------------ original commit in Linus's tree ------------------"
echo
cat $PATCH
echo
# echo
# echo -n "Patches currently in gregkh-2.6 which might be from "
# echo "$FIRST_AUTHOR are"
# echo
# grep -lR $FIRST_AUTHOR /home/gregkh/linux/patches/ 2> /dev/null |
# sed -e 's/\/home\/gregkh\/linux\/patches\///'
) |
makemail -to "$AUTHOR" \
-from="$FROM" \
-cc="$STABLE" \
-subject="FAILED: patch \"$SUBJECT\" failed to apply to $STABLE_VERSION-stable tree" \
-date="$(date -R)" \
-message_id="$ID" \
"$CHARCMD" | \
~/bin/msmtp-enqueue.sh $to
}
git_id="$1"
shift
if [ "${git_id}" == "" ] ; then
echo "bad_stable GIT_ID KERNEL_VERSION"
echo "Must provide git id to be told is bad"
exit;
fi
full_git_id=$(git log -1 --format="%H" "${git_id}")
if [[ "${full_git_id}" == "" ]]; then
echo "git id ${git_id} not found"
exit;
fi
git_id="${full_git_id}"
echo "Commit id ${txtcyn}${git_id}${txtrst}"
queued_in=$(cd ${SCRIPT_TOP}/.. && grep -l -r ${git_id} queue-* | sort -Vr)
if [[ "${queued_in}" != "" ]]; then
for q in ${queued_in}; do
echo " queued in: ${txtgrn}${q}${txtrst}"
done
fi
lines=$(git show ${git_id} | grep -i "fixes:" | sed -e 's/^[ \t]*//' | cut -f 2 -d ':' | sed -e 's/^[ \t]*//' | cut -f 1 -d ' ')
for fix in ${lines}; do
fix_id=$(git log -1 --format="%H" "${fix}")
if [[ "${fix_id}" != "" ]]; then
#echo "fix_id=${fix_id}"
release=$(/home/gregkh/linux/vulns/tools/verhaal/id_found_in "${fix_id}")
echo " fixed in: ${txtylw}${release}${txtrst}"
fi
done
if [ "$#" == "0" ] ; then
versions=$("${SCRIPT_TOP}/active_kernel_versions_get.sh")
else
versions="$*"
fi
echo "versions=${versions}"
for STABLE_VERSION in ${versions}
do
echo "bad version = ${STABLE_VERSION}"
TMPFILE=`mktemp bad_patch.XXXXX` || exit 1
git show --pretty=email $git_id > $TMPFILE
reply $TMPFILE
rm $TMPFILE
done
#for patch_file in $*
#do
# reply $patch_file
# echo "acknowledged $patch_file"
# echo "-----------------------------------------------"
# echo
#done