Copy mir-setup to 1.1 branch
authorzak <zak>
Sat, 11 Nov 2006 12:52:05 +0000 (12:52 +0000)
committerzak <zak>
Sat, 11 Nov 2006 12:52:05 +0000 (12:52 +0000)
12 files changed:
scripts/mir-setup/README [new file with mode: 0755]
scripts/mir-setup/conf/config [new file with mode: 0755]
scripts/mir-setup/conf/config-examplesite [new file with mode: 0755]
scripts/mir-setup/conf/config.properties-default [new file with mode: 0755]
scripts/mir-setup/conf/env [new file with mode: 0755]
scripts/mir-setup/conf/robots.txt [new file with mode: 0755]
scripts/mir-setup/conf/site-httpd.conf [new file with mode: 0755]
scripts/mir-setup/conf/site-ssl-dedicated-httpd.conf [new file with mode: 0755]
scripts/mir-setup/conf/site-ssl-httpd-fragment.conf [new file with mode: 0755]
scripts/mir-setup/conf/tomcat-manager.conf [new file with mode: 0755]
scripts/mir-setup/mir-setup [new file with mode: 0755]
scripts/mir-setup/munge_config_file.pl [new file with mode: 0755]

diff --git a/scripts/mir-setup/README b/scripts/mir-setup/README
new file mode 100755 (executable)
index 0000000..8f81d2c
--- /dev/null
@@ -0,0 +1,23 @@
+$Id: README,v 1.1.2.1 2006/11/11 12:52:05 zak Exp $
+
+The mir-setup script was developed initially on pulp (the
+UK development server) and then on traven. It hasn't been
+extensively tested outside of those environments, but is
+here in the hope that it is useful.
+
+See http://docs.indymedia.org/view/Sysadmin/TravenMirInstall
+for more information on setting up sites with this script.
+
+The files in this directory should be installed as follows:
+
+mir/scripts/
+  mir-setup              ->   /usr/local/sbin/
+  munge_config_file.pl   ->   /usr/local/share/mir-setup/
+  conf/*                 ->   /etc/mir-setup/
+
+If you choose different locations (for example running the
+script direct from the CVS checkout, you'll need to modify CONFDIR
+(in mir-setup itself) and/or SHAREDIR (in conf/config) accordingly.
+
+Note that this script has only been used with the MIR_1_1 branch so
+far.
diff --git a/scripts/mir-setup/conf/config b/scripts/mir-setup/conf/config
new file mode 100755 (executable)
index 0000000..89c59b5
--- /dev/null
@@ -0,0 +1,38 @@
+# $Id: config,v 1.1.2.1 2006/11/11 12:52:06 zak Exp $
+
+# System configuration file for mir-setup script
+
+# $SITE = short site name, eg "uk"
+# $FQDN = long site name, eg "www.indymedia.org.uk"
+
+# Main install directory for site
+INSTALLDIR=/mir/$SITE
+
+# Directory for produced files (HTML, media etc)
+PRODUCTIONDIR=/imc/mir/$SITE
+
+# Database name
+DATABASE=$SITE
+
+# CVS source for Mir
+MIRCVSROOT=:pserver:anonymous@cvs.codecoop.org:/cvsroot/mir
+
+if [ -z "$MIRVERSION" ]; then MIRVERSION=MIR_1_1; fi
+
+
+# System-wide Postgres, Apache and Tomcat stuff
+
+# Files in this directory should all be included by the main Apache config
+# file with a wildcard
+APACHECONFDIR=/etc/apache2/mir-sites
+
+APACHECTL=/usr/sbin/apache2ctl
+WEBAPPSDIR=/var/lib/tomcat4/webapps
+TOMCATSCRIPT=/etc/init.d/tomcat4
+TOMCATUSER=tomcat4
+
+# May be overridden
+if [ -z "$TOMCATGROUP" ]; then TOMCATGROUP=tomcat4; fi
+
+# Include environment settings
+source "$CONFDIR/env"
diff --git a/scripts/mir-setup/conf/config-examplesite b/scripts/mir-setup/conf/config-examplesite
new file mode 100755 (executable)
index 0000000..6b7c2e5
--- /dev/null
@@ -0,0 +1,48 @@
+# $Id: config-examplesite,v 1.2.2.1 2006/11/11 12:52:06 zak Exp $
+
+# Example site configuration file for mir-setup script
+
+# Short site name
+SITE=examplesite
+
+# Database dump (.tar.gz format) to import rather than using default one
+# DBDUMP=/path/to/dump.tar.gz
+
+# Share database from this config file. Note that this is probably a bad
+# idea, since articles won't get regenerated properly on all installs.
+# However it is how the UK dev server used to work.
+# SHAREDB=/path/to/other/install/config.properties
+
+# Full canonical domain name of production site
+FQDN="publish.$SITE.indymedia.org"
+
+# User to run this site as, and who will have access to files
+USER="$SITE"
+
+# Group to run this site as, and who will have access to files
+GROUP="$SITE"
+
+# Group for tomcat-accessible stuff
+TOMCATGROUP="$SITE-tomcat"
+
+# Aliased domain names for production site
+# ALIASES="www0.$SITE.indymedia.org"
+
+# Full canonical domain name for mirrors
+MIRRORFQDN="www.$SITE.indymedia.org"
+
+# Full canonical domain name for SSL production site
+SECUREFQDN="publish.$SITE.indymedia.org"
+
+# CVS source for site configuration
+SITECVSROOT=":pserver:anonymous@cvs.codecoop.org:/cvsroot/imc-$SITE"
+SITEVERSION= # blank for CVS HEAD
+
+# The content of this directory will be overlaid onto the Mir tree
+SITEOVERLAYDIR="setup_$SITE"
+
+# The config.properties template to use
+CONFIGPROPERTIES="$CONFDIR/config.properties-default"
+
+# Include system config file
+source "$CONFDIR/config"
diff --git a/scripts/mir-setup/conf/config.properties-default b/scripts/mir-setup/conf/config.properties-default
new file mode 100755 (executable)
index 0000000..e5dee0e
--- /dev/null
@@ -0,0 +1,331 @@
+# $Id: config.properties-default,v 1.1.2.1 2006/11/11 12:52:06 zak Exp $
+# Based on mir/etc/config.properties-dist 1.31.2.5
+#
+# Sample config for Mir
+# by Matthias <mjordan@code-fu.de> 2001-09-12
+# reorganized by <init@nadir.org>  2003-02-12
+#
+# The Mir software realizes a semi-dynamic web service:
+# The web server that is accessed by readers has pure static
+# pages. These pages are generated by the Mir software that
+# consists of a collection of Java servlets and HTML templates.
+#
+# Mir uses a database server to store the data that is needed to
+# build the static site.
+# So there are basically three parts in this config file:
+#
+# a) general & admin setup
+# b) static site config
+# c) dynamic site
+# d) database config
+#
+# edit this to suit your needs
+# After editing this file, two steps need to be taken to make the changes effective:
+#   1. ant has to be invoked.
+#   2. tomcat needs to be restarted.
+#
+# This file only contains the properties that are most often changed. To view all
+# possible config values, refer to the file default.properties, located in the
+# source directory. Don't change settings in default.properties however, instead
+# use this file.
+#
+# Note: for filename values, by default, files are used relative to the servlet's
+# WEB-INF directory.
+#
+# The setup uses the following assumptions:
+# The URL to reach the site is http://mir.someserver.org
+# The StorageRoot of this URL is /var/www/project/site/
+# All produced pages and media are located below this directory.
+
+################################################
+############    A) GENERAL SETUP  ##############
+################################################
+
+# mir/project an contact information
+# for display on the site
+#
+Mir.Name=$FQDN
+Mir.Shortname=$SITE
+
+Mir.Contact-email.address=webmaster@$FQDN
+Mir.Contact-email.name=$FQDN webmaster
+
+Mir.Tech-email.address=webmaster@$FQDN
+Mir.Tech-email.name=$FQDN technical contact
+
+Mir.Public-email.address=webmaster@$FQDN
+Mir.Public-email.name=$FQDN public contact
+
+# Default timezone to display times in in admin, producers
+# use CET for Central European Time (Paris, Amsterdam)
+# more timezones here: http://www.postgresql.org/docs/7.2/static/timezones.html
+#
+Mir.DefaultTimezone= America/New_York
+
+# Default date/time format
+# For the syntax of the format, refer to
+# http://java.sun.com/j2se/1.3/docs/api/java/text/SimpleDateFormat.html
+Mir.DefaultDateTimeFormat = yyyy-MM-dd HH:mm
+
+# For missing values, the FallbackLanguage is used as default
+#
+Mir.Admin.FallbackLanguage=en
+
+#################################
+# admin interface configuration #
+#################################
+
+# Settings for the admin login:
+# If the default language is left empty, it will set the accept-language of
+# the client browser as the default.
+#
+Mir.Login.DefaultLanguage=en
+Mir.Login.Languages=en;de;fr;nl;es;pt;eu;sv;tr;zh;gz
+
+# Show who's logged in?
+#
+Mir.Admin.ShowLoggedinUsers=1
+
+# enable deletion of comments/articles?
+#
+Mir.Localizer.Admin.AllowDeleteComment=1
+Mir.Localizer.Admin.AllowDeleteArticle=1
+
+#######################
+# automated producers #
+#######################
+
+# Which producers need to be called after an article is posted
+#
+Mir.Localizer.OpenPosting.ContentProducers= \
+media.new;articles.changed;startpage.generate;synchronization.run
+
+# Which producers need to be called after a comment is posted
+#
+Mir.Localizer.OpenPosting.CommentProducers= \
+articles.changed;synchronization.run
+
+# Which producers need to be called after the "produce all new" link is clicked from admin
+#
+Mir.Localizer.Producer.AllNewProducers= \
+media.new;articles.changed;startpage.run;synchronization.run
+
+#########
+# rsync #
+#########
+
+#use rsync to mirror the website to a remote-host
+#
+Rsync=no
+Rsync.Script.Path=/var/www/bin/rsync-copy.sh
+
+
+###################
+# FileEdit module #
+###################
+
+# for extra flexibility editors can edit text-files from within the admin-interface
+# these files can then be included in webpages using SSI as footer or announcement-box...
+#
+# a list of directories to edit
+# format:
+#      <name>:<path>:<file filter>:<0|1 (recursion off or on)> [, ....]
+#
+ServletModule.FileEdit.Configuration= \
+  includes:/var/www/project/site/includes:.*\\.inc:1
+
+################################################
+###########  B) STATIC SITE CONFIG #############
+################################################
+
+# the url of the static site
+# on the machine where mir runs on
+#
+Producer.ProductionHost=http://$FQDN
+
+# the url of the public site
+# only different from ProductionHost if pages are copied to
+# one ore more mirror-servers for delivery
+#
+Producer.PublicationHost=http://$MIRRORFQDN
+
+# Produrce.StorageRoot is the directory, in which
+# the generated HTML pages will be stored
+#
+Producer.StorageRoot=$PRODUCTIONDIR
+
+# use this property only if the pages are NOT produced under the docRoot
+# of the webserver. all links in the produced pages are prepended
+# with Producer.DocRoot
+#
+Producer.DocRoot=
+
+
+#####################
+# media server URLs #
+#####################
+
+# for better performance or load-sharing
+# images/media can be copied to (and served from) different servers
+# only in this case image- and medialinks need different URLs.
+
+# the url of the video-server
+#
+Producer.Video.Host=/video
+
+# the url of the audio-server
+#
+Producer.Audio.Host=/audio
+
+# the url of the image-server
+#
+Producer.Image.Host=/images
+
+# the url of the media-server
+#
+Producer.Media.Host=/media
+
+# the url of the real-media-server
+#
+Producer.RealMedia.Host=rtsp://$MIRRORFQDN/real/
+
+
+
+############################################
+# image/media specific storage directories #
+############################################
+
+# absolute directory, where the images are saved
+#
+Producer.Image.Path=$PRODUCTIONDIR/images/
+
+
+# absolute directory, where the media files are saved
+#
+Producer.Media.Path=$PRODUCTIONDIR/media
+
+# absolute directory, where the realmedia data files(ra and rm) are saved
+# the ram files which point to the RealMedia.Host get saved in the regular Media dir
+# this should make rsyncing to a separate streaming server much easier
+#
+Producer.RealMedia.Path=$PRODUCTIONDIR/rtsp
+
+# mir creates a small thumbnail-icon for each image posted
+# relativ directory, where the thumbnails will be saved
+#
+Producer.Image.IconPath=/icon
+
+
+####################
+# media-type-icons #
+####################
+
+# by default they are stored in the webservers [docRoot]/img directory
+# they are distibuted with the mir-source (etc/producer/images)
+# use the "staticimages.generate" producer once to copy them in place
+#
+
+# Tiny Icons for the media types on the newswire summary.
+# (right hand side of start page)
+#
+Producer.Icon.TinyImage=photo_small.gif
+Producer.Icon.TinyAudio=audio_small.gif
+Producer.Icon.TinyVideo=video_small.gif
+Producer.Icon.TinyText=text_small.gif
+
+#Medium sized icons used at various places
+#
+Producer.Icon.BigImage=photo_big.gif
+Producer.Icon.BigAudio=audio_big.gif
+Producer.Icon.BigVideo=video_big.gif
+Producer.Icon.BigText=text_big.gif
+
+#Icons used for links
+#
+Producer.ExtLinkName=extlink.gif
+Producer.IntLinkName=intlink.gif
+Producer.MailLinkName=maillink.gif
+
+# this is the name of the subdirectory where the image-dir
+# will be linked to.
+#
+Producer.ImageRoot=/img
+
+
+
+################################################
+########### C) DYNAMIC SITE CONFIG #############
+################################################
+
+# the main mir-servlet
+#
+Producer.ActionServlet=/servlet/Mir
+
+# the url of the openposting-servlet
+#
+Producer.OpenAction=https://$SECUREFQDN/$SITE/servlet/OpenMir
+
+# the maximum allowed size of an uploaded media file in KB.
+#
+MaxMediaUploadSize=20000
+
+# the maximum number of allowed media items to upload at once.
+#
+ServletModule.OpenIndy.MaxMediaUploadItems=20
+
+# the default number of media items to upload at once
+#
+ServletModule.OpenIndy.DefaultMediaUploadItems=1
+
+
+######################
+# PDF configurations #
+######################
+
+# the following lines are used to construct PDFs on the fly from one or more articles
+# for the moment, if you want to change anything else about your pdfs, you
+# will have to learn some java!
+#
+# keep in mind that there may not be enough room for all the text you enter as the
+# value of one these options, if text doesn't appear, the only easy thing to do is
+# use less text!
+#
+
+# a single line of big text which will appear at the top of the first page of all generated pdfs
+#
+PDF.Title=$FQDN
+
+# about two lines of small text which will appear at the bottom of every page
+#
+PDF.Footer=Mir-CMS PDF-Newsletter.  Content is good, and free to use for non-commercial purposes under the Open Content license. If you have questions, email someone.
+
+# the size paper your target audience will likely have in their printers.
+# pick one of A4 or LETTER
+#
+PDF.PageSize=A4
+
+################################################
+############ D) DATABASE CONFIG   ##############
+################################################
+
+# specify your database
+#
+Database.Name=$DBNAME
+Database.Username=$DBUSER
+Database.Password=$DBPASS
+
+Database.Host=localhost
+Database.Port=5432
+Database.Driver=org.postgresql.Driver
+
+
+############################################
+# encoding configuration                   #
+############################################
+
+# The default encoding charset used in the written html files as well
+# as the dynamic output html.
+Mir.DefaultHTMLCharset=UTF-8
+
+# The java equivalent of Mir.DefaultHTMLCharset
+Mir.DefaultEncoding=UTF8
diff --git a/scripts/mir-setup/conf/env b/scripts/mir-setup/conf/env
new file mode 100755 (executable)
index 0000000..12a3fc6
--- /dev/null
@@ -0,0 +1,5 @@
+export TOMCAT_HOME=/var/lib/tomcat4
+export JAI_HOME=/usr/local/lib/jai-1_1_2_01/lib
+export JAI_IIO_HOME=/usr/local/lib/jai_imageio-1_0_01/lib
+export CLASSPATH=.:$JAI_IIO_HOME/clibwrapper_jiio.jar:$JAI_IIO_HOME/jai_imageio.jar:$JAI_HOME/jai_core.jar:$JAI_HOME/jai_codec.jar:$JAI_HOME/mlibwrapper_jai.jar:/usr/share/java:$CLASSPATH
+export LD_LIBRARY_PATH=$JAI_IIO_HOME:$JAI_HOME:$LD_LIBRARY_PATH
diff --git a/scripts/mir-setup/conf/robots.txt b/scripts/mir-setup/conf/robots.txt
new file mode 100755 (executable)
index 0000000..1f53798
--- /dev/null
@@ -0,0 +1,2 @@
+User-agent: *
+Disallow: /
diff --git a/scripts/mir-setup/conf/site-httpd.conf b/scripts/mir-setup/conf/site-httpd.conf
new file mode 100755 (executable)
index 0000000..87f0921
--- /dev/null
@@ -0,0 +1,44 @@
+# Editor: vim:syn=apache
+# $FQDN
+<VirtualHost *:80>
+  ServerAdmin $USER@$FQDN
+  DocumentRoot $PRODUCTIONDIR
+  ServerName $FQDN
+  ServerAlias $ALIAS
+
+  CustomLog /var/log/apache2/$SITE.log combined
+
+# Back end should only be accessed via SSL; bounce to enforce this
+  Redirect /$SITE/servlet/Mir https://$SECUREFQDN/$SITE/servlet/Mir
+  
+  <Location /$SITE>
+    JkUriSet worker ajp13:localhost:8009
+  </Location>
+  <Directory $PRODUCTIONDIR>
+    Options Indexes IncludesNoExec FollowSymLinks MultiViews
+    IndexOptions +SuppressHTMLPreamble +SuppressDescription
+    AddHandler server-parsed .html
+    AddType 'text/html; charset=utf-8' .html
+    AllowOverride None
+    Order allow,deny
+    Allow from all  
+  </Directory>
+  # Apache gzip compression
+  <Location />
+    # This is taken from here: 
+    # http://httpd.apache.org/docs-2.0/mod/mod_deflate.html
+    # Insert filter
+    SetOutputFilter DEFLATE
+    # Netscape 4.x has some problems...
+    BrowserMatch ^Mozilla/4 gzip-only-text/html
+    # Netscape 4.06-4.08 have some more problems
+    BrowserMatch ^Mozilla/4\.0[678] no-gzip
+    # MSIE masquerades as Netscape, but it is fine
+    BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
+    # Don't compress images
+    SetEnvIfNoCase Request_URI \
+    \.(?:gif|jpe?g|png)$ no-gzip dont-vary
+    # Make sure proxies don't deliver the wrong content
+    Header append Vary User-Agent env=!dont-vary
+  </Location>
+</VirtualHost>
diff --git a/scripts/mir-setup/conf/site-ssl-dedicated-httpd.conf b/scripts/mir-setup/conf/site-ssl-dedicated-httpd.conf
new file mode 100755 (executable)
index 0000000..211e8f4
--- /dev/null
@@ -0,0 +1,42 @@
+# Editor: vim:syn=apache
+# $SECUREFQDN (SSL)
+<VirtualHost $SECUREFQDN:443>
+  ServerAdmin $USER@$FQDN
+  DocumentRoot $PRODUCTIONDIR
+  ServerName $SECUREFQDN
+
+  SSLEngine on
+  SSLCertificateFile /etc/apache2/ssl/$SECUREFQDN.crt
+  SSLCertificateKeyFile /etc/apache2/ssl/$SECUREFQDN.key
+
+  <Location /$SITE>
+    JkUriSet worker ajp13:localhost:8009
+  </Location>
+  <Directory $PRODUCTIONDIR>
+    Options Indexes IncludesNoExec FollowSymLinks MultiViews
+    IndexOptions +SuppressHTMLPreamble +SuppressDescription
+    AddHandler server-parsed .html
+    AddType 'text/html; charset=utf-8' .html
+    AllowOverride None
+    Order allow,deny
+    Allow from all  
+  </Directory>
+  # Apache gzip compression
+  <Location />
+    # This is taken from here: 
+    # http://httpd.apache.org/docs-2.0/mod/mod_deflate.html
+    # Insert filter
+    SetOutputFilter DEFLATE
+    # Netscape 4.x has some problems...
+    BrowserMatch ^Mozilla/4 gzip-only-text/html
+    # Netscape 4.06-4.08 have some more problems
+    BrowserMatch ^Mozilla/4\.0[678] no-gzip
+    # MSIE masquerades as Netscape, but it is fine
+    BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
+    # Don't compress images
+    SetEnvIfNoCase Request_URI \
+    \.(?:gif|jpe?g|png)$ no-gzip dont-vary
+    # Make sure proxies don't deliver the wrong content
+    Header append Vary User-Agent env=!dont-vary
+  </Location>
+</VirtualHost>
diff --git a/scripts/mir-setup/conf/site-ssl-httpd-fragment.conf b/scripts/mir-setup/conf/site-ssl-httpd-fragment.conf
new file mode 100755 (executable)
index 0000000..e78ebd0
--- /dev/null
@@ -0,0 +1,10 @@
+# Editor: vim:syn=apache
+# $FQDN
+
+# This should be included within the SSL virtual host definition
+# for a canonical host which has a dedicated IP address. If your
+# site has its own IP, this can be the same as your ususl hostname.
+
+  <Location /$SITE>
+    JkUriSet worker ajp13:localhost:8009
+  </Location>
diff --git a/scripts/mir-setup/conf/tomcat-manager.conf b/scripts/mir-setup/conf/tomcat-manager.conf
new file mode 100755 (executable)
index 0000000..47f7446
--- /dev/null
@@ -0,0 +1,7 @@
+# $Id: tomcat-manager.conf,v 1.1.2.1 2006/11/11 12:52:06 zak Exp $
+
+# Configuration for Tomcat manager access
+
+# Put mir-setup's Tomcat manager password in this URL:
+
+TOMCAT_MANAGER_URL=http://mir-setup:PASSWORD@localhost:8180/manager
diff --git a/scripts/mir-setup/mir-setup b/scripts/mir-setup/mir-setup
new file mode 100755 (executable)
index 0000000..e08f9da
--- /dev/null
@@ -0,0 +1,291 @@
+#!/bin/bash
+# $Id: mir-setup,v 1.2.2.1 2006/11/11 12:52:05 zak Exp $
+
+# Script to install a new Mir site
+
+# Initial version -zak 2005-01-23
+# Moved to traven -zak 2005-04-05
+# Added to CVS    -zak 2005-06-13
+
+set -e
+
+CONFDIR="/etc/mir-setup"
+SHAREDIR="/usr/local/share/mir-setup"
+PROG="`basename $0`"
+
+die()
+{
+  echo >&2 "$@";
+  exit 1;
+}
+
+optdie()
+{
+  echo >&2 "$@";
+  echo >&2 "Try $PROG --help";
+  exit 1;
+}
+
+manage()
+{
+  (
+    source "$CONFDIR/tomcat-manager.conf"
+    
+    if [ -z "$TOMCAT_MANAGER_URL" ]; then die "No TOMCAT_MANAGER_URL specified"; fi
+    
+    echo "$TOMCAT_MANAGER_URL/html/$1?path=/$2" | wget -q -O /dev/null -i -
+  ) 
+}
+
+usage() {
+    echo >&2 "Usage: $PROG options"
+    echo >&2
+    echo >&2 "  Exactly one of the following is required:"
+    echo >&2 "    -f|--config <file>        mir-setup site config file"
+    echo >&2 "       --start  <site>        start the given site's webapp"
+    echo >&2 "       --stop   <site>        stop the given site's webapp"
+    echo >&2 "       --reload <site>        reload the given site's webapp"
+    echo >&2
+    echo >&2 "  Debugging options:"
+    echo >&2 "    -d|--debug                Debugging output, including 'set -x' shell trace"
+    echo >&2 "    -p|--checkpoint <start>   Run from specified checkpoint after failed run"
+}
+
+while [ $# != 0 ]; do
+    case "$1" in
+        -f|--config) shift; CONFIGFILE="$1" ;;
+        --start|--stop|--reload) ACTION="$1"; shift; SITE="$1" ;;
+       -d|--debug)  set -x; DEBUG=1 ;;
+       -p|--checkpoint) shift; START_CHECKPOINT="$1" ;;
+       -h|-?|--help) usage; exit 0 ;;
+        -*) optdie "$PROG: unknown option $1" ;;
+       *) optdie "$PROG: unexpected argument '$1'" ;;
+    esac
+    shift
+done
+
+case "$ACTION" in
+    --start|--stop|--reload)
+        if [ -n "$CONFIGFILE" ]; then optdie "$PROG: config file specified with $ACTION"; fi
+       echo -n "$ACTION"ing "$SITE..."
+       manage "`echo "$ACTION" | sed -e 's/^--//'`" "$SITE"
+       echo " done."
+       exit 0
+        ;;
+esac
+       
+if [ -z "$CONFIGFILE" ]; then optdie "$PROG: no site config file; use -f"; fi
+
+source "$CONFIGFILE"
+
+if [ -z "$SITE" ]; then optdie "$PROG: no site name"; fi
+if [ -z "$FQDN" ]; then optdie "$PROG: no site fqdn"; fi
+if [ -z "$USER" ]; then optdie "$PROG: no user"; fi
+
+OWNER="$USER:$GROUP"
+TOMCATOWNER="$USER:$TOMCATGROUP"
+
+if [ -n "$GROUP" ]; then
+    umask 002
+    PRIVMODE=660
+else
+    umask 022
+    PRIVMODE=600
+fi
+
+if [ -n "$MIRVERSION" ]; then MIRVERSIONOPT="-r$MIRVERSION"; fi
+if [ -n "$SITEVERSION" ]; then SITEVERSIONOPT="-r$SITEVERSION"; fi
+
+if [ -n "$SHAREDB" ]; then
+  if [ -n "$DBNAME" ]; then optdie "$PROG: SHAREDB and DBNAME set"; fi
+  if [ -n "$DBUSER" ]; then optdie "$PROG: SHAREDB and DBUSER set"; fi
+  if [ -n "$DBPASS" ]; then optdie "$PROG: SHAREDB and DBPASS set"; fi
+  
+  DBNAME="`perl -ne 'if (/\s*Database\.Name\s*=\s*(\S+)/) { print "$1\n" }' /mir/uk/setup_uk/etc/config.properties`"
+  DBUSER="`perl -ne 'if (/\s*Database\.Username\s*=\s*(\S+)/) { print "$1\n" }' /mir/uk/setup_uk/etc/config.properties`"
+  DBPASS="`perl -ne 'if (/\s*Database\.Password\s*=\s*(\S+)/) { print "$1\n" }' /mir/uk/setup_uk/etc/config.properties`"
+else
+  if [ -z "$DBNAME" ]; then DBNAME="$SITE"; fi
+  if [ -z "$DBUSER" ]; then DBUSER="$SITE"; fi
+  if [ -z "$DBPASS" ]; then DBPASS="`pwgen -s 8 1`"; fi
+fi
+
+if [ -z "$CONFIGPROPERTIES" ]; then CONFIGPROPERTIES="$CONFDIR/config.properties"; fi
+if [ ! -e "$CONFIGPROPERTIES" ]; then
+  optdie "$CONFIGPROPERTIES does not exist"
+fi
+
+CUR_CHECKPOINT=0
+checkpoint()
+{
+  CUR_CHECKPOINT=$(($CUR_CHECKPOINT + 1))
+  if [ -n "$START_CHECKPOINT" ]; then
+    if [ "$CUR_CHECKPOINT" -lt "$START_CHECKPOINT" ]; then
+      echo "Skipping checkpoint $CUR_CHECKPOINT: $@"
+      unset RUNNING
+    else
+      echo "Running from checkpoint $CUR_CHECKPOINT: $@"
+      RUNNING=1
+    fi
+  else
+    echo "Checkpoint $CUR_CHECKPOINT: $@"
+    RUNNING=1
+  fi
+}
+
+checkpoint "Prepare install directory: $INSTALLDIR"
+if [ -n "$RUNNING" ]; then
+  mkdir -p "$INSTALLDIR"
+  chown "$OWNER" "$INSTALLDIR"
+  chmod g+s "$INSTALLDIR"
+fi
+
+checkpoint "Check out Mir [$MIRVERSION] from $MIRCVSROOT"
+if [ -n "$RUNNING" ]; then
+  cd "$INSTALLDIR"
+  sudo -u "$USER" cvs -z3 -d"$MIRCVSROOT" checkout $MIRVERSIONOPT mir
+  chown -R "$OWNER" mir
+fi
+checkpoint "Check out site templates [$SITEVERSION] from $SITECVSROOT"
+if [ -n "$RUNNING" ]; then
+  cd "$INSTALLDIR"
+  sudo -u "$USER" cvs -z3 -d"$SITECVSROOT" checkout $SITEVERSIONOPT "$SITEOVERLAYDIR"
+  chown -R "$OWNER" "$SITEOVERLAYDIR"
+fi
+
+checkpoint "Prepare production directory: $PRODUCTIONDIR"
+if [ -n "$RUNNING" ]; then
+  mkdir -p "$PRODUCTIONDIR"
+  chown "$TOMCATOWNER" "$PRODUCTIONDIR"
+  chmod g+s "$PRODUCTIONDIR"
+  cd "$PRODUCTIONDIR"
+  PRODUCTIONSUBDIRS="abstract comments content de en img inc style"
+  mkdir -p $PRODUCTIONSUBDIRS
+  chown "$TOMCATOWNER" $PRODUCTIONSUBDIRS
+  ln -snf en/index.html
+fi
+
+munge_config_file()
+{
+  (
+    export SITE
+    export FQDN
+    export MIRRORFQDN
+    export SECUREFQDN
+    export ALIASES
+    export USER
+    export DBNAME
+    export DBUSER
+    export DBPASS
+    export PRODUCTIONDIR
+
+    perl -w "$SHAREDIR/munge_config_file.pl" <"$1" >"$2"
+    chown "$OWNER" "$2"
+  )
+}
+
+checkpoint "Install robots.txt file"
+if [ -n "$RUNNING" ]; then
+  munge_config_file "$CONFDIR/robots.txt" "$PRODUCTIONDIR/robots.txt"
+fi
+
+checkpoint "Install site-specific Apache configuration file (non-SSL)"
+if [ -n "$RUNNING" ]; then
+  mkdir -p "$APACHECONFDIR"
+  munge_config_file "$CONFDIR/site-httpd.conf" "$APACHECONFDIR/$SITE.conf"
+fi
+
+checkpoint "Install site-specific Apache configuration file (SSL on dedicated IP)"
+if [ -n "$RUNNING" ]; then
+  mkdir -p "$APACHECONFDIR/ssl-dedicated"
+  munge_config_file "$CONFDIR/site-ssl-dedicated-httpd.conf" "$APACHECONFDIR/ssl-dedicated/$SITE.conf"
+fi
+
+checkpoint "Install site-specific Apache configuration file (SSL fragment for webapp via canonical host)"
+if [ -n "$RUNNING" ]; then
+  mkdir -p "$APACHECONFDIR/ssl-fragments"
+  munge_config_file "$CONFDIR/site-ssl-httpd-fragment.conf" "$APACHECONFDIR/ssl-fragments/$SITE.conf"
+fi
+
+checkpoint "Restart Apache with new configuration"
+if [ -n "$RUNNING" ]; then
+  "$APACHECTL" configtest
+  "$APACHECTL" graceful
+fi
+
+checkpoint "Overlay /etc from site template"
+if [ -n "$RUNNING" ]; then
+  cd "$INSTALLDIR/mir"
+  mv etc etc.orig
+  ln -snf "../$SITEOVERLAYDIR/etc"
+fi
+
+if [ -n "$SHAREDB" ]; then
+  checkpoint "Sharing existing database (not creating)"
+  checkpoint "Sharing existing database (not importing/installing)"
+  checkpoint "Sharing existing database (not setting permissions)"
+else
+  checkpoint "Create database"
+  if [ -n "$RUNNING" ]; then
+    sudo -u postgres createdb --encoding=unicode "$DBNAME"
+    sudo -u postgres psql "$DBNAME" <<EOF
+CREATE USER $DBUSER WITH PASSWORD '$DBPASS' NOCREATEDB NOCREATEUSER;
+UPDATE pg_database SET datdba=(SELECT usesysid FROM pg_user WHERE usename='$DBUSER') WHERE datname='$DBNAME';
+EOF
+  fi
+  
+  if [ -n "$DBDUMP" ]; then
+    checkpoint "Import database dump"
+    if [ -n "$RUNNING" ]; then
+      zcat "$DBDUMP" | sudo -u postgres pg_restore -d "$DBNAME" -O -x
+    fi
+  else
+    checkpoint "Install default database"
+    if [ -n "$RUNNING" ]; then
+      for i in "$INSTALLDIR"/mir/dbscripts/{create_pg,help*,populate*}.sql; do
+        sudo -u postgres psql -f $i "$DBNAME"
+      done
+    fi
+  fi
+
+  checkpoint "Set database permissions"
+  if [ -n "$RUNNING" ]; then
+    # Clumsy -- produces errors which we should ignore
+    echo >&2 "Don't worry about errors from some of the GRANTs here"
+    sudo -u postgres psql -qto "|psql \"$DBNAME\"" "$DBNAME" <<EOF
+SELECT 'GRANT ALL ON '||relname||' TO $DBUSER;'
+FROM pg_class
+WHERE relname not like 'pg%'
+ORDER by relname;
+EOF
+  fi
+fi
+
+checkpoint "Install config.properties"
+if [ -n "$RUNNING" ]; then
+  touch "$INSTALLDIR/mir/etc/config.properties"
+  chmod "$PRIVMODE" "$INSTALLDIR/mir/etc/config.properties"
+  munge_config_file "$CONFIGPROPERTIES" "$INSTALLDIR/mir/etc/config.properties"
+fi
+
+checkpoint "Running ant to build Mir"
+if [ -n "$RUNNING" ]; then
+  cd "$INSTALLDIR/mir"
+  sudo -u "$USER" ant
+fi
+
+checkpoint "Fixing file permissions"
+if [ -n "$RUNNING" ]; then
+  cd "$INSTALLDIR/mir"
+  sed -e "s/^GROUP=.*\$/GROUP=$TOMCATGROUP/" perms.sh-dist >perms.sh
+  chmod +x perms.sh
+  ./perms.sh
+fi
+
+checkpoint "Linking into Tomcat Web apps directory"
+if [ -n "$RUNNING" ]; then
+  cd "$WEBAPPSDIR"
+  ln -snf "$INSTALLDIR/mir/bin/mir" "$SITE"
+fi
+
+checkpoint "All done!"
diff --git a/scripts/mir-setup/munge_config_file.pl b/scripts/mir-setup/munge_config_file.pl
new file mode 100755 (executable)
index 0000000..c0d98fb
--- /dev/null
@@ -0,0 +1,42 @@
+#!/usr/bin/perl -w
+# $Id: munge_config_file.pl,v 1.1.2.1 2006/11/11 12:52:05 zak Exp $
+
+use strict;
+
+my $SITE = $ENV{"SITE"};
+my $FQDN = $ENV{"FQDN"};
+my $MIRRORFQDN = $ENV{"MIRRORFQDN"};
+my $SECUREFQDN = $ENV{"SECUREFQDN"};
+my $USER = $ENV{"USER"};
+my $DBNAME = $ENV{"DBNAME"};
+my $DBUSER = $ENV{"DBUSER"};
+my $DBPASS = $ENV{"DBPASS"};
+my $PRODUCTIONDIR = $ENV{"PRODUCTIONDIR"};
+my @ALIASES = defined $ENV{"ALIASES"} ? split ' ', $ENV{"ALIASES"} : ();
+
+while (my $line = <>)
+{
+    $line =~ s/\$SITE\b/$SITE/g;
+    $line =~ s/\$FQDN\b/$FQDN/g;
+    $line =~ s/\$MIRRORFQDN\b/$MIRRORFQDN/g;
+    $line =~ s/\$SECUREFQDN\b/$SECUREFQDN/g;
+    $line =~ s/\$USER\b/$USER/g;
+    $line =~ s/\$DBNAME\b/$DBNAME/g;
+    $line =~ s/\$DBUSER\b/$DBUSER/g;
+    $line =~ s/\$DBPASS\b/$DBPASS/g;
+    $line =~ s/\$PRODUCTIONDIR\b/$PRODUCTIONDIR/g;
+      
+    if ($line =~ /\$ALIAS\b/)
+    {
+        for my $alias (@ALIASES)
+       {
+           my $out = $line;
+           $out =~ s/\$ALIAS\b/$alias/g;
+           print $out;
+        }
+    }
+    else
+    {
+       print $line;
+    }
+}