fix changes
[platform/upstream/libzypp.git] / mkChangelog
1 #! /bin/bash
2 #
3
4 function errexit() {
5   exec >&2
6   echo "Error: $@"
7   exit 1
8 }
9
10 export LC_ALL=""
11 EDITOR=${EDITOR:-vi}
12
13 TDIR=$(dirname $0)
14 test -n "$TDIR" && cd $TDIR
15
16 CHANGESFILE=$(ls package/*.changes)
17 test -f "$CHANGESFILE" || errexit "No changes file '$CHANGESFILE'"
18
19 VERSIONFILE="VERSION.cmake"
20 test -f "$VERSIONFILE" || errexit "No version file '$VERSIONFILE'"
21
22 ## Version.cmake tags in getversion() are still zypp specific.
23
24 function usage() {
25   exec >&2
26 cat <<EOF
27
28 Usage:   $(basename $0) [OPTIONS]
29 Options: -h,-?,--help   This page.
30
31 $(basename $0) will load the changes file '$CHANGESFILE'
32 into your editor (\$EDITOR=$EDITOR), providing a new changes
33 entry template:
34
35     -------------------------------------------------------------------
36     Wed Jul 30 18:20:06 CEST 2008 - ma@suse.de
37
38     -
39     - revision 10702
40     #---delete-or-release---# LAST RELEASED: 5.3.2 (2) NEW RELEASE: 5.4.0 (4)
41
42 The revision number is a guess and assumes you will check in to
43 SVN shortly after editing (current server revision + 1).
44
45 The line '#---delete-or-release---#...' shows the last version submitted
46 to autobuild ('# LAST RELEASED:; tag in $VERSIONFILE). And also the current
47 version, asuming you already updated the $VERSIONFILE according to your changes.
48 (The number in parenthesis is _COMPATMINOR)
49
50
51 - Delete the line if you don't want to submit the package to autobuild.
52
53 - Leave the line in place if you want to submit the package.
54
55
56 Closing the editor you are prompted:
57
58     #---delete-or-release---# LAST RELEASED: 5.3.2 (2) NEW RELEASE: 5.4.0 (4)
59     (a)bort, (c)ontinue, (e)dit :
60
61 Choosing (c)ontinue will write the new changes file. The '#---delete-or-release---#'
62 line is missing in case you deleted it. It's presence will remind you
63 that it is going to be converted into:
64
65     - version 5.4.0
66
67 and the '# LAST RELEASED:; tag in $VERSIONFILE will be updated accordingly.
68 Now check the result, check in your changes, build the package and submit
69 to autobuild.
70
71 Released by accident? Don't mind. Nothing bad will happen. If you want to
72 undo the change, restore the 'LAST RELEASED: ' entry in $VERSIONFILE and
73 delete the '- version' line in $CHANGESFILE'.
74
75 EOF
76   exit 1
77 }
78
79 case "$1" in
80   -[hH?]*)
81     usage
82     ;;
83   --help)
84     usage
85     ;;
86 esac
87
88 function getversion() {
89   cat "$VERSIONFILE" \
90   | awk '
91   function getnum() {
92     gsub("^[^\"]*\"","")
93     gsub("\".*$","")
94   }
95   /^ *SET *\( *LIBZYPP_MAJOR *"[0-9]+" *\)/       {getnum();major=$0}
96   /^ *SET *\( *LIBZYPP_MINOR *"[0-9]+" *\)/       {getnum();minor=$0}
97   /^ *SET *\( *LIBZYPP_PATCH *"[0-9]+" *\)/       {getnum();patch=$0}
98   /^ *SET *\( *LIBZYPP_COMPATMINOR *"[0-9]+" *\)/ {getnum();compatminor=$0}
99   /^# LAST RELEASED:/                             {gsub("^.*RELEASED: *","");gsub(" +$","");gsub(" +\\("," (");lastrelease=$0}
100   END {
101     thisrelease = major"."minor"."patch" ("compatminor")"
102     if ( thisrelease == lastrelease )
103       print "#---delete-or-release---# LAST RELEASED: "lastrelease" UNCHANGED RELEASE: "thisrelease
104     else
105       print "#---delete-or-release---# LAST RELEASED: "lastrelease" NEW RELEASE: "thisrelease
106   }
107   '
108 }
109
110 function nextrevision() {
111   svn status -u CMakeLists.txt \
112   | awk '/^Status against revision:/{print $4+1}'
113 }
114
115
116 test -r /etc/sysconfig/mail && source /etc/sysconfig/mail
117 EMAIL="${USER}@${FROM_HEADER:-$(hostname -f)}"
118
119 GOTVERSION="$(getversion)"
120
121 TMPFILE=$(mktemp)
122 exec 3>&1-
123 exec >$TMPFILE
124 echo "-------------------------------------------------------------------"
125 echo "$(date) - $EMAIL"
126 echo ""
127 echo "- "
128 echo "- revision $(nextrevision)"
129 echo "$GOTVERSION"
130 echo ""
131 cat $CHANGESFILE
132 exec >&3
133
134 RES=e
135 while [ "$RES" == "e" ]; do
136   $EDITOR $TMPFILE
137   echo
138   NEWREL=$(grep '#---delete-or-release---#' $TMPFILE)
139   test -n "$NEWREL" && echo "$NEWREL"
140   read -n 1 -p "(a)bort, (c)ontinue, (e)dit : " RES
141   echo
142   echo
143   case "$RES" in
144     [eE]*)
145       RES=e
146       ;;
147     [cC])
148       test -n "$NEWREL" && {
149         echo "Remember new release in $VERSIONFILE"
150         sed -i 's/^.*#---delete-or-release---#.*RELEASE:/- version/' $TMPFILE
151         NEWREL=$(sed 's/^.*#---delete-or-release---#.*RELEASE:/# LAST RELEASED:/' <<<"$NEWREL")
152         sed -i "s/^# LAST RELEASED:.*$/$NEWREL/" $VERSIONFILE
153       }
154
155       echo "Store new $CHANGESFILE"
156       cp $TMPFILE $CHANGESFILE
157
158       echo "$(sed 's/^.*#---delete-or-release---#.*RELEASE:/# CURRENT RELEASE:/' <<<"$GOTVERSION")"
159       awk '{print}/^----------/{n=n+1; if ( n == 2 ) exit 0; }' $CHANGESFILE
160
161       ;;
162     *)
163       echo "Leave $CHANGESFILE untouched"
164       ;;
165   esac
166 done
167
168 rm -f $TMPFILE