abump.in 2.08 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 20 21

# version bump a pkg

do_bump() {
22 23
	local pkgname=${1%-[0-9]*}
	local pkgver=${1#${pkgname}-}
24 25 26 27 28

	APORTS=$HOME/aports

	set -e

29
	cd $APORTS/*/$pkgname || return 1
30
	local section=${PWD%/*} upgrade="upgrade" cve=
31
	section=${section##*/}
32 33 34 35
	if [ -n "$cvelist" ]; then
		upgrade="security upgrade"
		cve=" ($cvelist)"
	fi
36

37
	message="$section/$pkgname: $upgrade to ${pkgver}${cve}"
38
	if [ -n "$fixes" ]; then
39
		message="$message
40 41 42 43

fixes #${fixes#\#}
"
	fi
44
	echo "$message"
45

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

48 49 50 51
	sed -i -e "s/^pkgver=.*/pkgver=$pkgver/" \
		-e "s/^pkgrel=.*/pkgrel=0/" \
		APKBUILD

52
	abuild $abuild_opts checksum all || exit 1
53 54

	git add APKBUILD
55
	git commit -m"$message"
56 57
}

58
usage() {
59 60 61 62 63 64 65 66 67 68 69 70
	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__
71 72
}

73 74
keep=
recursive="-r"
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
cvelist=
fixes=

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
		-s|--security) cvelist="$2"; shift;;
		-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
94
	esac
95
	shift
96
done
97 98 99 100
if [ $# -eq 0 ]; then
	usage
	exit 2
fi
101

102 103
abuild_opts="$recursive $keep"

104 105 106 107
while [ $# -gt 0 ]; do
	( do_bump "$1" ) || exit 1
	shift
done
108