]> git.evergreen-ils.org Git - working/random.git/blob - installer/wheezy/eg_wheezy_installer.sh
make it easier to compare system information between runs
[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 while getopts ayst option
18 do
19         case "${option}"
20         in
21                 a) AUTOSTART=1;;
22                 y) YES=1;;
23                 s) SAMPLEDATA=--load-all-sample;;
24                 t) LIVETEST=1;;
25         esac
26 done
27
28 function my_init {
29     date
30     init_variables
31     configure_cpan
32     build_essentials
33     setting_up_opensrf_env
34     cloning_git_repos
35     opensrf_prereqs
36     evergreen_prereqs
37     evergreen_db_prereqs
38     setting_ldconfig_and_rsyslog_and_hosts_and_ejabberd
39     build_opensrf
40     test_opensrf_build
41     install_opensrf
42     build_evergreen
43     test_evergreen_build
44     install_evergreen
45     configure_database
46     configure_apache
47     if [ $AUTOSTART ]; then
48         start_evergreen
49         test_evergreen_live
50     fi
51 }
52
53 function init_variables {
54     echo _.-~= initializing installer
55     # -----------------------------------------------------------------------
56     # Handling passed arguments to the script
57     # -----------------------------------------------------------------------
58     export DOJO_VERSION='1.3.3';
59     export PATH=/openils/bin:$PATH
60     export LD_LIBRARY_PATH=/openils/lib:/usr/local/lib:/usr/local/lib/dbd:$LD_LIBRARY_PATH
61     export BASE_DIR=$PWD
62     echo AUTOSTART=${AUTOSTART}
63     echo YES=${YES}
64     echo SAMPLEDATA=${SAMPLEDATA}
65     echo LIVETEST=${LIVETEST}
66     echo DOJO_VERSION=${DOJO_VERSION}
67     echo PATH=${PATH}
68     echo LD_LIBRARY_PATH=${LD_LIBRARY_PATH}
69     echo BASE_DIR=${BASE_DIR}
70     # -----------------------------------------------------------------------
71     # Change to suit...
72     # -----------------------------------------------------------------------
73     # If you change the jabber password, you will need to 
74     # edit opensrf_core.xml and srfsh.xml accordingly
75     export JABBER_PASSWORD='password'
76     export ADMIN_USER='admin';
77     export ADMIN_PASS='demo123';
78     # -----------------------------------------------------------------------
79     # You can override these like so:
80     #       EVERGREEN_BRANCH='master' ./eg_wheezy_installer.sh
81     # -----------------------------------------------------------------------
82     OPENSRF_REPO='git://git.evergreen-ils.org/OpenSRF.git'
83     OPENSRF_BRANCH='master'
84     EVERGREEN_REPO='git://git.evergreen-ils.org/Evergreen.git'
85     EVERGREEN_BRANCH='master'
86     echo OPENSRF_REPO=${OPENSRF_REPO}
87     echo OPENSRF_BRANCH=${OPENSRF_BRANCH}
88     echo EVERGREEN_REPO=${EVERGREEN_REPO}
89     echo EVERGREEN_BRANCH=${EVERGREEN_BRANCH}
90     OPENSRF_PREREQ_TARGET=debian-wheezy
91     EVERGREEN_PREREQ_TARGET=debian-wheezy
92     EVERGREEN_DB_PREREQ_TARGET=postgres-server-debian-wheezy
93     echo OPENSRF_PREREQ_TARGET=${OPENSRF_PREREQ_TARGET}
94     echo EVERGREEN_PREREQ_TARGET=${EVERGREEN_PREREQ_TARGET}
95     echo EVERGREEN_DB_PREREQ_TARGET=${EVERGREEN_DB_PREREQ_TARGET}
96     echo End of intializing installer =~-._
97 }
98
99 function configure_cpan {
100     echo _.-~= configure CPAN
101     # -----------------------------------------------------------------------
102     # force CPAN to load by installing something that should already be installed
103     if [ $YES ]; then
104         yes | cpan Fcntl
105     else
106         cpan Fcntl
107     fi
108     echo Return Value = $?
109     # CPAN follow pre-reqs?
110     if [ ! "$(echo 'o conf prerequisites_policy' | cpan | grep follow)" ]; then
111     if [ $YES ]; then
112
113         echo "setting cpan prerequisites_policy to follow"
114         echo -e "o conf prerequisites_policy follow\\n o conf commit" | cpan
115
116     else
117
118         echo '
119
120 -----------------------------------------------------------------------
121 The install will go faster if CPAN is configured to automatically install 
122 prerequisites.  You can revert the action later with:
123
124 echo -e "o conf prerequisites_policy ask\n o conf commit" | cpan 
125 '
126         while true; do
127             echo -n 'Automatically install prereqs? [Y/n] ';
128             read X;
129             [ "$X" == 'n' -o "$X" == "N" ] && break;
130             if [ "$X" == 'y' -o "$X" == 'Y' ]; then
131                 echo -e "o conf prerequisites_policy follow\\n o conf commit" | cpan
132                 break;
133             fi;
134         done;
135     fi;
136     fi;
137     echo End of configure CPAN =~-._
138 }
139
140 function build_essentials {
141     echo _.-~= Installing some build essentials
142     # Install some essential tools
143     apt-get update \
144     && apt-get -yq dist-upgrade \
145     && apt-get -yq install build-essential automake git psmisc ntp rsyslog;
146     echo Return Value = $?
147
148     if [ $LIVETEST ]; then
149         cpan TAP::Parser::SourceHandler::pgTAP
150         echo Return Value = $?
151     fi;
152     echo End of Installing some build essentials  =~-._
153 }
154
155 function setting_up_opensrf_env {
156     echo _.-~= creating opensrf user and environment
157     # Create opensrf user and set up environment
158     if [ ! "$(grep ^opensrf: /etc/passwd)" ]; then
159         useradd -m -s /bin/bash opensrf
160         echo Return Value = $?
161         echo 'export PATH=/openils/bin:$PATH' >> /home/opensrf/.bashrc
162         echo 'export LD_LIBRARY_PATH=/openils/lib:/usr/local/lib:/usr/local/lib/dbd:$LD_LIBRARY_PATH' >> /home/opensrf/.bashrc
163     fi;
164     echo end of creating opensrf user and environment =~-._
165 }
166
167 function cloning_git_repos {
168     echo _.-~= cloning git repositories
169     OSRF_COMMAND="
170     cd /home/opensrf;
171     git clone --depth 0 --branch $OPENSRF_BRANCH $OPENSRF_REPO OpenSRF;
172     git clone --depth 0 --branch $EVERGREEN_BRANCH $EVERGREEN_REPO Evergreen;
173     "
174     rm -rf /home/opensrf/Evergreen /home/opensrf/OpenSRF
175     su - opensrf sh -c "$OSRF_COMMAND";
176     echo Return Value = $?
177
178     # Show tips
179     cd /home/opensrf/OpenSRF/
180     echo 'Tip of OpenSRF:' `git log --format=oneline | head -1`
181     cd /home/opensrf/Evergreen/
182     echo 'Tip of Evergreen:' `git log --format=oneline | head -1`
183
184     echo End of cloning git repositories =~-._
185 }
186
187 function opensrf_prereqs {
188     echo _.-~= Installing OpenSRF pre-requisites
189     # Install pre-reqs
190     mkdir -p /usr/src/evergreen; 
191     cd /usr/src/evergreen;
192     if [ $YES ]; then
193         yes | make -f /home/opensrf/OpenSRF/src/extras/Makefile.install ${OPENSRF_PREREQ_TARGET}
194     else
195         make -f /home/opensrf/OpenSRF/src/extras/Makefile.install ${OPENSRF_PREREQ_TARGET}
196     fi;
197     echo Return Value = $?
198     echo End of Installing OpenSRF pre-requisites =~-._
199 }
200
201 function evergreen_prereqs {
202     echo _.-~= Installing Evergreen pre-requisites
203     if [ $YES ]; then
204         yes | make -f /home/opensrf/Evergreen/Open-ILS/src/extras/Makefile.install ${EVERGREEN_PREREQ_TARGET}
205     else
206         make -f /home/opensrf/Evergreen/Open-ILS/src/extras/Makefile.install ${EVERGREEN_PREREQ_TARGET}
207     fi;
208     echo Return Value = $?
209     echo End of Installing Evergreen pre-requisites =~-._
210 }
211
212 function evergreen_db_prereqs {
213     echo _.-~= Installing Evergreen database pre-requisites
214     if [ $YES ]; then
215         yes | make -f /home/opensrf/Evergreen/Open-ILS/src/extras/Makefile.install ${EVERGREEN_DB_PREREQ_TARGET}
216     else
217         make -f /home/opensrf/Evergreen/Open-ILS/src/extras/Makefile.install ${EVERGREEN_DB_PREREQ_TARGET}
218     fi;
219     echo Return Value = $?
220     echo End of Installing Evergreen database pre-requisites =~-._
221 }
222
223 function setting_ldconfig_and_rsyslog_and_hosts_and_ejabberd {
224     echo _.-~= setting ld.so.conf and rsyslog and /etc/hosts and ejabberd
225     cp $BASE_DIR/evergreen.ld.conf /etc/ld.so.conf.d/
226     ldconfig;
227     echo Return Value = $?
228     # Configure rsyslog and restart
229     cp /home/opensrf/Evergreen/Open-ILS/examples/evergreen-rsyslog.conf /etc/rsyslog.d/evergreen.conf
230     /etc/init.d/rsyslog restart
231     echo Return Value = $?
232     if [ ! "$(grep 'public.localhost' /etc/hosts)" ]; then
233
234         if [ $YES ]; then
235             echo 'Adding public.localhost and private.localhost to /etc/hosts'
236             echo '127.0.1.2    public.localhost     public' >> /etc/hosts
237             echo '127.0.1.3    private.localhost    private' >> /etc/hosts
238         else
239
240         cat <<EOF
241
242     * Add these lines to /etc/hosts.
243
244     127.0.1.2   public.localhost    public
245     127.0.1.3   private.localhost   private
246
247 EOF
248         fi;
249
250     else
251         echo "INFO: /etc/hosts already has public.localhost line";
252     fi
253     echo Return Value = $?
254     # Patch Ejabberd and register users
255     if [ ! "$(grep 'public.localhost' /etc/ejabberd/ejabberd.cfg)" ]; then
256         cd /etc/ejabberd/
257         /etc/init.d/ejabberd stop;
258         killall beam epmd; # just in case
259         cp ejabberd.cfg /root/ejabberd.cfg.orig
260         patch -p0 < $BASE_DIR/ejabberd.EG.patch
261         chown ejabberd:ejabberd ejabberd.cfg
262         /etc/init.d/ejabberd start
263         echo Return Value = $?
264         sleep 2;
265         ejabberdctl register router  private.localhost $JABBER_PASSWORD
266         echo Return Value = $?
267         ejabberdctl register opensrf private.localhost $JABBER_PASSWORD
268         echo Return Value = $?
269         ejabberdctl register router  public.localhost  $JABBER_PASSWORD
270         echo Return Value = $?
271         ejabberdctl register opensrf public.localhost  $JABBER_PASSWORD
272         echo Return Value = $?
273     fi;
274     echo End of setting ld.so.conf and rsyslog and /etc/hosts and ejabberd =~-._
275 }
276
277 function build_opensrf {
278     # Build and install OpenSRF
279     echo _.-~= Building OpenSRF
280     OSRF_COMMAND='
281     cd /home/opensrf/OpenSRF;
282     autoreconf -i;
283     ./configure --prefix=/openils --sysconfdir=/openils/conf;
284     make;'
285     su - opensrf sh -c "$OSRF_COMMAND"
286     echo Return Value = $?
287     echo End of Building OpenSRF =~-._
288 }
289
290 function test_opensrf_build {
291     echo _.-~= Running OpenSRF build tests
292     cd /home/opensrf/OpenSRF;
293     make check
294     echo Return Value = $?
295     echo End of OpenSRF build tests =~-._
296 }
297
298 function install_opensrf {
299     echo _.-~= Installing OpenSRF
300     make install
301     echo Return Value = $?
302     echo End of Installing OpenSRF =~-._
303 }
304
305 function build_evergreen {
306     echo _.-~= Building Evergreen
307     OSRF_COMMAND='
308     export PATH=/openils/bin:$PATH
309     cd /home/opensrf/Evergreen;
310     autoreconf -i;
311     ./configure --prefix=/openils --sysconfdir=/openils/conf;
312     make;
313     '
314     su - opensrf sh -c "$OSRF_COMMAND"
315     echo Return Value = $?
316     echo End of Building Evergreen =~-._
317 }
318
319 function test_evergreen_build {
320     echo _.-~= Running Evergreen build tests
321     cd /home/opensrf/Evergreen
322     make check
323     echo Return Value = $?
324     echo End of Evergreen build tests =~-._
325 }
326
327 function install_evergreen {
328     echo _.-~= Installing Evergreen
329     make install
330     echo Return Value = $?
331
332     cp /openils/conf/opensrf.xml.example      /openils/conf/opensrf.xml
333     cp /openils/conf/opensrf_core.xml.example /openils/conf/opensrf_core.xml
334
335     # fetch and install Dojo
336     cd /tmp;
337     wget -N "http://download.dojotoolkit.org/release-$DOJO_VERSION/dojo-release-$DOJO_VERSION.tar.gz" \
338     || wget -N "http://evergreen-ils.org/~phasefx/download.dojotoolkit.org/dojo-release-$DOJO_VERSION.tar.gz"
339     tar -zxf dojo-release-$DOJO_VERSION.tar.gz;
340     cp -r dojo-release-$DOJO_VERSION/* /openils/var/web/js/dojo/;
341
342     # give it all to opensrf
343     chown -R opensrf:opensrf /openils
344
345     # copy srfsh config into place
346     cp /openils/conf/srfsh.xml.example /home/opensrf/.srfsh.xml;
347     chown opensrf:opensrf /home/opensrf/.srfsh.xml;
348     echo End of Installing Evergreen =~-._
349 }
350
351 function configure_database {
352     echo _.-~= configure database
353     if [ $YES ]; then
354         echo "Using password evergreen for the evergreen database user."
355         echo -e "evergreen\nevergreen\n" | su - postgres sh -c 'createuser -P -s evergreen;'
356     else
357         echo -e "\n\nPlease enter a password for the evergreen database user.\n  If you do not want to edit configs, use \"evergreen\"\n"
358         su - postgres sh -c 'createuser -P -s evergreen;'
359     fi;
360
361     # Apply the DB schema
362     cd /home/opensrf/Evergreen
363     perl Open-ILS/src/support-scripts/eg_db_config \
364         --create-database       \
365         --create-schema         \
366         --create-offline        \
367         --update-config $SAMPLEDATA \
368         --service all           \
369         --user evergreen        \
370         --password evergreen    \
371         --hostname localhost    \
372         --database evergreen    \
373         --admin-user $ADMIN_USER \
374         --admin-pass $ADMIN_PASS;
375     echo Return Value = $?
376
377     if [ $LIVETEST ]; then
378         PG_CMD="
379         git clone --depth 0 https://github.com/theory/pgtap.git \
380         && cd pgtap \
381         && make \
382         && make installcheck
383         "
384         su - postgres -c "$PG_CMD"
385         cd /var/lib/postgresql/pgtap \
386         && make install;
387         echo 'CREATE EXTENSION pgtap;' | su - postgres -c "psql evergreen"
388     fi;
389     echo configure database =~-._
390 }
391
392 function configure_apache {
393     echo _.-~= configure apache
394     /etc/init.d/apache2 stop
395     # Copy apache configs into place and create SSL cert
396     cd /home/opensrf/Evergreen/
397     cp Open-ILS/examples/apache/eg.conf       /etc/apache2/sites-available/
398     cp Open-ILS/examples/apache/eg_vhost.conf /etc/apache2/
399     cp Open-ILS/examples/apache/eg_startup    /etc/apache2/
400
401     mkdir -p /etc/apache2/ssl;
402     if [ ! -f /etc/apache2/ssl/server.key ] ; then
403         echo -e "\n\nConfiguring a new temporary SSL certificate....\n";
404         if [ $YES ]; then
405            yes "" | openssl req -new -x509 -days 365 -nodes -out /etc/apache2/ssl/server.crt -keyout /etc/apache2/ssl/server.key
406         else
407            openssl req -new -x509 -days 365 -nodes -out /etc/apache2/ssl/server.crt -keyout /etc/apache2/ssl/server.key
408         fi;
409     else
410         echo -e "\nkeeping existing ssl/server.key file\n";
411     fi
412
413     a2enmod ssl  
414     echo Return Value = $?
415     a2enmod rewrite
416     echo Return Value = $?
417     a2enmod expires 
418     echo Return Value = $?
419     a2dissite 000-default
420     echo Return Value = $?
421     a2ensite eg.conf
422     echo Return Value = $?
423
424     echo Modifying APACHE_RUN_USER/APACHE_RUN_GROUP in /etc/apache2/envvars
425     sed -i 's/www-data/opensrf/g' /etc/apache2/envvars
426
427     echo Making sure /var/lock/apache2 is owned by opensrf
428     chown opensrf:opensrf /var/lock/apache2
429
430     echo Modifying KeepAliveTimeout in /etc/apache2/apache2.conf
431     sed -i 's/KeepAliveTimeout .*/KeepAliveTimeout 1/' /etc/apache2/apache2.conf
432
433     echo End of configure apache =~-._
434 }
435
436 function start_evergreen {
437     echo _.-~= Starting Evergreen
438     if [ $LIVETEST ]; then
439         rm /openils/var/log/*.log
440     fi
441
442     OSRF_COMMAND='
443     export LD_LIBRARY_PATH=/openils/lib:/usr/local/lib:/usr/local/lib/dbd:$LD_LIBRARY_PATH \
444     && export PATH=/openils/bin:$PATH \
445     && OSRF_HOSTNAME="dns_hack" /openils/bin/osrf_control --localhost --restart-all  && sleep 3 \
446     && /openils/bin/autogen.sh /openils/conf/opensrf_core.xml \
447     && echo Finis;
448     '
449     echo Starting services...
450     su - opensrf sh -c "$OSRF_COMMAND";
451     echo Return Value = $?
452
453     echo Restarting Apache
454     /etc/init.d/apache2 restart
455     echo Return Value = $?
456
457     echo End of Starting Evergreen =~-._
458 }
459
460 function test_evergreen_live {
461     # TODO: Eventually move these tests into a Make target within Evergreen
462     cd /home/opensrf/Evergreen
463     echo _.-~= Running pgTAP tests
464     su - postgres -c 'cd /home/opensrf/Evergreen ; pg_prove -vr -d evergreen Open-ILS/src/sql/Pg/t/ ; echo Return Value = $?'
465     echo End of pgTAP tests =~-._
466     echo _.-~= Running pgTAP live tests
467     su - postgres -c 'cd /home/opensrf/Evergreen ; pg_prove -vr -d evergreen Open-ILS/src/sql/Pg/live_t/ ; echo Return Value = $?'
468     echo End of pgTAP live tests =~-._
469     echo _.-~= Running settings-tester.pl
470     su - opensrf sh -c 'export PATH=/openils/bin:$PATH ; cd /home/opensrf/Evergreen/Open-ILS/src/support-scripts/ ; ./settings-tester.pl ; echo Return Value = $?'
471     echo End of settings-tester.pl output =~-._
472     echo _.-~= Running perl live tests
473     su - opensrf sh -c 'export PATH=/openils/bin:$PATH ; cd /home/opensrf/Evergreen/Open-ILS/src/perlmods/ ; make livecheck; echo Return Value = $?'
474     echo End of perl live tests =~-._
475     echo _.-~= Gathering log summary
476     echo ''
477     echo 'wc -l *.log:'
478     su - opensrf sh -c 'cd /openils/var/log/ ; wc -l *.log'
479     echo ''
480     echo 'du -sh *.log:'
481     su - opensrf sh -c 'cd /openils/var/log/ ; du -sh *.log'
482     echo ''
483     echo 'perl -ne ''if (/^\[.*?\] (.*?) \[/) { print "$1\n"; }'' osrfsys.log | sort | uniq -c | sort -k2:'
484     (cd /openils/var/log/ ; perl -ne 'if (/^\[.*?\] (.*?) \[/) { print "$1\n"; }' osrfsys.log | sort | uniq -c | sort -k2)
485     echo ''
486     echo End of log summary =~-._
487     cd /openils/var/log/
488     for x in *.log; do
489         echo _.-~= Log Output: $x
490         cat $x
491         echo End of $x =~-._
492     done
493     echo _.-~= Gathering system information
494     echo ''
495     date
496     echo ''
497     uname -a
498     echo 'select version();' | su - postgres -c 'psql -At'
499     echo ''
500     echo '/proc/meminfo:'
501     cat /proc/meminfo
502     echo ''
503     echo '/proc/cpuinfo:'
504     cat /proc/cpuinfo
505     echo ''
506     echo 'dpkg --list:'
507     dpkg --list | sort
508     echo ''
509     echo 'cpan -l:'
510     sudo cpan -l 2> /dev/null | sort
511     echo End of system information =~-._
512     date
513 }
514
515 my_init
516
517