abump.in 2.81 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
program_version=@VERSION@
10
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 notbumped="" name ver section message
Dubiousjim's avatar
Dubiousjim committed
22
	local upgrade="${cvelist:+security }upgrade"
23
	local a
24
	for p; do
25 26 27 28
		if [ $rc -gt 0 ]; then
			notbumped="$notbumped $p"
			continue
		fi
29 30
		name=${p%-[0-9]*}
		ver=${p#${name}-}
31 32 33
		if [ "$name" = "$ver" ]; then
			die "version missing for $p"
		fi
34

Natanael Copa's avatar
Natanael Copa committed
35 36 37 38
		(
		set -e

		# calculate APKBUILD's path    #vim syntax higlight '
Natanael Copa's avatar
Natanael Copa committed
39
		if [ "${name#*/}" != "$name" ] && ! [ -d "$APORTSDIR/${name%/*}" ]; then
Natanael Copa's avatar
Natanael Copa committed
40
			die "'$p' should be of form 'foo-1.2.3' or 'main/foo-1.2.3'"
41
		fi
Natanael Copa's avatar
Natanael Copa committed
42 43
		a=$(aports_buildscript "$name" ) \
			|| die "can't find APKBUILD for $name"
44 45 46

		# verify APKBUILD
		. "$a" || exit 1
Natanael Copa's avatar
Natanael Copa committed
47 48 49 50
		[ "$pkgname" = "$name" ] \
			|| die "APKBUILD has different \$pkgname for $name"
		type package | grep -q function \
			|| die "missing package() for $name"
51

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

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

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

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

69
		abuild $abuild_opts checksum all
70

71 72
		git add APKBUILD
		git commit -m"$message"
Natanael Copa's avatar
Natanael Copa committed
73
		)
74 75 76
		rc=$?
		if [ $rc -gt 0 ]; then
			error "Failed to build $p"
77
		fi
78
	done
79 80
	if [ -n "$notbumped" ]; then
		error "Not bumped: $notbumped"
81
	fi
82
	return $rc
83 84
}

85
usage() {
86
	cat >&2 <<__EOF__
87
$program $program_version - bump pkgver in APKBUILDs
88
Usage: $program [-s CVE-1,CVE-2,...] [-f ISSUE] [-R|--recursive] [-k|--keep] PKGNAME-1.2.3 ...
89 90 91 92 93 94 95 96 97
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__
98 99
}

100 101
keep=
recursive="-r"
102 103 104
cvelist=
fixes=

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

108 109
args=`getopt -o f:s:Rkqh --long fixes:,security:,recursive,keep,quiet,help \
	-n "$program" -- "$@"`
110 111 112 113 114 115 116
if [ $? -ne 0 ]; then
	usage
	exit 2
fi
eval set -- "$args"
while true; do
	case $1 in
Dubiousjim's avatar
Dubiousjim committed
117
		-s|--security) cvelist=" ($2)"; shift;;
118 119 120 121 122 123 124
		-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
125
	esac
126
	shift
127
done
128 129 130 131
if [ $# -eq 0 ]; then
	usage
	exit 2
fi
132

133 134
abuild_opts="$recursive $keep"

135
do_bump "$@"
136