]> git.evergreen-ils.org Git - working/random.git/blob - installer/wheezy/eg_wheezy_installer.sh
more separation of output
[working/random.git] / installer / wheezy / eg_wheezy_installer.sh
1 #!/bin/bash
2 # -----------------------------------------------------------------------
3 # Copyright (C) 2009-2012  Equinox Software Inc.
4 # Bill Erickson <berick@esilibrary.com>
5
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version.
10
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15 # -----------------------------------------------------------------------
16
17 date
18
19 DOJO_VERSION='1.3.3';
20
21 export PATH=/openils/bin:$PATH
22 export LD_LIBRARY_PATH=/openils/lib:/usr/local/lib:/usr/local/lib/dbd:$LD_LIBRARY_PATH
23
24 # -----------------------------------------------------------------------
25 # Change to suit...
26 # -----------------------------------------------------------------------
27 # If you change the jabber password, you will need to 
28 # edit opensrf_core.xml and srfsh.xml accordingly
29 JABBER_PASSWORD='password'
30 ADMIN_USER='admin';
31 ADMIN_PASS='demo123';
32 # -----------------------------------------------------------------------
33
34 # -----------------------------------------------------------------------
35 # Handling passed arguments to the script
36 # -----------------------------------------------------------------------
37 while getopts ayst option
38 do
39         case "${option}"
40         in
41                 a) AUTOSTART=1;;
42                 y) YES=1;;
43                 s) SAMPLEDATA=--load-all-sample;;
44                 t) LIVETEST=1;;
45         esac
46 done
47
48 # -----------------------------------------------------------------------
49 # force CPAN to load by installing something that should already be installed
50 if [ $YES ]; then
51     yes | cpan Fcntl
52 else
53     cpan Fcntl
54 fi
55
56 # CPAN follow pre-reqs?
57 if [ ! "$(echo 'o conf prerequisites_policy' | cpan | grep follow)" ]; then
58 if [ $YES ]; then
59
60     echo "setting cpan prerequisites_policy to follow"
61     echo -e "o conf prerequisites_policy follow\\n o conf commit" | cpan
62
63 else
64
65     echo '
66
67 -----------------------------------------------------------------------
68 The install will go faster if CPAN is configured to automatically install 
69 prerequisites.  You can revert the action later with:
70
71 echo -e "o conf prerequisites_policy ask\n o conf commit" | cpan 
72 '
73     while true; do
74         echo -n 'Automatically install prereqs? [Y/n] ';
75         read X;
76         [ "$X" == 'n' -o "$X" == "N" ] && break;
77         if [ "$X" == 'y' -o "$X" == 'Y' ]; then
78             echo -e "o conf prerequisites_policy follow\\n o conf commit" | cpan
79             break;
80         fi;
81     done;
82 fi;
83 fi;
84
85 # -----------------------------------------------------------------------
86
87 # And they're off...
88 BASE_DIR=$PWD
89
90 # Install some essential tools
91 apt-get update; 
92 apt-get -yq dist-upgrade;
93 apt-get -yq install build-essential automake git psmisc ntp rsyslog;
94
95 if [ $LIVETEST ]; then
96     cpan TAP::Parser::SourceHandler::pgTAP
97 fi;
98
99 cp $BASE_DIR/evergreen.ld.conf /etc/ld.so.conf.d/
100 ldconfig;
101
102 # Create opensrf user and set up environment
103 if [ ! "$(grep ^opensrf: /etc/passwd)" ]; then
104     useradd -m -s /bin/bash opensrf
105     echo 'export PATH=/openils/bin:$PATH' >> /home/opensrf/.bashrc
106     echo 'export LD_LIBRARY_PATH=/openils/lib:/usr/local/lib:/usr/local/lib/dbd:$LD_LIBRARY_PATH' >> /home/opensrf/.bashrc
107 fi;
108
109 # XXX for now, fetch the debian-wheezy install target working branches and merge in master
110 # You can override these like so:  EVERGREEN_BRANCH='master' ./eg_wheezy_installer.sh
111 OPENSRF_REPO='git://git.evergreen-ils.org/OpenSRF.git'
112 OPENSRF_BRANCH='master'
113 #EVERGREEN_REPO='git://git.evergreen-ils.org/working/Evergreen.git'
114 #EVERGREEN_BRANCH='collab/phasefx/qa-integration'
115 EVERGREEN_REPO='git://git.evergreen-ils.org/Evergreen.git'
116 EVERGREEN_BRANCH='master'
117 OSRF_COMMAND="
118 cd /home/opensrf;
119 git clone --depth 0 --branch $OPENSRF_BRANCH $OPENSRF_REPO OpenSRF;
120 git clone --depth 0 --branch $EVERGREEN_BRANCH $EVERGREEN_REPO Evergreen;
121 "
122 rm -rf /home/opensrf/Evergreen /home/opensrf/OpenSRF
123 su - opensrf sh -c "$OSRF_COMMAND";
124
125 # Show tips
126
127 cd /home/opensrf/OpenSRF/
128 echo 'Tip of OpenSRF:' `git log --format=oneline | head -1`
129 cd /home/opensrf/Evergreen/
130 echo 'Tip of Evergreen:' `git log --format=oneline | head -1`
131
132 # Install pre-reqs
133 mkdir -p /usr/src/evergreen; 
134 cd /usr/src/evergreen;
135 if [ $YES ]; then
136 echo _.-~= Installing OpenSRF pre-requisites
137     yes | make -f /home/opensrf/OpenSRF/src/extras/Makefile.install debian-wheezy
138 echo Return Value = $?
139 echo End of Installing OpenSRF pre-requisites =~-._
140 else
141 echo _.-~= Installing Evergreen pre-requisites
142     make -f /home/opensrf/OpenSRF/src/extras/Makefile.install debian-wheezy
143 echo Return Value = $?
144 echo End of Installing Evergreen pre-requisites =~-._
145 echo _.-~= Installing Evergreen database pre-requisites
146     make -f /home/opensrf/Evergreen/Open-ILS/src/extras/Makefile.install postgres-server-debian-wheezy
147 echo Return Value = $?
148 echo End of Installing Evergreen database pre-requisites =~-._
149 fi;
150
151 # Configure rsyslog and restart
152 cp /home/opensrf/Evergreen/Open-ILS/examples/evergreen-rsyslog.conf /etc/rsyslog.d/evergreen.conf
153 /etc/init.d/rsyslog restart
154
155
156 # Patch Ejabberd and register users
157 if [ ! "$(grep 'public.localhost' /etc/ejabberd/ejabberd.cfg)" ]; then
158     cd /etc/ejabberd/
159     /etc/init.d/ejabberd stop;
160     killall beam epmd; # just in case
161     cp ejabberd.cfg /root/ejabberd.cfg.orig
162     patch -p0 < $BASE_DIR/ejabberd.EG.patch
163     chown ejabberd:ejabberd ejabberd.cfg
164     /etc/init.d/ejabberd start
165     sleep 2;
166     ejabberdctl register router  private.localhost $JABBER_PASSWORD
167     ejabberdctl register opensrf private.localhost $JABBER_PASSWORD
168     ejabberdctl register router  public.localhost  $JABBER_PASSWORD
169     ejabberdctl register opensrf public.localhost  $JABBER_PASSWORD
170 fi;
171
172
173
174 # Build and install OpenSRF
175 OSRF_COMMAND='
176 cd /home/opensrf/OpenSRF;
177 autoreconf -i;
178 ./configure --prefix=/openils --sysconfdir=/openils/conf;
179 make;'
180
181 echo _.-~= Building OpenSRF
182 su - opensrf sh -c "$OSRF_COMMAND"
183 echo Return Value = $?
184 echo End of Building OpenSRF =~-._
185 cd /home/opensrf/OpenSRF;
186 echo _.-~= Running OpenSRF build tests
187 make check
188 echo Return Value = $?
189 echo End of OpenSRF build tests =~-._
190 make install
191
192 # Build and install the ILS
193 OSRF_COMMAND='
194 export PATH=/openils/bin:$PATH
195 cd /home/opensrf/Evergreen;
196 autoreconf -i;
197 ./configure --prefix=/openils --sysconfdir=/openils/conf;
198 make;
199 '
200
201 echo _.-~= Building Evergreen
202 su - opensrf sh -c "$OSRF_COMMAND"
203 echo Return Value = $?
204 echo End of Building Evergreen =~-._
205 cd /home/opensrf/Evergreen
206 echo _.-~= Running Evergreen build tests
207 make check
208 echo Return Value = $?
209 echo End of Evergreen build tests =~-._
210
211 make install
212
213 cp /openils/conf/opensrf.xml.example      /openils/conf/opensrf.xml
214 cp /openils/conf/opensrf_core.xml.example /openils/conf/opensrf_core.xml
215
216 # fetch and install Dojo
217 cd /tmp;
218 wget -N "http://download.dojotoolkit.org/release-$DOJO_VERSION/dojo-release-$DOJO_VERSION.tar.gz";
219 tar -zxf dojo-release-$DOJO_VERSION.tar.gz;
220 cp -r dojo-release-$DOJO_VERSION/* /openils/var/web/js/dojo/;
221
222 # give it all to opensrf
223 chown -R opensrf:opensrf /openils
224
225 # copy srfsh config into place
226 cp /openils/conf/srfsh.xml.example /home/opensrf/.srfsh.xml;
227 chown opensrf:opensrf /home/opensrf/.srfsh.xml;
228
229 if [ $YES ]; then
230     echo "Using password evergreen for the evergreen database user."
231     echo -e "evergreen\nevergreen\n" | su - postgres sh -c 'createuser -P -s evergreen;'
232 else
233     echo -e "\n\nPlease enter a password for the evergreen database user.\n  If you do not want to edit configs, use \"evergreen\"\n"
234     su - postgres sh -c 'createuser -P -s evergreen;'
235 fi;
236
237 # Apply the DB schema
238 cd /home/opensrf/Evergreen
239 perl Open-ILS/src/support-scripts/eg_db_config \
240     --create-database       \
241     --create-schema         \
242     --create-offline        \
243     --update-config $SAMPLEDATA \
244     --service all           \
245     --user evergreen        \
246     --password evergreen    \
247     --hostname localhost    \
248     --database evergreen    \
249     --admin-user $ADMIN_USER \
250     --admin-pass $ADMIN_PASS;
251
252 if [ $LIVETEST ]; then
253     PG_CMD="
254     git clone --depth 0 https://github.com/theory/pgtap.git \
255     && cd pgtap \
256     && make \
257     && make installcheck
258     "
259     su - postgres -c "$PG_CMD"
260     cd /var/lib/postgresql/pgtap \
261     && make install;
262     echo 'CREATE EXTENSION pgtap;' | su - postgres -c "psql evergreen"
263 fi;
264
265 # Copy apache configs into place and create SSL cert
266 cd /home/opensrf/Evergreen/
267 cp Open-ILS/examples/apache/eg.conf       /etc/apache2/sites-available/
268 cp Open-ILS/examples/apache/eg_vhost.conf /etc/apache2/
269 cp Open-ILS/examples/apache/eg_startup    /etc/apache2/
270
271 mkdir -p /etc/apache2/ssl;
272 if [ ! -f /etc/apache2/ssl/server.key ] ; then
273     echo -e "\n\nConfiguring a new temporary SSL certificate....\n";
274     if [ $YES ]; then
275        yes "" | openssl req -new -x509 -days 365 -nodes -out /etc/apache2/ssl/server.crt -keyout /etc/apache2/ssl/server.key
276     else
277        openssl req -new -x509 -days 365 -nodes -out /etc/apache2/ssl/server.crt -keyout /etc/apache2/ssl/server.key
278     fi;
279 else
280     echo -e "\nkeeping existing ssl/server.key file\n";
281 fi
282
283 a2enmod ssl  
284 a2enmod rewrite
285 a2enmod expires 
286 a2dissite 000-default
287 a2ensite eg.conf
288
289 if [ ! "$(grep 'public.localhost' /etc/hosts)" ]; then
290
291     if [ $YES ]; then
292         echo 'Adding public.localhost and private.localhost to /etc/hosts'
293         echo '127.0.1.2    public.localhost     public' >> /etc/hosts
294         echo '127.0.1.3    private.localhost    private' >> /etc/hosts
295     else
296
297     cat <<EOF
298
299 * Add these lines to /etc/hosts.
300
301 127.0.1.2   public.localhost    public
302 127.0.1.3   private.localhost   private
303
304 EOF
305     fi;
306
307 else
308     echo "INFO: /etc/hosts already has public.localhost line";
309 fi
310
311 if [ $AUTOSTART ]; then
312
313 if [ $LIVETEST ]; then
314     rm /openils/var/log/*.log
315 fi
316
317 OSRF_COMMAND='
318 export LD_LIBRARY_PATH=/openils/lib:/usr/local/lib:/usr/local/lib/dbd:$LD_LIBRARY_PATH \
319 && export PATH=/openils/bin:$PATH \
320 && OSRF_HOSTNAME="dns_hack" /openils/bin/osrf_control --localhost --stop_all  && sleep 3 \
321 && OSRF_HOSTNAME="dns_hack" /openils/bin/osrf_control --localhost --start_all  && sleep 3 \
322 && /openils/bin/autogen.sh /openils/conf/opensrf_core.xml \
323 && echo Finis;
324 '
325 echo Starting services...
326 su - opensrf sh -c "$OSRF_COMMAND";
327
328 echo Modifying APACHE_RUN_USER/APACHE_RUN_GROUP in /etc/apache2/envvars
329 sed -i 's/www-data/opensrf/g' /etc/apache2/envvars
330
331 echo Making sure /var/lock/apache2 is owned by opensrf
332 chown opensrf:opensrf /var/lock/apache2
333
334 echo Modifying KeepAliveTimeout in /etc/apache2/apache2.conf
335 sed -i 's/KeepAliveTimeout .*/KeepAliveTimeout 1/' /etc/apache2/apache2.conf
336
337 echo Restarting Apache
338 /etc/init.d/apache2 restart
339
340 if [ $LIVETEST ]; then
341 # TODO: Eventually move these tests into a Make target within Evergreen
342     cd /home/opensrf/Evergreen
343     echo _.-~= Running pgTAP tests
344     su - postgres -c 'cd /home/opensrf/Evergreen ; pg_prove -vr -d evergreen Open-ILS/src/sql/Pg/t/ ; echo Return Value = $?'
345     echo End of pgTAP tests =~-._
346     echo _.-~= Running settings-tester.pl
347     echo _.-~= Running pgTAP live tests
348     su - postgres -c 'cd /home/opensrf/Evergreen ; pg_prove -vr -d evergreen Open-ILS/src/sql/Pg/live_t/ ; echo Return Value = $?'
349     echo End of pgTAP live tests =~-._
350     echo _.-~= Running settings-tester.pl
351     su - opensrf sh -c 'export PATH=/openils/bin:$PATH ; cd /home/opensrf/Evergreen/Open-ILS/src/support-scripts/ ; ./settings-tester.pl ; echo Return Value = $?'
352     echo End of settings-tester.pl output =~-._
353     echo _.-~= Running perl live tests
354     su - opensrf sh -c 'export PATH=/openils/bin:$PATH ; cd /home/opensrf/Evergreen/Open-ILS/src/perlmods/ ; make livecheck; echo Return Value = $?'
355     echo End of perl live tests =~-._
356     echo _.-~= Gathering log summary
357     echo ''
358     echo 'wc -l *.log:'
359     su - opensrf sh -c 'cd /openils/var/log/ ; wc -l *.log'
360     echo ''
361     echo 'du -sh *.log:'
362     su - opensrf sh -c 'cd /openils/var/log/ ; du -sh *.log'
363     echo ''
364     echo 'perl -ne ''if (/^\[.*?\] (.*?) \[/) { print "$1\n"; }'' osrfsys.log | sort | uniq -c | sort -k2:'
365     (cd /openils/var/log/ ; perl -ne 'if (/^\[.*?\] (.*?) \[/) { print "$1\n"; }' osrfsys.log | sort | uniq -c | sort -k2)
366     echo ''
367     echo End of log summary =~-._
368     echo _.-~= Gathering system information
369     echo ''
370     date
371     echo ''
372     uname -a
373     echo 'select version();' | su - postgres -c 'psql -At'
374     echo ''
375     echo '/proc/meminfo:'
376     cat /proc/meminfo
377     echo ''
378     echo '/proc/cpuinfo:'
379     cat /proc/cpuinfo
380     echo ''
381     echo 'dpkg --list:'
382     dpkg --list
383     echo ''
384     echo 'cpan -l:'
385     sudo cpan -l
386     echo End of system information =~-._
387     date
388 else
389     cat <<EOF
390 * Test the system
391
392 # as opensrf user
393 echo "request open-ils.cstore open-ils.cstore.direct.actor.user.retrieve 1" | srfsh
394 EOF
395 fi;
396
397 else
398
399     cat <<EOF
400 * Start services
401
402 su - opensrf
403 osrf_control --localhost --start-all      && sleep  3;
404 /openils/bin/autogen.sh /openils/conf/opensrf_core.xml;
405
406 * Test the system
407
408 # as opensrf user
409 echo "request open-ils.cstore open-ils.cstore.direct.actor.user.retrieve 1" | srfsh
410
411 * Now finish configuring Apache
412
413 1. s/www-data/opensrf/g in envvars
414 2. KeepAliveTimeout 1 in apache2.conf
415
416
417 EOF
418
419 fi;