-
Notifications
You must be signed in to change notification settings - Fork 52
/
abump.in
143 lines (121 loc) · 3.06 KB
/
abump.in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/bin/sh
# abump - bump pkgver in APKBUILDs
# Copyright (c) 2012 Natanael Copa <[email protected]>
#
# Distributed under GPL-2.0-only
#
program_version=@VERSION@
sharedir=${ABUILD_SHAREDIR:-@sharedir@}
if ! [ -f "$sharedir/functions.sh" ]; then
echo "$sharedir/functions.sh: not found" >&2
exit 1
fi
. "$sharedir/functions.sh"
: ${ABUILD:="abuild"}
# version bump packages
do_bump() {
local p rc=0 notbumped="" name ver section message
local upgrade="${cvelist:+security }upgrade"
local a
for p; do
if [ $rc -gt 0 ]; then
notbumped="$notbumped $p"
continue
fi
name=${p%-[0-9]*}
ver=${p#${name}-}
if [ "$name" = "$ver" ]; then
die "version missing for $p"
fi
(
set -e
# calculate APKBUILD's path #vim syntax highlight '
if [ "${name#*/}" != "$name" ] && ! [ -d "$APORTSDIR/${name%/*}" ]; then
die "'$p' should be of form 'foo-1.2.3' or 'main/foo-1.2.3'"
fi
a=$(aports_buildscript "$name" ) \
|| die "can't find APKBUILD for $name"
# sourcing APKBUILDs should not affect the environment of abump
# so do that in a subshell, along with any checks that need the
# information from the APKBUILD.
(
# verify APKBUILD
. "$a" || exit 1
name=${name#*/}
[ "$pkgname" = "$name" ] \
|| die "APKBUILD has different \$pkgname for $name"
type package | grep -q function \
|| die "missing package() for $name"
if [ "$pkgver" = "$ver" ] && git diff-index --quiet HEAD -- "$a"; then
die "version is already $ver"
fi
)
cd "${a%/*}"
section=${PWD%/*}
section=${section##*/}
message="$section/$name: $upgrade to ${ver}${cvelist}"
if [ -n "$fixes" ]; then
message="$message
fixes #${fixes#\#}
"
fi
msg "$message"
sed -i -e "s/^pkgver=[^ ]*/pkgver=$ver/" \
-e "s/^pkgrel=[^ ]*/pkgrel=0/" \
APKBUILD
$ABUILD $abuild_opts checksum all
git add APKBUILD
git commit -m"$message"
)
rc=$?
if [ $rc -gt 0 ]; then
error "Failed to build $p"
fi
done
if [ -n "$notbumped" ]; then
error "Not bumped: $notbumped"
fi
return $rc
}
usage() {
cat <<-__EOF__
$program $program_version - bump pkgver in APKBUILDs
Usage: $program [-s CVE-1,CVE-2,...] [-f ISSUE] [-k|--keep] PKGNAME-1.2.3 ...
Options:
-s, --security CVE1,CVE-2,... Security update
-f, --fixes ISSUE Fixes ISSUE
-k, --keep Run abuild with -k to keep existing packages
-q, --quiet
-h, --help Show this help
__EOF__
}
keep=
cvelist=
fixes=
args=$(getopt -o f:s:kqh --long fixes:,security:,keep,quiet,help \
-n "$program" -- "$@")
if [ $? -ne 0 ]; then
usage >&2
exit 2
fi
eval set -- "$args"
while true; do
case $1 in
-s|--security) cvelist=" ($2)"; shift;;
-f|--fixes) fixes="$2"; shift;;
-k|--keep) keep="-k";;
-q|--quiet) quiet=1;; # suppresses msg
-h|--help) usage; exit 0;;
--) shift; break;;
*) exit 1;; # getopt error
esac
shift
done
if [ $# -eq 0 ]; then
usage >&2
exit 2
fi
[ -n "$APORTSDIR" ] || error "can't locate \$APORTSDIR"
git rev-parse 2>/dev/null || die "not in a git tree"
abuild_opts="${ABUILD_OPTS- -r} $keep"
do_bump "$@"