abuild/abump.in

139 lines
2.9 KiB
Plaintext
Raw Normal View History

#!/bin/sh
# abump - bump pkgver in APKBUILDs
# Copyright (c) 2012 Natanael Copa <ncopa@alpinelinux.org>
#
2020-10-23 14:39:18 +00:00
# Distributed under GPL-2.0-only
#
program_version=@VERSION@
sharedir=${ABUILD_SHAREDIR:-@sharedir@}
if ! [ -f "$sharedir/functions.sh" ]; then
echo "$sharedir/functions.sh: not found" >&2
exit 1
fi
. "$sharedir/functions.sh"
: ${ABUILD:="abuild"}
# version bump packages
do_bump() {
local p rc=0 notbumped="" name ver section message
2013-07-05 04:21:28 +00:00
local upgrade="${cvelist:+security }upgrade"
local a
for p; do
if [ $rc -gt 0 ]; then
notbumped="$notbumped $p"
continue
fi
name=${p%-[0-9]*}
ver=${p#${name}-}
2014-10-30 08:10:39 +00:00
if [ "$name" = "$ver" ]; then
die "version missing for $p"
fi
(
set -e
# calculate APKBUILD's path #vim syntax higlight '
2013-07-09 12:57:20 +00:00
if [ "${name#*/}" != "$name" ] && ! [ -d "$APORTSDIR/${name%/*}" ]; then
die "'$p' should be of form 'foo-1.2.3' or 'main/foo-1.2.3'"
fi
a=$(aports_buildscript "$name" ) \
|| die "can't find APKBUILD for $name"
# verify APKBUILD
. "$a" || exit 1
2014-10-30 09:48:22 +00:00
name=${name#*/}
[ "$pkgname" = "$name" ] \
|| die "APKBUILD has different \$pkgname for $name"
type package | grep -q function \
|| die "missing package() for $name"
2021-04-29 10:48:24 +00:00
if [ "$pkgver" = "$ver" ] && git diff-index --quiet HEAD -- APKBUILD; then
die "version is already $ver"
fi
cd "${a%/*}"
2013-07-05 04:21:28 +00:00
section=${PWD%/*}
section=${section##*/}
message="$section/$name: $upgrade to ${ver}${cvelist}"
if [ -n "$fixes" ]; then
message="$message
fixes #${fixes#\#}
"
fi
msg "$message"
sed -i -e "s/^pkgver=.*/pkgver=$ver/" \
-e "s/^pkgrel=.*/pkgrel=0/" \
APKBUILD
$ABUILD $abuild_opts checksum all
git add APKBUILD
git commit -m"$message"
)
rc=$?
if [ $rc -gt 0 ]; then
error "Failed to build $p"
2013-07-22 13:57:14 +00:00
fi
done
if [ -n "$notbumped" ]; then
error "Not bumped: $notbumped"
2013-07-22 13:57:14 +00:00
fi
return $rc
}
usage() {
2016-08-20 13:16:48 +00:00
cat >&2 <<-__EOF__
$program $program_version - bump pkgver in APKBUILDs
Usage: $program [-s CVE-1,CVE-2,...] [-f ISSUE] [-R|--recursive] [-k|--keep] PKGNAME-1.2.3 ...
Options:
-s, --security CVE1,CVE-2,... Security update
-f, --fixes ISSUE Fixes ISSUE
-k, --keep Run abuild with -k to keep existing packages
-q, --quiet
-h, --help Show this help
__EOF__
}
keep=
cvelist=
fixes=
[ -n "$APORTSDIR" ] || error "can't locate \$APORTSDIR"
2013-07-05 04:21:32 +00:00
git rev-parse 2>/dev/null || die "not in a git tree"
args=$(getopt -o f:s:kqh --long fixes:,security:,keep,quiet,help \
-n "$program" -- "$@")
if [ $? -ne 0 ]; then
usage
exit 2
fi
eval set -- "$args"
while true; do
case $1 in
2013-07-05 04:21:28 +00:00
-s|--security) cvelist=" ($2)"; shift;;
-f|--fixes) fixes="$2"; shift;;
-k|--keep) keep="-k";;
-q|--quiet) quiet=1;; # suppresses msg
-h|--help) usage; exit;;
--) shift; break;;
*) exit 1;; # getopt error
esac
shift
done
if [ $# -eq 0 ]; then
usage
exit 2
fi
abuild_opts="${ABUILD_OPTS- -r} $keep"
do_bump "$@"