fix snapshot creation, and put snapshots on sourceforge.net directly (not via ftp...
[docutils.git] / sandbox / infrastructure / docutils-update.local
blob2081d33a7c90391d873292fb59f92bcc6347a818
1 #! /bin/bash
2 # $Id$
4 # This script updates the Docutils web site.
5 # ATTENTION
6 # Any .html document with a corresponding .txt file is regenerated
7 # if the .txt has changed, but no new .html files will be generated.
9 # Options:
10 # -f Do not give feedback.
11 # -t Run the script in trace mode ("set -o xtrace").
12 # -u Regenerate .html unconditionally.
13 # -v Run verbosely.
15 # Prerequisites:
17 # - Checked out trunk at $snapshotdir.
18 # - Checked out main tree at $lib, no longer necessary.
20 # exit on error
21 set -e
23 # make all newly created files group writeable
24 umask 002
26 # URL for SVN project checkout:
27 svnurl=http://svn.berlios.de/svnroot/repos/docutils/trunk/docutils
29 basedir=/home/groups/docutils/htdocs
30 if [ ! -e $basedir ] ; then
31 basedir=`pwd`/update-dir
32 test -d $basedir || mkdir $basedir
34 project=docutils
35 # $auxdir is non-public.
36 auxdir=$basedir/aux
37 test -d $auxdir || mkdir $auxdir
38 # $htdocsdest is the destination for htdocs and will be moved to
39 # another server later; so we keep it non-public (under $auxdir).
40 htdocsdest=$auxdir/htdocs
41 test -d $htdocsdest || mkdir $htdocsdest
42 # Where to create the snapshots (non-public).
43 snapshotdir=$auxdir/snapshots
44 test -d $snapshotdir || mkdir $snapshotdir
45 # # Where to publish the snapshots (public).
46 # snapshotdest=/home/groups/ftp/pub/docutils
47 bindir=$auxdir/bin
48 test -d $bindir || mkdir $bindir
50 htdocs_patchfile=$auxdir/htdocs.patch
51 htdocs_tarball=$auxdir/htdocs.tar
52 htdocs_new_tarball=$auxdir/htdocs.new.tar
53 # htdocs directory on SF.net
54 remoteproject=/home/groups/d/do/docutils
55 remotehtdocs=$remoteproject/htdocs
56 # local checkout
57 pylib=$auxdir/lib/python
58 lib=$pylib/$project
59 # Lock directory.
60 lockdir=$auxdir/lock
61 # SSH stuff.
62 sshdir=$auxdir/.ssh
63 sshhost=docutilsupdate@shell.sourceforge.net
64 sshhost=docutilsupdate,docutils@web.sourceforge.net
65 sshcommand="ssh -i $lockdir/id_dsa
66 -o UserKnownHostsFile=$sshdir/known_hosts $sshhost"
67 # Project base URL (for sitemap) without trailing slash.
68 baseurl="http://docutils.sourceforge.net"
70 export PYTHONPATH=$pylib:$lib:$lib/extras
71 export PATH=$lib/tools:$PATH
73 trace=0
74 unconditional=0
75 verbose=0
76 feedback=1
78 while getopts ftuv opt
80 case $opt in
81 f) feedback=;;
82 t) trace=1;;
83 u) unconditional=1;;
84 v) verbose=1;;
85 \?) exit 2;;
86 esac
87 done
88 shift `expr $OPTIND - 1`
90 test $feedback && echo 'Starting docutils-update run...' || true
92 if [ $trace -eq 1 -o $verbose -eq 1 ] ; then
93 set -o xtrace
96 # Acquire lock.
97 if ! mkdir $lockdir; then
98 echo
99 echo Could not create lock directory at
100 echo $lockdir
101 echo
102 echo Please ensure no other user is running this script
103 echo and delete the directory.
104 exit 1
106 # Always clean up on exit.
107 trap "rm -rf $lockdir; trap - 0; exit 1" 0 1 2 3 15
108 # Make sure the lock directory is deletable (i.e. rwx) by other group
109 # members (in case this script crashes after copying files into the
110 # directory) and un-readable by world (because we'll be storing the
111 # key in it).
112 chmod 0770 $lockdir
115 # update library area
116 if [ -e $lib ] ; then
117 cd $lib
118 svn up --quiet
119 else
120 test -d $pylib || mkdir -p $pylib
121 cd $pylib
122 svn checkout $svnurl
125 # -------------------- Snapshots: --------------------
127 # gather the materials
128 cd $snapshotdir
129 svn -q revert $project/$project/__init__.py
130 haschanges="`svn up docutils sandbox web | grep -v '^At revision '; true`"
132 # update __version_details__ string
133 version_details="snapshot `date --utc --iso`, r`svn info docutils | grep ^Revision: | sed 's/^Revision: //'`"
134 (echo ",s/^__version_details__ = .*\$/__version_details__ = '$version_details'/";
135 echo wq) | ed $project/$project/__init__.py 2> /dev/null
137 # Ensure proper directory permissions are set so that the files can be
138 # modified by several users. Changing permissions of files is
139 # probably not necessary because files can be deleted and re-created.
140 # Do not change permissions of aux directory to keep it non-public
141 # (but change permissions for all subdirectories).
142 #find $basedir -type f -print0 | xargs -0 chmod ug+rw 2> /dev/null || true
143 find $basedir -name aux -o -type d -print0 | xargs -0 chmod ug+rwxs 2> /dev/null || true
145 # create the snapshots
146 exclude='--exclude=.svn'
147 tar -cz $exclude -f $project-snapshot.tgz $project
148 tar -cz $exclude -f $project-sandbox-snapshot.tgz sandbox
149 tar -cz $exclude -f $project-web-snapshot.tgz web
150 ( cd sandbox/gschwant ;
151 tar -cz $exclude -f ../../docfactory-snapshot.tgz docfactory )
153 # plant the snapshots
154 mv -f *snapshot.tgz $htdocsdest
156 # if [ -d $snapshotdest ] ; then
157 # mv -f *snapshot.tgz $snapshotdest
158 # else
159 # echo "Skip snapshots, directory $snapshotdest does not exist"
160 # fi
162 # revert and touch (to avoid updating the web site only because of the
163 # changed timestamp)
164 svn -q revert $project/$project/__init__.py
165 touch $project/$project/__init__.py --date \
166 "`svn info $project/$project/__init__.py | \
167 grep 'Last Changed Date:' | sed 's/[^:]*: //'`"
169 # -------------------- htdocs: --------------------
171 cd $snapshotdir
173 function copy_to_htdocsdest() {
174 find "$@" -type d -name .svn -prune -o \( -type f -o -type l \) -print0 | \
175 xargs -0 cp --no-dereference --update --parents \
176 --target-directory=$htdocsdest
179 # update htdocs
180 copy_to_htdocsdest sandbox
181 (cd $project; copy_to_htdocsdest *)
182 (cd web; copy_to_htdocsdest * .[^.]*)
184 # update HTML docs
185 cd $htdocsdest/tools
187 if [ $trace -eq 0 ] ; then
188 set +o xtrace
191 for makefile in `find .. -name Makefile.docutils-update` ; do
192 dir=`dirname $makefile`
193 ( cd $dir ; make -f Makefile.docutils-update -s )
194 done
196 for htmlfile in `find .. -name '*.html'` ; do
197 dir=`dirname $htmlfile`
198 base=`basename $htmlfile .html`
199 txtfile=$dir/$base.txt
200 if [ -e $txtfile ] ; then
201 if [ $unconditional -eq 1 -o $txtfile -nt $htmlfile ] ; then
202 if [ "${base:0:4}" == "pep-" ] ; then
203 test $feedback && echo "$txtfile (PEP)" || true
204 python $lib/tools/rstpep2html.py --config=$dir/docutils.conf $txtfile $htmlfile
205 haschanges=1
206 else
207 test $feedback && echo $txtfile || true
208 python $lib/tools/rst2html.py --config=$dir/docutils.conf $txtfile $htmlfile
209 haschanges=1
213 done
215 if [ $trace -eq 1 -o $verbose -eq 1 ] ; then
216 set -o xtrace
219 # -------------------- XML sitemap for search engines: --------------------
221 cd $htdocsdest
223 # Update the sitemap only if something has changed because it takes
224 # very much CPU time.
225 if test -n "$haschanges"; then
227 echo '<?xml version="1.0" encoding="UTF-8"?>'
228 echo '<urlset xmlns="http://www.google.com/schemas/sitemap/0.84">'
229 if [ $trace -eq 0 ] ; then
230 set +o xtrace
232 find . -name '.[^.]*' -prune -o -type d -printf '%p/\n' \
233 -o \( -type f -o -type l \) -print | \
234 while read i; do
235 # i is the file name.
236 if test "$i" == ./; then
237 # Homepage.
238 i=index.html
239 url="$baseurl/"
240 elif test "$i" == ./sitemap -o "${i: -1}" == / -a -f "${i}index.html"; then
241 # This is a directory and it has an index.html, so we
242 # don't need to include it.
243 continue
244 else
245 url="$baseurl${i:1}"
246 url="${url// /%20}"
248 lastmod="`date --iso-8601=seconds -u -r "$i"`"
249 # Google wants a colon in front of the last two digits.
250 lastmod="${lastmod::22}:00"
251 if test "${i: -5}" == .html; then
252 # HTML files (including the home page) have highest priority.
253 priority=1.0
254 elif test "${i: -4}" == .txt; then
255 # Text files have medium priority.
256 priority=0.5
257 else
258 # Everything else (source files etc.) has low priority.
259 priority=0.2
261 echo "<url><loc>$url</loc><lastmod>$lastmod</lastmod><priority>$priority</priority></url>"
262 done
263 if [ $trace -eq 1 -o $verbose -eq 1 ] ; then
264 set -o xtrace
266 echo '</urlset>'
267 ) > sitemap
268 gzip -f sitemap
271 # -------------------- Push changes to remote server. --------------------
273 # sourceforge no longer allows shell access, use rsync via ssh
274 # specify your user in your .ssh/config
276 cd $htdocsdest
277 # do not use -a to avoid "failed to set permissions"
278 rsync -e ssh -r ./ web.sourceforge.net:$remotehtdocs
280 trap - 0 1 2 3 15
281 rm -rf $lockdir
282 test $feedback && echo '...docutils-update done.' || true
284 # Local Variables:
285 # indent-tabs-mode: nil
286 # End: