abump.in 2.87 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
: ${ABUILD:="abuild"}

20

21
# version bump packages
22
do_bump() {
23
	local p rc=0 notbumped="" name ver section message
24
	local upgrade="${cvelist:+security }upgrade"
25
	local a
26
	for p; do
27 28 29 30
		if [ $rc -gt 0 ]; then
			notbumped="$notbumped $p"
			continue
		fi
31 32
		name=${p%-[0-9]*}
		ver=${p#${name}-}
33 34 35
		if [ "$name" = "$ver" ]; then
			die "version missing for $p"
		fi
36

Natanael Copa's avatar
Natanael Copa committed
37 38 39 40
		(
		set -e

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

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

55
		cd "${a%/*}"
56
		section=${PWD%/*}
57 58
		section=${section##*/}

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

fixes #${fixes#\#}
"
65
		fi
66
		msg "$message"
67

68
		sed -i -e "s/^pkgver=.*/pkgver=$ver/" \
69 70
			-e "s/^pkgrel=.*/pkgrel=0/" \
			APKBUILD
71

72
		$ABUILD $abuild_opts checksum all
73

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

88
usage() {
89 90 91 92 93 94 95 96 97 98 99 100
	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
		  -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__
101 102
}

103 104
keep=
recursive="-r"
105 106 107
cvelist=
fixes=

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

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

136 137
abuild_opts="$recursive $keep"

138
do_bump "$@"