]> TLD Linux GIT Repositories - packages/postfix.git/blob - relup.sh
- updated to 3.4.6
[packages/postfix.git] / relup.sh
1 #!/bin/sh
2 # script to run after "release bump" style change.
3 # takes Release from spec and creates commit with message
4 # groups similiar commits together.
5 # "- release $rel"
6
7 set -e
8
9 get_dump() {
10         local specfile="$1"
11         if ! out=$(rpm --specfile "$specfile" --define 'prep %dump' -q 2>&1); then
12                 echo >&2 "$out"
13                 echo >&2 "You need icon files being present in SOURCES."
14                 exit 1
15         fi
16         echo "$out"
17 }
18
19 usage="Usage:
20 ${0##*/} [-i] [-u] [-t] [-n] [-m <MESSAGE>] <SPECLIST>
21
22 Options:
23 -i
24   Try to increment package release
25 -u
26   git pull first
27 -t | -n
28   Test mode (dry-run). do not commit
29 -m
30   Specify commit message
31
32 "
33
34 get_release() {
35         local specfile="$1"
36         rel=$(awk '/^%define[   ]+_?rel[        ]+/{print $NF}' $specfile)
37         if [ -z "$rel" ]; then
38                 dump=$(get_dump "$specfile")
39                 rel=$(echo "$dump" | awk '/PACKAGE_RELEASE/{print $NF; exit}')
40         fi
41         echo $rel
42 }
43
44 set_release() {
45         local specfile="$1"
46         local rel="$2"
47         local newrel="$3"
48         sed -i -e "
49                 s/^\(%define[ \t]\+_\?rel[ \t]\+\)$rel\$/\1$newrel/
50                 s/^\(Release:[ \t]\+\)$rel\$/\1$newrel/
51         " $specfile
52 }
53
54 if [ ! -x /usr/bin/getopt ]; then
55         echo >&1 "You need to install util-linux to use relup.sh"
56         exit 1
57 fi
58
59 t=$(getopt -o 'm:inuth' -n "${0##*/}" -- "$@") || exit $?
60 # Note the quotes around `$t': they are essential!
61 eval set -- "$t"
62
63 while true; do
64         case "$1" in
65         -i)
66                 inc=1
67                 ;;
68         -u)
69                 update=1
70                 ;;
71         -t | -n)
72                 test=1
73                 ;;
74         -m)
75                 shift
76                 message="${1#- }"
77                 ;;
78         -h)
79                 echo "$usage"
80                 exit 0
81                 ;;
82         --)
83                 shift
84                 break
85         ;;
86         *)
87                 echo 2>&1 "Internal error: [$1] not recognized!"
88                 exit 1
89                 ;;
90         esac
91         shift
92 done
93
94 tmpd=$(mktemp -d "${TMPDIR:-/tmp}/relXXXXXX")
95 topdir=$(rpm -E '%{_topdir}')
96 cd "$topdir"
97 for pkg in "$@"; do
98         name=${pkg%.spec} name=${name##*/}
99         spec=$(rpm -D "name $name" -E '%{_specdir}/%{name}.spec')
100         spec=${spec#$topdir/}
101         if [ "$update" = "1" ]; then
102                 ./builder -g -ns "$spec"
103         fi
104         rel=$(get_release "$spec")
105         if [ "$inc" = 1 ]; then
106                 if [[ $rel = *%* ]]; then
107                         relmacro=${rel#*%}
108                         relnum=${rel%%%*}
109                         newrel=$(expr ${relnum} + 1)
110                         set_release "$spec" $rel "${newrel}%${relmacro}"
111                 else
112                         newrel=$(expr ${rel} + 1)
113                         set_release "$spec" $rel $newrel
114                 fi
115
116                 # refetch release
117                 rel=$(get_release "$spec")
118         fi
119         echo "$spec" >> "$tmpd/$rel"
120 done
121
122 n="$(echo -e '\nn')"
123 n="${n%%n}"
124 for file in $(ls "$tmpd" 2>/dev/null); do
125         files=$(cat "$tmpd/$file")
126         pkg=$(cat "$tmpd/$file" |sed -e 's|/.*||')
127         spec=$(cat "$tmpd/$file" |sed -e 's|.*/||')
128         rel=$(basename "$file")
129         msg=""
130         [ -n "$message" ] && msg="$msg- $message$n"
131         msg="$msg- release ${rel%%%*} (by relup.sh)$n"
132         if [ "$test" != 1 ]; then
133                 cd $pkg
134                 git commit -m "$msg" $spec
135                 git push
136                 cd ..
137         fi
138 done
139 rm -rf $tmpd