summaryrefslogtreecommitdiffstats
path: root/meta/classes/sign_package_feed.bbclass
blob: 7ff3a35a2fa88c475404306bc7c367dd2ccf3abf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# Class for signing package feeds
#
# Related configuration variables that will be used after this class is
# iherited:
# PACKAGE_FEED_PASSPHRASE_FILE
#           Path to a file containing the passphrase of the signing key.
# PACKAGE_FEED_GPG_NAME
#           Name of the key to sign with. May be key id or key name.
# PACKAGE_FEED_GPG_BACKEND
#           Optional variable for specifying the backend to use for signing.
#           Currently the only available option is 'local', i.e. local signing
#           on the build host.
# PACKAGE_FEED_GPG_SIGNATURE_TYPE
#           Optional variable for specifying the type of gpg signature, can be:
#               1. Ascii armored (ASC), default if not set
#               2. Binary (BIN)
#           This variable is only available for IPK feeds. It is ignored on
#           other packaging backends.
# GPG_BIN
#           Optional variable for specifying the gpg binary/wrapper to use for
#           signing.
# GPG_PATH
#           Optional variable for specifying the gnupg "home" directory:
#
inherit sanity

PACKAGE_FEED_SIGN = '1'
PACKAGE_FEED_GPG_BACKEND ?= 'local'
PACKAGE_FEED_GPG_SIGNATURE_TYPE ?= 'ASC'

# Make feed signing key to be present in rootfs
FEATURE_PACKAGES_package-management_append = " signing-keys-packagefeed"

python () {
    # Check sanity of configuration
    for var in ('PACKAGE_FEED_GPG_NAME', 'PACKAGE_FEED_GPG_PASSPHRASE_FILE'):
        if not d.getVar(var):
            raise_sanity_error("You need to define %s in the config" % var, d)

    sigtype = d.getVar("PACKAGE_FEED_GPG_SIGNATURE_TYPE")
    if sigtype.upper() != "ASC" and sigtype.upper() != "BIN":
        raise_sanity_error("Bad value for PACKAGE_FEED_GPG_SIGNATURE_TYPE (%s), use either ASC or BIN" % sigtype)
}

do_package_index[depends] += "signing-keys:do_deploy"
do_rootfs[depends] += "signing-keys:do_populate_sysroot gnupg-native:do_populate_sysroot"
Name.Function.Magic */ .highlight .vc { color: #f8f8f2 } /* Name.Variable.Class */ .highlight .vg { color: #f8f8f2 } /* Name.Variable.Global */ .highlight .vi { color: #f8f8f2 } /* Name.Variable.Instance */ .highlight .vm { color: #f8f8f2 } /* Name.Variable.Magic */ .highlight .il { color: #ae81ff } /* Literal.Number.Integer.Long */ } @media (prefers-color-scheme: light) { .highlight .hll { background-color: #ffffcc } .highlight .c { color: #888888 } /* Comment */ .highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */ .highlight .k { color: #008800; font-weight: bold } /* Keyword */ .highlight .ch { color: #888888 } /* Comment.Hashbang */ .highlight .cm { color: #888888 } /* Comment.Multiline */ .highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */ .highlight .cpf { color: #888888 } /* Comment.PreprocFile */ .highlight .c1 { color: #888888 } /* Comment.Single */ .highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */ .highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */ .highlight .ge { font-style: italic } /* Generic.Emph */ .highlight .gr { color: #aa0000 } /* Generic.Error */ .highlight .gh { color: #333333 } /* Generic.Heading */ .highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */ .highlight .go { color: #888888 } /* Generic.Output */ .highlight .gp { color: #555555 } /* Generic.Prompt */ .highlight .gs { font-weight: bold } /* Generic.Strong */ .highlight .gu { color: #666666 } /* Generic.Subheading */ .highlight .gt { color: #aa0000 } /* Generic.Traceback */ .highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */ }
#!/bin/sh
#
# Copyright (c) 2010-2013,  Intel Corporation.
#
# SPDX-License-Identifier: GPL-2.0-or-later
#

#
# This script is intended to be used to prepare a series of patches
# and a cover letter in an appropriate and consistent format for
# submission to Open Embedded and The Yocto Project, as well as to
# related projects and layers.
#

ODIR=pull-$$
RELATIVE_TO="master"
COMMIT_ID="HEAD"
PREFIX="PATCH"
RFC=0

usage() {
CMD=$(basename $0)
cat <<EOM
Usage: $CMD [-h] [-o output_dir] [-m msg_body_file] [-s subject] [-r relative_to] [-i commit_id] [-d relative_dir] -u remote [-b branch] [-- <format-patch options>]
  -b branch           Branch name in the specified remote (default: current branch)
  -l local branch     Local branch name (default: HEAD)
  -c                  Create an RFC (Request for Comment) patch series
  -h                  Display this help message
  -a                  Automatically push local branch (-l) to remote branch (-b),
                      or set CPR_CONTRIB_AUTO_PUSH in env
  -i commit_id        Ending commit (default: HEAD)
  -m msg_body_file    The file containing a blurb to be inserted into the summary email
  -o output_dir       Specify the output directory for the messages (default: pull-PID)
  -p prefix           Use [prefix N/M] instead of [PATCH N/M] as the subject prefix
  -r relative_to      Starting commit (default: master)
  -s subject          The subject to be inserted into the summary email
  -u remote           The git remote where the branch is located, or set CPR_CONTRIB_REMOTE in env
  -d relative_dir     Generate patches relative to directory

 Examples:
   $CMD -u contrib -b nitin/basic
   $CMD -u contrib -r distro/master -i nitin/distro -b nitin/distro
   $CMD -u contrib -r distro/master -i nitin/distro -b nitin/distro -l distro
   $CMD -u contrib -r master -i misc -b nitin/misc -o pull-misc
   $CMD -u contrib -p "RFC PATCH" -b nitin/experimental
   $CMD -u contrib -i misc -b nitin/misc -d ./bitbake
   $CMD -u contrib -r origin/master -o /tmp/out.v3 -- -v3 --in-reply-to=20170511120134.XX7799@site.com
EOM
}

REMOTE="$CPR_CONTRIB_REMOTE"
# Parse and validate arguments
while getopts "b:acd:hi:m:o:p:r:s:u:l:" OPT; do
	case $OPT in
	b)
		BRANCH="$OPTARG"
		;;
	l)
		L_BRANCH="$OPTARG"
		;;
	c)
		RFC=1
		;;
	d)
		RELDIR="$OPTARG"
		;;
	h)
		usage
		exit 0
		;;
	i)
		COMMIT_ID="$OPTARG"
		;;
	m)
		BODY="$OPTARG"
		if [ ! -e "$BODY" ]; then
			echo "ERROR: Body file does not exist"
			exit 1
		fi
		;;
	o)
		ODIR="$OPTARG"
		;;
	p)
		PREFIX="$OPTARG"
		;;
	r)
		RELATIVE_TO="$OPTARG"
		;;
	s)
		SUBJECT="$OPTARG"
		;;
	u)
		REMOTE="$OPTARG"
		;;
	a)
		CPR_CONTRIB_AUTO_PUSH="1"
		;;
	--)
		shift
		break
		;;
	esac
done

shift "$((OPTIND - 1))"
extraopts="$@"

if [ -z "$REMOTE" ]; then
	echo "ERROR: Missing parameter -u or CPR_CONTRIB_REMOTE in env, no git remote!"
	usage
	exit 1
fi

REMOTE_URL=$(git config remote.$REMOTE.url)
if [ $? -ne 0 ]; then
	echo "ERROR: git config failed to find a url for '$REMOTE'"
	echo
	echo "To add a remote url for $REMOTE, use:"
	echo "  git config remote.$REMOTE.url <url>"
	exit 1
fi

# Rewrite private URLs to public URLs
# Determine the repository name for use in the WEB_URL later
USER_RE="[A-Za-z0-9_.@][A-Za-z0-9_.@-]*\$\?"
PROTO_RE="[a-z][a-z+]*://"
GIT_RE="\(^\($PROTO_RE\)\?\)\($USER_RE@\)\?\([^:/]*\)[:/]\(.*\)"
REMOTE_URL=${REMOTE_URL%.git}
REMOTE_REPO=$(echo $REMOTE_URL | sed "s#$GIT_RE#\5#")
REMOTE_URL=$(echo $REMOTE_URL | sed "s#$GIT_RE#https://\4/\5#")

if [ -z "$BRANCH" ]; then
	BRANCH=$(git branch | grep -e "^\* " | cut -d' ' -f2)
	echo "NOTE: Assuming remote branch '$BRANCH', use -b to override."
fi

if [ -z "$L_BRANCH" ]; then
	L_BRANCH=HEAD
	echo "NOTE: Assuming local branch HEAD, use -l to override."
fi

if [ $RFC -eq 1 ]; then
	PREFIX="RFC $PREFIX"
fi


# Set WEB_URL from known remotes
WEB_URL=""
case "$REMOTE_URL" in
	*git.yoctoproject.org*)
		WEB_URL="https://git.yoctoproject.org/$REMOTE_REPO/log/?h=$BRANCH"
		;;
	*git.openembedded.org*)
		WEB_URL="https://git.openembedded.org/$REMOTE_REPO/log/?h=$BRANCH"
		;;
	*github.com*)
		WEB_URL="https://github.com/$REMOTE_REPO/tree/$BRANCH"
		;;
esac

# Perform a sanity test on the web URL. Issue a warning if it is not
# accessible, but do not abort as users may want to run offline.
if [ -n "$WEB_URL" ]; then
	if [ "$CPR_CONTRIB_AUTO_PUSH" = "1" ]; then
		echo "Pushing '$BRANCH' on '$REMOTE' as requested..."
		git push $REMOTE $L_BRANCH:$BRANCH
		echo ""
	fi
	wget --no-check-certificate -q $WEB_URL -O /dev/null
	if [ $? -ne 0 ]; then
		echo "WARNING: Branch '$BRANCH' was not found on the contrib git tree."
		echo "         Please check your remote and branch parameter before sending."
		echo ""
	fi
fi

if [ -e $ODIR ]; then
	echo "ERROR: output directory $ODIR exists."
	exit 1
fi
mkdir $ODIR

if [ -n "$RELDIR" ]; then
	ODIR=$(realpath $ODIR)
	pdir=$(pwd)
	cd $RELDIR
	extraopts="$extraopts --relative"
fi

# Generate the patches and cover letter
git format-patch $extraopts -M40 --subject-prefix="$PREFIX" -n -o $ODIR --thread=shallow --cover-letter $RELATIVE_TO..$COMMIT_ID > /dev/null

if [ -z "$(ls -A $ODIR 2> /dev/null)" ]; then
    echo "ERROR: $ODIR is empty, no cover letter and patches was generated!"
    echo "       This is most likely due to that \$RRELATIVE_TO..\$COMMIT_ID"
    echo "       ($RELATIVE_TO..$COMMIT_ID) don't contain any differences."
    rmdir $ODIR
    exit 1
fi

[ -n "$RELDIR" ] && cd $pdir

# Customize the cover letter
CL="$(echo $ODIR/*0000-cover-letter.patch)"
PM="$ODIR/pull-msg"
GIT_VERSION=$(`git --version` | tr -d '[:alpha:][:space:].' | sed 's/\(...\).*/\1/')
NEWER_GIT_VERSION=210
if [ $GIT_VERSION -lt $NEWER_GIT_VERSION ]; then
	git request-pull $RELATIVE_TO $REMOTE_URL $COMMIT_ID >> "$PM"
else
	git request-pull $RELATIVE_TO $REMOTE_URL $L_BRANCH:$BRANCH >> "$PM"
fi
if [ $? -ne 0 ]; then
	echo "ERROR: git request-pull reported an error"
	rm -rf $ODIR
	exit 1
fi

# The cover letter already has a diffstat, remove it from the pull-msg
# before inserting it.
sed -n "0,\#$REMOTE_URL# p" "$PM" | sed -i "/BLURB HERE/ r /dev/stdin" "$CL"
rm "$PM"

# If this is an RFC, make that clear in the cover letter
if [ $RFC -eq 1 ]; then
(cat <<EOM
Please review the following changes for suitability for inclusion. If you have
any objections or suggestions for improvement, please respond to the patches. If
you agree with the changes, please provide your Acked-by.

EOM
) | sed -i "/BLURB HERE/ r /dev/stdin" "$CL"
fi

# Insert the WEB_URL if there is one
if [ -n "$WEB_URL" ]; then
	echo "  $WEB_URL" | sed -i "\#$REMOTE_URL# r /dev/stdin" "$CL"
fi


# If the user specified a message body, insert it into the cover letter and
# remove the BLURB token.
if [ -n "$BODY" ]; then
	sed -i "/BLURB HERE/ r $BODY" "$CL"
	sed -i "/BLURB HERE/ d" "$CL"
fi

# Set subject automatically if there is only one patch
patch_cnt=`git log --pretty=oneline ${RELATIVE_TO}..${L_BRANCH} | wc -l`
if [ -z "$SUBJECT" -a $patch_cnt -eq 1 ]; then
    SUBJECT="`git log --format=%s ${RELATIVE_TO}..${L_BRANCH}`"
fi

# Replace the SUBJECT token with it.
if [ -n "$SUBJECT" ]; then
	sed -i -e "s\`\*\*\* SUBJECT HERE \*\*\*\`$SUBJECT\`" "$CL"
fi


# Generate report for user
cat <<EOM
The following patches have been prepared:
$(for PATCH in $(ls $ODIR/*); do echo "    $PATCH"; done)

Review their content, especially the summary mail:
    $CL

When you are satisfied, you can send them with:
    send-pull-request -a -p $ODIR
EOM

# Check the patches for trailing white space
egrep -q -e "^\+.*\s+$" $ODIR/*
if [ $? -ne 1 ]; then
	echo
	echo "WARNING: Trailing white space detected at these locations"
	egrep -nH --color -e "^\+.*\s+$" $ODIR/*
fi