Update commit message style to Git not CVS
[packages/rpm-build-tools.git] / relup.sh
CommitLineData
45baae4c 1#!/bin/bash
3c02bcbe 2# script to run after "release bump" style change.
5dc951e1 3# takes Release from spec and creates commit with message
c2d1361e 4# groups similiar commits together.
3c02bcbe 5# "- release $rel"
5dc951e1
ER
6
7set -e
5dc951e1
ER
8
9get_dump() {
b9c37ff0 10 local specfile="$1"
efec12ac
JR
11 local rpm_dump
12 local success="y"
13 if [ -x /usr/bin/rpm-specdump ]; then
14 rpm_dump=$(rpm-specdump "$specfile" 2>&1) || success="n"
15 else
16 rpm_dump=$(rpm --specfile "$specfile" --define 'prep %dump' -q 2>&1) || success="n"
17 fi
18 if [ "$success" != "y" ]; then
19 echo >&2 "$rpm_dump"
c2d1361e
ER
20 echo >&2 "You need icon files being present in SOURCES."
21 exit 1
22 fi
efec12ac 23 echo "$rpm_dump"
5dc951e1
ER
24}
25
e5c1545d 26usage="Usage:
409001f7 27${0##*/} [-i] [-g] [-u] [-t|-n] [-m <MESSAGE>] <SPECLIST>
e5c1545d
ER
28
29Options:
30-i
31 Try to increment package release
409001f7
ER
32-g
33 get packages if missing, do nothing else
2592af77 34-u
409001f7 35 update packages (git pull)
ed891ce4
ER
36-t | -n
37 Test mode (dry-run). do not commit
e5c1545d
ER
38-m
39 Specify commit message
40
41"
42
5dc951e1 43get_release() {
376ea54e 44 local specfile="$1"
4881d2e7 45 rel=$(awk '/^%define[ ]+_?rel[ ]+/{print $NF}' $specfile)
376ea54e 46 if [ -z "$rel" ]; then
c2d1361e 47 dump=$(get_dump "$specfile")
520382b9 48 rel=$(echo "$dump" | awk '$2~/^(PACKAGE_)?RELEASE$/{print $NF; exit}')
376ea54e
ER
49 fi
50 echo $rel
5dc951e1
ER
51}
52
82e31bc6
ER
53set_release() {
54 local specfile="$1"
55 local rel="$2"
bdfdf194 56 local newrel="$3"
82e31bc6 57 sed -i -e "
4881d2e7 58 s/^\(%define[ \t]\+_\?rel[ \t]\+\)$rel\$/\1$newrel/
5c68af79 59 s/^\(Release:[ \t]\+\)$rel\$/\1$newrel/
82e31bc6
ER
60 " $specfile
61}
62
62113de5
ER
63bump_release() {
64 local release=$1 rel
65
66 rel=$(expr ${release} + 1)
67 echo $rel
68}
69
d509f566
ER
70# normalize spec
71# takes as input:
72# - PACKAGE/
73# - ./PACKAGE/
74# - PACKAGE
75# - PACKAGE.spec
76# - ./PACKAGE.spec
77# - PACKAGE/PACKAGE
78# - PACKAGE/PACKAGE.spec
79# - ./PACKAGE/PACKAGE.spec
80# - rpm/PACKAGE/PACKAGE
81# - rpm/PACKAGE/PACKAGE.spec
82# - ./rpm/PACKAGE/PACKAGE.spec
83# returns PACKAGE
84package_name() {
85 local specfile="${1%/}" package
86
f88a9927
ER
87 # strip branch
88 specfile=${specfile%:*}
d509f566
ER
89 # basename
90 specfile=${specfile##*/}
91 # strip .spec
92 package=${specfile%.spec}
93
94 echo $package
95}
96
f88a9927
ER
97get_branch() {
98 local specfile="${1%/}" branch
99
100 branch=${specfile#*:}
101
5167c72b
JR
102 if [ "$branch" != "$specfile" ]; then
103 echo "$branch"
104 else
105 echo ""
106 fi
f88a9927
ER
107}
108
b6f02a43
ER
109if [ ! -x /usr/bin/getopt ]; then
110 echo >&1 "You need to install util-linux to use relup.sh"
111 exit 1
112fi
113
409001f7 114t=$(getopt -o 'm:inguth' -n "${0##*/}" -- "$@") || exit $?
82e31bc6 115# Note the quotes around `$t': they are essential!
b6f02a43
ER
116eval set -- "$t"
117
118while true; do
119 case "$1" in
82e31bc6
ER
120 -i)
121 inc=1
122 ;;
2592af77
AM
123 -u)
124 update=1
125 ;;
409001f7
ER
126 -g)
127 get=1
128 ;;
ed891ce4 129 -t | -n)
bdfdf194
ER
130 test=1
131 ;;
b6f02a43
ER
132 -m)
133 shift
6de0e286 134 message="${1#- }"
b6f02a43 135 ;;
e5c1545d
ER
136 -h)
137 echo "$usage"
138 exit 0
139 ;;
b6f02a43
ER
140 --)
141 shift
142 break
143 ;;
144 *)
145 echo 2>&1 "Internal error: [$1] not recognized!"
146 exit 1
147 ;;
148 esac
149 shift
150done
151
b822263b 152topdir=$(rpm -E '%{_topdir}')
07ea9b01 153
06258291
ER
154n="$(echo -e '\nn')"
155n="${n%%n}"
156
b822263b
ER
157cd "$topdir"
158for pkg in "$@"; do
f88a9927 159 branch=$(get_branch "$pkg")
06258291 160 # pkg: package %{name}
d509f566 161 pkg=$(package_name "$pkg")
06258291
ER
162
163 # spec: package/package.spec
d509f566 164 spec=$(rpm -D "name $pkg" -E '%{_specdir}/%{name}.spec')
b822263b 165 spec=${spec#$topdir/}
d509f566 166
06258291
ER
167 # pkgdir: package/
168 pkgdir=${spec%/*}
169
26841699
ER
170 # specname: only spec filename
171 specname=${spec##*/}
172
06258291 173 # start real work
5167c72b
JR
174 if [ -n "$branch" ]; then
175 echo "$pkg:$branch ..."
176 else
177 echo "$pkg ..."
178 fi
62113de5 179
06258291 180 # get package
409001f7
ER
181 [ "$get" = 1 -a -d "$pkgdir" ] && continue
182
183 if [ "$update" = "1" -o "$get" = "1" ]; then
5167c72b
JR
184 if [ -n "$branch" ]; then
185 ./builder -g -ns "$spec" -r $branch
186 else
187 ./builder -g -ns "$spec"
188 fi
86d87bda 189 fi
06258291 190
409001f7
ER
191 [ "$get" = 1 ] && continue
192
06258291 193 # update .spec files
59617750 194 rel=$(get_release "$spec")
82e31bc6 195 if [ "$inc" = 1 ]; then
ca451162
JR
196 if [[ $rel = *%* ]]; then
197 relmacro=${rel#*%}
62113de5 198 newrel=$(bump_release ${rel%%%*})
ca451162
JR
199 set_release "$spec" $rel "${newrel}%${relmacro}"
200 else
62113de5 201 newrel=$(bump_release ${rel})
ca451162
JR
202 set_release "$spec" $rel $newrel
203 fi
f4dbef5b
ER
204
205 # refetch release
206 rel=$(get_release "$spec")
82e31bc6 207 fi
b9c37ff0 208
06258291
ER
209 # commit the changes
210 msg=""
357c6ac7
ER
211 [ -n "$message" ] && msg="${msg}$message$n$n"
212 msg="${msg}Release ${rel%%%*} (by relup.sh)"
213
06258291
ER
214 echo git commit -m "$msg" $spec
215 if [ "$test" != 1 ]; then
216 cd $pkgdir
26841699 217 git commit -m "$msg" $specname
06258291
ER
218 git push
219 cd ..
220 fi
b9c37ff0 221done
This page took 0.180502 seconds and 4 git commands to generate.