]> andersk Git - test.git/blob - commit
Use 2048-bit RSA keys for auto-generated certificates.
[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     sed -i -e 's/debhelper *([^0-9]*[^)]*)/debhelper (>= 7.0.0)/'             \
68         "${prj}-${ver}/debian/control"
69     sed -i -e 's/dh_clean *-k/dh_prep/' "${prj}-${ver}/debian/rules"
70
71     # Check that the version number in the debian/changelog file matches
72     if [ "$(sed -e 's/^'"${prj}"' *(\([^-]*\)-.*).*/\1/;t1;d;:1;q'            \
73              "${prj}-${ver}/debian/changelog")" != "${ver}" ]; then
74       echo "Debian changelog file does not match current version number!" >&2
75       exit 1
76     fi
77
78     # Build Debian packages.
79     (cd "${prj}-${ver}"
80      fakeroot dpkg-buildpackage -sa -us -uc || :)
81     trap '' EXIT
82
83     # Run lintian
84     lintian --verbose -I ${prj}_${ver}*_*.changes
85   ) || exit 1
86
87   # Revert any changes that might be pending in distributions/debian/*
88   local revert="$(svn st |
89                   grep distributions/debian |
90                   grep '^[^?]' |
91                   awk '{ print $2 }' |
92                   tac)"
93   if [ -n "${revert}" ]; then
94     svn revert ${revert}
95     rm -f ${revert}
96   fi
97
98   # Create distributions/debian if it does not exist yet.
99   mkdir -p distributions/debian
100   for i in distributions distributions/debian; do
101     if [ -z "$(svn st "${i}" 2>/dev/null | grep -v '^[?]')" ]; then
102       svn add --depth=empty "${i}"
103     fi
104   done
105
106   # If this version of files already exists in the distribution directory,
107   # we are not yet ready to cut a new release. Just clean up and exit.
108   for i in "${prj}_${ver}"[-.]*.*; do
109     [ -r "distributions/debian/${i}" ] && {
110       rm $(ls "${prj}_${ver}"[-.]* | egrep -v '_*.changes|_*.deb')
111       return 0
112     }
113   done
114
115   # Move new Debian files into release area.
116   mv $(ls "${prj}_${ver}"[-.]* | egrep -v '_*.changes|_*.deb')                \
117      distributions/debian/
118   svn add distributions/debian/"${prj}_${ver}"[-.]*.*
119
120   # Let the caller know that we added new packages.
121   return 1
122 }
123
124 # Quick sanity check that we are running from the correct directory
125 test -r configure.ac
126
127 # Make sure there are no stale files
128 svn update
129
130 # Determine Subversion revision number, project name, and public version
131 # number
132 {
133   rev=$(($(svn info | sed -e 's/^Revision: \(.*\)/\1/;t1;d;:1;q')+1))
134   prj="$(sed -e 's/^AC_INIT(\([^,]*\),.*/\1/;t1;d;:1;q' configure.ac)"
135   ver="$(sed -e 's/^AC_INIT([^,]*, *\([^,]*\),.*/\1/;t1;d;:1;q' configure.ac)"
136 } 2>/dev/null
137
138 # Update "configure.ac" with the next Subversion revision number. This
139 # information will trickle down into various source files where it becomes
140 # part of the user-visible version information.
141 sed -i -e 's/^\(VCS_REVISION=\).*/\1'"${rev}"'/' configure.ac
142 touch shellinabox/vt100.jspp shellinabox/shell_in_a_box.jspp
143
144 # If the manual page has been changed, make sure that the time stamp will be
145 # changed, too.
146 if [ -n "$(svn st shellinabox/shellinaboxd.man.in 2>/dev/null |
147            grep '^M')" ]; then
148   sed -i -e 's/^\([.]TH .*\)"[^"]*"/\1"'"$(date +'%b %d, %Y')"'"/
149              s/2008-2[01][0-9][0-9]/2008-'"$(date +'%Y')"'/g'                 \
150       shellinabox/shellinaboxd.man.in
151 fi
152
153 # Always update the year in the user visible copyright statement(s)
154 for i in shellinabox/shell_in_a_box.jspp                                      \
155          shellinabox/vt100.jspp                                               \
156          COPYING                                                              \
157          debian/copyright; do
158   sed -i -e 's/\(2[01][0-9][0-9]-\)2[01][0-9][0-9]/\1'"$(date +'%Y')"'/g' "$i"
159 done
160
161 # If a source file has changed, make sure to update the year in the copyright
162 # statement for that particular file.
163 svn st | egrep '^[MA]' | awk '{ print $2 }' |
164   egrep '^(shellinabox|libhttp|demo)/' |
165   egrep '[.](html|h|c|css|jspp)$' |
166   while read -r f; do
167    sed -i -e 's/\(2[01][0-9][0-9]-\)2[01][0-9][0-9]/\1'"$(date +'%Y')"'/g' "$f"
168   done
169
170 # For now, Ubuntu/Hardy is still quite popular. We want to make it easy for
171 # our users to build Debian packages from source. So, make sure we lock the
172 # compatibility level at 6. Once we no longer care about maintaining strict
173 # backwards compatibility, we can lift this restriction.
174 echo 6 >debian/compat
175 sed -i -e 's/debhelper *([^0-9]*[^)]*)/debhelper (>= 6.0.0)/' debian/control
176 sed -i -e 's/dh_prep/dh_clean *-k/' debian/rules
177
178 # Build all the sources, create the distribution tar archive, and run some
179 # basic sanity checks.
180 make all distcheck
181
182 # Build Debian package and create all the files that are needed by the
183 # distribution maintainer.
184 msg=
185 debian_package || {
186   msg="${msg}
187 NOTICE: New version released. Please do not forget to notify distributions"
188   if [ -r ~/.shellinabox-notifier ]; then
189     while read e; do
190       {
191         echo "This is an automatically generated e-mail notification that"
192         echo "a new release of ShellInABox has just been made available"
193         echo "on the project's website at http://shellinabox.com"
194         echo
195         echo "You had previously requested to be notified when this happens."
196       } | mail -s "New ShellInABox release" "$e"
197     done
198   else
199     msg="${msg}
200 NOTICE: Could not find ~/.shellinabox-notifier. Not sending e-mail..."
201   fi
202 }
203
204 svn diff $(svn st |
205            egrep -v ' configure$| aclocal.m4$|distributions|^[?]' |
206            sed -e 's/^[^ ]* *//') | less
207 echo -n 'Commit these changes (Y/n): '
208 yes_no 0 || exit 1
209 svn commit
210 echo "${msg}"
211
212 trap '' EXIT
213 exit 0
This page took 0.047129 seconds and 5 git commands to generate.