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