2 # ianb@erislabs.net 20081122
3 # checkpoint code taken from zak's mir-setup
4 # $Id: mir-prepare,v 1.1.2.2 2009/01/18 04:43:02 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 CONFFILES="config config-examplesite config.properties-default env robots.txt site-httpd.conf site-ssl-dedicated-httpd.conf site-ssl-httpd-fragment.conf tomcat-manager.conf"
74 (cd conf && cp $CONFFILES /etc/mir-setup)
77 checkpoint "Installing packages"
80 apt-get install $PACKAGES
81 echo "You probably want to do 'apt-get clean'"
84 checkpoint "Selecting $JAVA java with mir-choose-java"
87 mir-choose-java --subprocess $JAVA
90 checkpoint "Enabling apache modules"
93 a2enmod headers ssl include deflate jk rewrite
96 checkpoint "Anonymise apache error log"
99 if [ ! -f /etc/apache2/conf.d/mir-anon-error-log ]
101 echo 'ErrorLog "| /usr/local/bin/strip-ips-from-apache-error-log /var/log/apache2/error.log"' > /etc/apache2/conf.d/mir-anon-error-log
103 cp strip-ips-from-apache-error-log /usr/local/bin
106 checkpoint "Configure 'anon' log format"
109 if [ ! -f /etc/apache2/conf.d/mir-anon-access-log ]
111 echo 'LogFormat "noip %l %u %t \"%r\" %>s %b" anon' > /etc/apache2/conf.d/mir-anon-access-log
115 checkpoint "Creating directory for mir sites in apache"
118 if [ ! -d /etc/apache2/mir-sites ]
120 mkdir /etc/apache2/mir-sites
124 checkpoint "Enabling mir sites in apache"
127 if [ ! -f /etc/apache2/sites-available/mir-sites ]
129 echo "Include /etc/apache2/mir-sites/*.conf" > /etc/apache2/sites-available/mir-sites
134 checkpoint "Configuring apache jakarta workers"
137 if [ ! -f /etc/apache2/conf.d/mir-jk ]
139 echo "JkWorkersFile /etc/libapache2-mod-jk/workers.properties" > /etc/apache2/conf.d/mir-jk
143 checkpoint "Disabling tomcat security (yes, this is bad)"
146 if ! grep -q "^TOMCAT5_SECURITY=no" /etc/default/tomcat5.5
148 echo "TOMCAT5_SECURITY=no" >> /etc/default/tomcat5.5
152 checkpoint "Configuring password for tomcat manager"
155 if ! grep -q 'user username="mir-setup"' /etc/tomcat5.5/tomcat-users.xml
157 PASSWORD=$(pwgen -n 10 1)
158 ROLE=' <role rolename="manager"\/>'
159 USERNAME=' <user username="mir-setup" password="'"$PASSWORD"'" roles="manager"\/>'
160 perl -pi.bak -e 's/(mir-setup:)[^@]+/$1'"$PASSWORD"'/;' /etc/mir-setup/tomcat-manager.conf
161 perl -pi.bak -e 's/(<tomcat-users>)/$1\n'"$ROLE"'\n'"$USERNAME"'\n/;' /etc/tomcat5.5/tomcat-users.xml
165 checkpoint "Creating directory for SSL certs"
168 if [ ! -d /etc/apache2/ssl ]
170 mkdir /etc/apache2/ssl
174 checkpoint "Restarting apache and tomcat"
177 invoke-rc.d tomcat5.5 force-reload
178 invoke-rc.d apache2 force-reload
181 checkpoint "All done!"