2 # ianb@erislabs.net 20081122
3 # checkpoint code taken from zak's mir-setup
4 # $Id: mir-prepare,v 1.1.2.1 2009/01/18 03:00:22 ianb Exp $
8 CONFDIR="/etc/mir-setup"
11 PACKAGES="openssh-server pwgen apache2 ant tomcat5.5 tomcat5.5-admin imagemagick postgresql libjmagick6-java libapache2-mod-jk procmail cvs rsync sudo wget"
16 CUR_CHECKPOINT=$(($CUR_CHECKPOINT + 1))
17 if [ -n "$START_CHECKPOINT" ]; then
18 if [ "$CUR_CHECKPOINT" -lt "$START_CHECKPOINT" ]; then
19 echo "Skipping checkpoint $CUR_CHECKPOINT: $@"
22 echo "Running from checkpoint $CUR_CHECKPOINT: $@"
26 echo "Checkpoint $CUR_CHECKPOINT: $@"
40 echo >&2 "Try $PROG --help";
45 echo >&2 "Usage: $PROG options"
46 echo >&2 " Prepares system for a mir install"
47 echo >&2 " Run before mir-setup"
48 echo >&2 " -d|--debug Debugging output, including 'set -x' shell trace"
49 echo >&2 " -p|--checkpoint <start> Run from specified checkpoint after failed run"
50 echo >&2 " -j|--java sun|gcj Select Java implementation. Default: sun"
57 -d|--debug) set -x; DEBUG=1 ;;
58 -p|--checkpoint) shift; START_CHECKPOINT="$1" ;;
59 -j|--java) shift; JAVA="$1" ;;
60 -h|-?|--help) usage; exit 0 ;;
61 -*) optdie "$PROG: unknown option $1" ;;
62 *) optdie "$PROG: unexpected argument '$1'" ;;
67 checkpoint "Installing mir-setup"
70 mkdir -p /etc/mir-setup /usr/local/share/mir-setup
71 cp mir-setup mir-choose-java /usr/local/sbin
72 cp munge_config_file.pl /usr/local/share/mir-setup
73 cp conf/* /etc/mir-setup
76 checkpoint "Installing packages"
79 apt-get install $PACKAGES
80 echo "You probably want to do 'apt-get clean'"
83 checkpoint "Selecting $JAVA java with mir-choose-java"
86 mir-choose-java --subprocess $JAVA
89 checkpoint "Enabling apache modules"
92 a2enmod headers ssl include deflate jk rewrite
95 checkpoint "Anonymise apache error log"
98 if [ ! -f /etc/apache2/conf.d/mir-anon-error-log ]
100 echo 'ErrorLog "| /usr/local/bin/strip-ips-from-apache-error-log /var/log/apache2/error.log"' > /etc/apache2/conf.d/mir-anon-error-log
102 cp strip-ips-from-apache-error-log /usr/local/bin
105 checkpoint "Configure 'anon' log format"
108 if [ ! -f /etc/apache2/conf.d/mir-anon-access-log ]
110 echo 'LogFormat "noip %l %u %t \"%r\" %>s %b" anon' > /etc/apache2/conf.d/mir-anon-access-log
114 checkpoint "Creating directory for mir sites in apache"
117 if [ ! -d /etc/apache2/mir-sites ]
119 mkdir /etc/apache2/mir-sites
123 checkpoint "Enabling mir sites in apache"
126 if [ ! -f /etc/apache2/sites-available/mir-sites ]
128 echo "Include /etc/apache2/mir-sites/*.conf" > /etc/apache2/sites-available/mir-sites
133 checkpoint "Configuring apache jakarta workers"
136 if [ ! -f /etc/apache2/conf.d/mir-jk ]
138 echo "JkWorkersFile /etc/libapache2-mod-jk/workers.properties" > /etc/apache2/conf.d/mir-jk
142 checkpoint "Disabling tomcat security (yes, this is bad)"
145 if ! grep -q "^TOMCAT5_SECURITY=no" /etc/default/tomcat5.5
147 echo "TOMCAT5_SECURITY=no" >> /etc/default/tomcat5.5
151 checkpoint "Configuring password for tomcat manager"
154 if ! grep -q 'user username="mir-setup"' /etc/tomcat5.5/tomcat-users.xml
156 PASSWORD=$(pwgen -n 10 1)
157 ROLE=' <role rolename="manager"\/>'
158 USERNAME=' <user username="mir-setup" password="'"$PASSWORD"'" roles="manager"\/>'
159 perl -pi.bak -e 's/(mir-setup:)[^@]+/$1'"$PASSWORD"'/;' /etc/mir-setup/tomcat-manager.conf
160 perl -pi.bak -e 's/(<tomcat-users>)/$1\n'"$ROLE"'\n'"$USERNAME"'\n/;' /etc/tomcat5.5/tomcat-users.xml
164 checkpoint "Creating directory for SSL certs"
167 if [ ! -d /etc/apache2/ssl ]
169 mkdir /etc/apache2/ssl
173 checkpoint "Restarting apache and tomcat"
176 invoke-rc.d tomcat5.5 force-reload
177 invoke-rc.d apache2 force-reload
180 checkpoint "All done!"