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