abump.in 2.39 KB
Newer Older
1 2
#!/bin/sh

3 4 5 6 7 8
# abump - bump pkgver in APKBUILDs
# Copyright (c) 2012 Natanael Copa <ncopa@alpinelinux.org>
#
# Distributed under GPL-2
#

9 10
abuild_ver=@VERSION@
datadir=@datadir@
11

12 13
if ! [ -f "$datadir/functions.sh" ]; then
	echo "$datadir/functions.sh: not found" >&2
14
	exit 1
15 16 17
fi
. "$datadir/functions.sh"

18

19
# version bump packages
20
do_bump() {
Dubiousjim's avatar
Dubiousjim committed
21 22
	local p rc=0 pkgname pkgver section message
	local upgrade="${cvelist:+security }upgrade"
23
	local a
24 25 26 27
	for p; do
		pkgname=${p%-[0-9]*}
		pkgver=${p#${pkgname}-}

28 29 30 31 32 33 34
		# calculate APKBUILD's path
		if [ "${pkgname#*/}" != "$pkgname" ] && ! [ -d "$APORTSDIR/${pkgname%/*} ]; then
			error "'$p' should be of form 'foo-1.2.3' or 'main/foo-1.2.3'"
			rc=1; continue
		fi
		a=$(aports_buildscript "$pkgname" || die "can't find APKBUILD for $pkgname") || { rc=1; continue; }

35 36 37
		(
		set -e

38
		cd "${a%/*}"
Dubiousjim's avatar
Dubiousjim committed
39
		section=${PWD%/*}
40 41
		section=${section##*/}

Dubiousjim's avatar
Dubiousjim committed
42
		message="$section/$pkgname: $upgrade to ${pkgver}${cvelist}"
43 44
		if [ -n "$fixes" ]; then
			message="$message
45 46 47

fixes #${fixes#\#}
"
48 49
		fi
		echo "$message"
50

51
		( . ./APKBUILD; type package | grep -q function ) || die "package() missing"
52

53 54 55
		sed -i -e "s/^pkgver=.*/pkgver=$pkgver/" \
			-e "s/^pkgrel=.*/pkgrel=0/" \
			APKBUILD
56

57
		abuild $abuild_opts checksum all
58

59 60 61 62 63
		git add APKBUILD
		git commit -m"$message"
		) || rc=1
	done
	return $rc
64 65
}

66
usage() {
67 68 69 70 71 72 73 74 75 76 77 78
	cat >&2 <<__EOF__
$prog $abuild_ver - bump pkgver in APKBUILDs
Usage: $prog [-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
  -R, --recursive                Run abuild with -R for recursive building
  -k, --keep                     Run abuild with -k to keep existing packages
  -q, --quiet
  -h, --help                     Show this help

__EOF__
79 80
}

81 82
keep=
recursive="-r"
83 84 85
cvelist=
fixes=

86 87
[ -n "$APORTSDIR" ] || error "can't locate \$APORTSDIR"

88 89 90 91 92 93 94 95
args=`getopt -o s:Rkqh --long security:,recursive,keep,quiet,help -n "$prog" -- "$@"`
if [ $? -ne 0 ]; then
	usage
	exit 2
fi
eval set -- "$args"
while true; do
	case $1 in
Dubiousjim's avatar
Dubiousjim committed
96
		-s|--security) cvelist=" ($2)"; shift;;
97 98 99 100 101 102 103
		-f|--fixes) fixes="$2"; shift;;
		-R|--recursive) recursive="-R";;
		-k|--keep) keep="-k";;
		-q|--quiet) quiet=1;; # suppresses msg
		-h|--help) usage; exit;;
		--) shift; break;;
		*) exit 1;; # getopt error
104
	esac
105
	shift
106
done
107 108 109 110
if [ $# -eq 0 ]; then
	usage
	exit 2
fi
111

112 113
abuild_opts="$recursive $keep"

114
do_bump "$@"
115