2 # ianb@erislabs.net 20081122
3 # checkpoint code taken from zak's mir-setup
4 # $Id: mir-prepare.lenny,v 1.1.2.1 2010/12/16 18:31:08 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.lenny /usr/local/sbin/mir-setup
72 cp mir-choose-java.lenny /usr/local/sbin/mir-choose-java
73 cp munge_config_file.pl /usr/local/share/mir-setup
74 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"
75 (cd conf && cp $CONFFILES /etc/mir-setup)
78 checkpoint "Installing packages"
81 apt-get install $PACKAGES
82 echo "You probably want to do 'apt-get clean'"
85 checkpoint "Selecting $JAVA java with mir-choose-java"
88 mir-choose-java --subprocess $JAVA
91 checkpoint "Enabling apache modules"
94 a2enmod headers ssl include deflate jk rewrite
97 checkpoint "Anonymise apache error log"
100 if [ ! -f /etc/apache2/conf.d/mir-anon-error-log ]
102 echo 'ErrorLog "| /usr/local/bin/strip-ips-from-apache-error-log /var/log/apache2/error.log"' > /etc/apache2/conf.d/mir-anon-error-log
104 cp strip-ips-from-apache-error-log /usr/local/bin
107 checkpoint "Configure 'anon' log format"
110 if [ ! -f /etc/apache2/conf.d/mir-anon-access-log ]
112 echo 'LogFormat "noip %l %u %t \"%r\" %>s %b" anon' > /etc/apache2/conf.d/mir-anon-access-log
116 checkpoint "Creating directory for mir sites in apache"
119 if [ ! -d /etc/apache2/mir-sites ]
121 mkdir /etc/apache2/mir-sites
125 checkpoint "Enabling mir sites in apache"
128 if [ ! -f /etc/apache2/sites-available/mir-sites ]
130 echo "Include /etc/apache2/mir-sites/*.conf" > /etc/apache2/sites-available/mir-sites
135 checkpoint "Configuring apache jakarta workers"
138 if [ ! -f /etc/apache2/conf.d/mir-jk ]
140 echo "JkWorkersFile /etc/libapache2-mod-jk/workers.properties" > /etc/apache2/conf.d/mir-jk
144 checkpoint "Disabling tomcat security (yes, this is bad)"
147 if ! grep -q "^TOMCAT5_SECURITY=no" /etc/default/tomcat5.5
149 echo "TOMCAT5_SECURITY=no" >> /etc/default/tomcat5.5
153 checkpoint "Configuring password for tomcat manager"
156 if ! grep -q 'user username="mir-setup"' /etc/tomcat5.5/tomcat-users.xml
158 PASSWORD=$(pwgen -n 10 1)
159 ROLE=' <role rolename="manager"\/>'
160 USERNAME=' <user username="mir-setup" password="'"$PASSWORD"'" roles="manager"\/>'
161 perl -pi.bak -e 's/(mir-setup:)[^@]+/$1'"$PASSWORD"'/;' /etc/mir-setup/tomcat-manager.conf
162 perl -pi.bak -e 's/(<tomcat-users>)/$1\n'"$ROLE"'\n'"$USERNAME"'\n/;' /etc/tomcat5.5/tomcat-users.xml
166 checkpoint "Creating directory for SSL certs"
169 if [ ! -d /etc/apache2/ssl ]
171 mkdir /etc/apache2/ssl
175 checkpoint "Restarting apache and tomcat"
178 invoke-rc.d tomcat5.5 force-reload
179 invoke-rc.d apache2 force-reload
182 checkpoint "All done!"