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