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