]> andersk Git - test.git/blob - commit
Added some basic sanity checks to the commit script that now makes
[test.git] / commit
1 #!/bin/bash -e
2
3 # The script ensures that all commands succeed unless an error occurred. If it
4 # does though, the shell terminates the script and our exit handler runs.
5 trap 'tput bel || :; echo Failed! >&2' EXIT
6
7 # Ask the user a yes/no question. This function does not require the user to
8 # press ENTER after making a selection.
9 yes_no() {
10   local c
11   while :; do
12     c="$(set +e
13          trap 'stty echo -iuclc icanon 2>/dev/null' EXIT INT TERM QUIT
14          stty -echo iuclc -icanon 2>/dev/null
15          dd count=1 bs=1 2>/dev/null | od -An -tx1)"
16     case "$c" in
17       " 0a") if [ -n "$1" ]; then
18                [ $1 -eq 0 ] && echo "Y" || echo "N"
19                return $1
20              fi
21              ;;
22       " 79") echo "Y"
23              return 0
24              ;;
25       " 6e") echo "N"
26              return 1
27              ;;
28       "")    echo "Aborted" >&2
29              exit 1
30              ;;
31       *)     # The user pressed an unrecognized key. As we are not echoing
32              # any incorrect user input, alert the user by ringing the bell.
33              (tput bel) 2>/dev/null || :
34              ;;
35     esac
36   done
37 }
38
39 # Build Debian package and create all the files that are needed by the
40 # distribution maintainer.
41 debian_package() {
42   set -e
43   (
44     # Try to build the package. If things fail, let the exit handler remove all
45     # temporary files.
46     trap 'rm -rf "${prj}-${ver}" "${prj}_${ver}"*' EXIT
47
48     # Clean up any old temporary files
49     rm -rf "${prj}-${ver}" "${prj}_${ver}"*
50
51     # Extract the distribution source archive
52     tar zfx "${prj}-${ver}.tar.gz"
53
54     # We want to ship the "debian" directory with the source archive that
55     # users download directly from the project web site. This allows them to
56     # easily build their own Debian package by following the instructions in
57     # INSTALL.Debian.
58     # But when preparing our package for direct integration with Debian-based
59     # distributions, we have to instead remove the "debian" directory, as the
60     # distribution prefers that third-party projects are not built "natively".
61     mv "${prj}-${ver}/debian" "${prj}_${ver}_debian"
62     tar zfc "${prj}_${ver}.orig.tar.gz" "${prj}-${ver}"
63     mv "${prj}_${ver}_debian" "${prj}-${ver}/debian"
64
65     # Reset compatibility level
66     echo 7 >"${prj}-${ver}/debian/compat"
67
68     # Build Debian packages.
69     (cd "${prj}-${ver}"
70      fakeroot dpkg-buildpackage -sa -us -uc || :)
71     trap '' EXIT
72   )
73
74   # Revert any changes that might be pending in distributions/debian/*
75   local revert="$(svn st |
76                   grep distributions/debian |
77                   grep '^[^?]' |
78                   awk '{ print $2 }' |
79                   tac)"
80   if [ -n "${revert}" ]; then
81     svn revert ${revert}
82     rm -f ${revert}
83   fi
84
85   # Create distributions/debian if it does not exist yet.
86   mkdir -p distributions/debian
87   for i in distributions distributions/debian; do
88     if [ -z "$(svn st "${i}" 2>/dev/null | grep -v '^[?]')" ]; then
89       svn add --depth=empty "${i}"
90     fi
91   done
92
93   # If this version of files already exists in the distribution directory,
94   # we are not yet ready to cut a new release. Just clean up and exit.
95   for i in "${prj}_${ver}"[-.]*.*; do
96     [ -r "distributions/debian/${i}" ] && {
97       rm $(ls "${prj}_${ver}"[-.]* | egrep -v '_*.changes|_*.deb')
98       return 0
99     }
100   done
101
102   # Move new Debian files into release area.
103   mv $(ls "${prj}_${ver}"[-.]* | egrep -v '_*.changes|_*.deb')                \
104      distributions/debian/
105   svn add distributions/debian/"${prj}_${ver}"[-.]*.*
106
107   # Let the caller know that we added new packages.
108   return 1
109 }
110
111 # Quick sanity check that we are running from the correct directory
112 test -r configure.ac
113
114 # Make sure there are no stale files
115 svn update
116
117 # Determine Subversion revision number, project name, and public version
118 # number
119 {
120   rev=$(($(svn info | sed -e 's/^Revision: \(.*\)/\1/;t1;d;:1;q')+1))
121   prj="$(sed -e 's/^AC_INIT(\([^,]*\),.*/\1/;t1;d;:1;q' configure.ac)"
122   ver="$(sed -e 's/^AC_INIT([^,]*, *\([^,]*\),.*/\1/;t1;d;:1;q' configure.ac)"
123 } 2>/dev/null
124
125 # Update "configure.ac" with the next Subversion revision number. This
126 # information will trickle down into various source files where it becomes
127 # part of the user-visible version information.
128 sed -i -e 's/^\(VCS_REVISION=\).*/\1'"${rev}"'/' configure.ac
129 touch shellinabox/vt100.jspp shellinabox/shell_in_a_box.jspp
130
131 # If the manual page has been changed, make sure that the time stamp will be
132 # changed, too.
133 if [ -n "$(svn st shellinabox/shellinaboxd.man.in 2>/dev/null |
134            grep '^M')" ]; then
135   sed -i -e 's/^\([.]TH .*\)"[^"]*"/\1"'"$(date +'%b %d, %Y')"'"/
136              s/2008-2[01][0-9][0-9]/2008-'"$(date +'%Y')"'/g'                 \
137       shellinabox/shellinaboxd.man.in
138 fi
139
140 # Always update the year in the user visible copyright statement(s)
141 for i in shellinabox/shell_in_a_box.jspp                                      \
142          shellinabox/vt100.jspp                                               \
143          COPYING                                                              \
144          debian/copyright; do
145   sed -i -e 's/\(2[01][0-9][0-9]-\)2[01][0-9][0-9]/\1'"$(date +'%Y')"'/g' "$i"
146 done
147
148 # If a source file has changed, make sure to update the year in the copyright
149 # statement for that particular file.
150 svn st | egrep '^[MA]' | awk '{ print $2 }' |
151   egrep '^(shellinabox|libhttp|demo)/' |
152   egrep '[.](html|h|c|css|jspp)$' |
153   while read -r f; do
154    sed -i -e 's/\(2[01][0-9][0-9]-\)2[01][0-9][0-9]/\1'"$(date +'%Y')"'/g' "$f"
155   done
156
157 # For now, Ubuntu/Hardy is still quite popular. We want to make it easy for
158 # our users to build Debian packages from source. So, make sure we lock the
159 # compatibility level at 6. Once we no longer care about maintaining strict
160 # backwards compatibility, we can lift this restriction.
161 echo 6 >debian/compat
162
163 # Build all the sources, create the distribution tar archive, and run some
164 # basic sanity checks.
165 make all distcheck
166
167 # Build Debian package and create all the files that are needed by the
168 # distribution maintainer.
169 msg=
170 debian_package ||
171   msg="${msg}
172 NOTICE: New version released. Please do not forget to notify distributions"
173
174 svn diff $(svn st |
175            egrep -v ' configure$| aclocal.m4$|distributions|^[?]' |
176            sed -e 's/^[^ ]* *//') | less
177 echo -n 'Commit these changes (Y/n): '
178 yes_no 0 || exit 1
179 svn commit
180 echo "${msg}"
181
182 trap '' EXIT
183 exit 0
This page took 0.186902 seconds and 5 git commands to generate.