Merge branch 'master' of ssh://git@git.opensuse.org/projects/zypp/libzypp
[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     #---delete-or-release---# LAST RELEASED: 5.3.2 (2) NEW RELEASE: 5.4.0 (4)
40
41 The line '#---delete-or-release---#...' shows the last version submitted
42 to autobuild ('# LAST RELEASED:; tag in $VERSIONFILE). And also the current
43 version, asuming you already updated the $VERSIONFILE according to your changes.
44 (The number in parenthesis is _COMPATMINOR)
45
46
47 - Delete the line if you don't want to submit the package to autobuild.
48
49 - Leave the line in place if you want to submit the package.
50
51
52 Closing the editor you are prompted:
53
54     #---delete-or-release---# LAST RELEASED: 5.3.2 (2) NEW RELEASE: 5.4.0 (4)
55     (a)bort, (c)ontinue, (e)dit :
56
57 Choosing (c)ontinue will write the new changes file. The '#---delete-or-release---#'
58 line is missing in case you deleted it. It's presence will remind you
59 that it is going to be converted into:
60
61     - version 5.4.0
62
63 and the '# LAST RELEASED:; tag in $VERSIONFILE will be updated accordingly.
64 Now check the result, check in your changes, build the package and submit
65 to autobuild.
66
67 Released by accident? Don't mind. Nothing bad will happen. If you want to
68 undo the change, restore the 'LAST RELEASED: ' entry in $VERSIONFILE and
69 delete the '- version' line in $CHANGESFILE'.
70
71 EOF
72   exit 1
73 }
74
75 case "$1" in
76   -[hH?]*)
77     usage
78     ;;
79   --help)
80     usage
81     ;;
82 esac
83
84 function getversion() {
85   cat "$VERSIONFILE" \
86   | awk '
87   function getnum() {
88     gsub("^[^\"]*\"","")
89     gsub("\".*$","")
90   }
91   /^ *SET *\( *LIBZYPP_MAJOR *"[0-9]+" *\)/       {getnum();major=$0}
92   /^ *SET *\( *LIBZYPP_MINOR *"[0-9]+" *\)/       {getnum();minor=$0}
93   /^ *SET *\( *LIBZYPP_PATCH *"[0-9]+" *\)/       {getnum();patch=$0}
94   /^ *SET *\( *LIBZYPP_COMPATMINOR *"[0-9]+" *\)/ {getnum();compatminor=$0}
95   /^# LAST RELEASED:/                             {gsub("^.*RELEASED: *","");gsub(" +$","");gsub(" +\\("," (");lastrelease=$0}
96   END {
97     thisrelease = major"."minor"."patch" ("compatminor")"
98     if ( thisrelease == lastrelease )
99       print "#---delete-or-release---# LAST RELEASED: "lastrelease" UNCHANGED RELEASE: "thisrelease
100     else
101       print "#---delete-or-release---# LAST RELEASED: "lastrelease" NEW RELEASE: "thisrelease
102   }
103   '
104 }
105
106 test -r /etc/sysconfig/mail && source /etc/sysconfig/mail
107 EMAIL="${USER}@${FROM_HEADER:-$(hostname -f)}"
108
109 GOTVERSION="$(getversion)"
110
111 TMPFILE=$(mktemp)
112 exec 3>&1-
113 exec >$TMPFILE
114 echo "-------------------------------------------------------------------"
115 echo "$(date) - $EMAIL"
116 echo ""
117 echo "- "
118 echo "$GOTVERSION"
119 echo ""
120 cat $CHANGESFILE
121 exec >&3
122
123 RES=e
124 while [ "$RES" == "e" ]; do
125   $EDITOR $TMPFILE
126   echo
127   NEWREL=$(grep '#---delete-or-release---#' $TMPFILE)
128   test -n "$NEWREL" && echo "$NEWREL"
129   read -n 1 -p "(a)bort, (c)ontinue, (e)dit : " RES
130   echo
131   echo
132   case "$RES" in
133     [eE]*)
134       RES=e
135       ;;
136     [cC])
137       test -n "$NEWREL" && {
138         echo "Remember new release in $VERSIONFILE"
139         sed -i 's/^.*#---delete-or-release---#.*RELEASE:/- version/' $TMPFILE
140         NEWREL=$(sed 's/^.*#---delete-or-release---#.*RELEASE:/# LAST RELEASED:/' <<<"$NEWREL")
141         sed -i "s/^# LAST RELEASED:.*$/$NEWREL/" $VERSIONFILE
142       }
143
144       echo "Store new $CHANGESFILE"
145       cp $TMPFILE $CHANGESFILE
146
147       echo "$(sed 's/^.*#---delete-or-release---#.*RELEASE:/# CURRENT RELEASE:/' <<<"$GOTVERSION")"
148       awk '{print}/^----------/{n=n+1; if ( n == 2 ) exit 0; }' $CHANGESFILE
149
150       ;;
151     *)
152       echo "Leave $CHANGESFILE untouched"
153       ;;
154   esac
155 done
156
157 rm -f $TMPFILE