abump.in 2.73 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() {
21
	local p rc=0 name ver section message
Dubiousjim's avatar
Dubiousjim committed
22
	local upgrade="${cvelist:+security }upgrade"
23
	local a
24
	for p; do
25 26
		name=${p%-[0-9]*}
		ver=${p#${name}-}
27

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

		# verify APKBUILD
		(
		. "$a" || exit 1
38 39
		[ "$pkgname" = "$name" ] || die "APKBUILD has different \$pkgname for $name"
		type package | grep -q function || die "missing package() for $name"
Dubiousjim's avatar
Dubiousjim committed
40
		case $(apk version --test "$pkgver" "$ver") in
41 42
		'=') die "$pkgname is already at version $pkgver";;
		'>') die "$pkgname is already at newer version $pkgver";;
Dubiousjim's avatar
Dubiousjim committed
43 44 45
		'<') exit 0;;
		*) exit 1;;
		esac
46
		) || { rc=1; continue; }
47

48 49 50
		(
		set -e

51
		cd "${a%/*}"
Dubiousjim's avatar
Dubiousjim committed
52
		section=${PWD%/*}
53 54
		section=${section##*/}

55
		message="$section/$name: $upgrade to ${ver}${cvelist}"
56 57
		if [ -n "$fixes" ]; then
			message="$message
58 59 60

fixes #${fixes#\#}
"
61
		fi
62
		msg "$message"
63

64
		sed -i -e "s/^pkgver=.*/pkgver=$ver/" \
65 66
			-e "s/^pkgrel=.*/pkgrel=0/" \
			APKBUILD
67

68
		abuild $abuild_opts checksum all
69

70 71 72 73 74
		git add APKBUILD
		git commit -m"$message"
		) || rc=1
	done
	return $rc
75 76
}

77
usage() {
78 79 80 81 82 83 84 85 86 87 88 89
	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__
90 91
}

92 93
keep=
recursive="-r"
94 95 96
cvelist=
fixes=

97
[ -n "$APORTSDIR" ] || error "can't locate \$APORTSDIR"
98
git rev-parse 2>/dev/null || die "not in a git tree"
99

100 101 102 103 104 105 106 107
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
108
		-s|--security) cvelist=" ($2)"; shift;;
109 110 111 112 113 114 115
		-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
116
	esac
117
	shift
118
done
119 120 121 122
if [ $# -eq 0 ]; then
	usage
	exit 2
fi
123

124 125
abuild_opts="$recursive $keep"

126
do_bump "$@"
127