]> git.evergreen-ils.org Git - working/random.git/blob - installer/wheezy/eg_wheezy_installer.sh
thinko
[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 echo _.-~= Installing Evergreen pre-requisites
141     yes | make -f /home/opensrf/OpenSRF/src/extras/Makefile.install debian-wheezy
142 echo Return Value = $?
143 echo End of Installing Evergreen pre-requisites =~-._
144 echo _.-~= Installing Evergreen database pre-requisites
145     yes | make -f /home/opensrf/Evergreen/Open-ILS/src/extras/Makefile.install postgres-server-debian-wheezy
146 echo Return Value = $?
147 echo End of Installing Evergreen database pre-requisites =~-._
148 else
149 echo _.-~= Installing OpenSRF pre-requisites
150     make -f /home/opensrf/OpenSRF/src/extras/Makefile.install debian-wheezy
151 echo Return Value = $?
152 echo End of Installing OpenSRF pre-requisites =~-._
153 echo _.-~= Installing Evergreen pre-requisites
154     make -f /home/opensrf/OpenSRF/src/extras/Makefile.install debian-wheezy
155 echo Return Value = $?
156 echo End of Installing Evergreen pre-requisites =~-._
157 echo _.-~= Installing Evergreen database pre-requisites
158     make -f /home/opensrf/Evergreen/Open-ILS/src/extras/Makefile.install postgres-server-debian-wheezy
159 echo Return Value = $?
160 echo End of Installing Evergreen database pre-requisites =~-._
161 fi;
162
163 # Configure rsyslog and restart
164 cp /home/opensrf/Evergreen/Open-ILS/examples/evergreen-rsyslog.conf /etc/rsyslog.d/evergreen.conf
165 /etc/init.d/rsyslog restart
166
167
168 # Patch Ejabberd and register users
169 if [ ! "$(grep 'public.localhost' /etc/ejabberd/ejabberd.cfg)" ]; then
170     cd /etc/ejabberd/
171     /etc/init.d/ejabberd stop;
172     killall beam epmd; # just in case
173     cp ejabberd.cfg /root/ejabberd.cfg.orig
174     patch -p0 < $BASE_DIR/ejabberd.EG.patch
175     chown ejabberd:ejabberd ejabberd.cfg
176     /etc/init.d/ejabberd start
177     sleep 2;
178     ejabberdctl register router  private.localhost $JABBER_PASSWORD
179     ejabberdctl register opensrf private.localhost $JABBER_PASSWORD
180     ejabberdctl register router  public.localhost  $JABBER_PASSWORD
181     ejabberdctl register opensrf public.localhost  $JABBER_PASSWORD
182 fi;
183
184
185
186 # Build and install OpenSRF
187 OSRF_COMMAND='
188 cd /home/opensrf/OpenSRF;
189 autoreconf -i;
190 ./configure --prefix=/openils --sysconfdir=/openils/conf;
191 make;'
192
193 echo _.-~= Building OpenSRF
194 su - opensrf sh -c "$OSRF_COMMAND"
195 echo Return Value = $?
196 echo End of Building OpenSRF =~-._
197 cd /home/opensrf/OpenSRF;
198 echo _.-~= Running OpenSRF build tests
199 make check
200 echo Return Value = $?
201 echo End of OpenSRF build tests =~-._
202 make install
203
204 # Build and install the ILS
205 OSRF_COMMAND='
206 export PATH=/openils/bin:$PATH
207 cd /home/opensrf/Evergreen;
208 autoreconf -i;
209 ./configure --prefix=/openils --sysconfdir=/openils/conf;
210 make;
211 '
212
213 echo _.-~= Building Evergreen
214 su - opensrf sh -c "$OSRF_COMMAND"
215 echo Return Value = $?
216 echo End of Building Evergreen =~-._
217 cd /home/opensrf/Evergreen
218 echo _.-~= Running Evergreen build tests
219 make check
220 echo Return Value = $?
221 echo End of Evergreen build tests =~-._
222
223 make install
224
225 cp /openils/conf/opensrf.xml.example      /openils/conf/opensrf.xml
226 cp /openils/conf/opensrf_core.xml.example /openils/conf/opensrf_core.xml
227
228 # fetch and install Dojo
229 cd /tmp;
230 wget -N "http://download.dojotoolkit.org/release-$DOJO_VERSION/dojo-release-$DOJO_VERSION.tar.gz";
231 tar -zxf dojo-release-$DOJO_VERSION.tar.gz;
232 cp -r dojo-release-$DOJO_VERSION/* /openils/var/web/js/dojo/;
233
234 # give it all to opensrf
235 chown -R opensrf:opensrf /openils
236
237 # copy srfsh config into place
238 cp /openils/conf/srfsh.xml.example /home/opensrf/.srfsh.xml;
239 chown opensrf:opensrf /home/opensrf/.srfsh.xml;
240
241 if [ $YES ]; then
242     echo "Using password evergreen for the evergreen database user."
243     echo -e "evergreen\nevergreen\n" | su - postgres sh -c 'createuser -P -s evergreen;'
244 else
245     echo -e "\n\nPlease enter a password for the evergreen database user.\n  If you do not want to edit configs, use \"evergreen\"\n"
246     su - postgres sh -c 'createuser -P -s evergreen;'
247 fi;
248
249 # Apply the DB schema
250 cd /home/opensrf/Evergreen
251 perl Open-ILS/src/support-scripts/eg_db_config \
252     --create-database       \
253     --create-schema         \
254     --create-offline        \
255     --update-config $SAMPLEDATA \
256     --service all           \
257     --user evergreen        \
258     --password evergreen    \
259     --hostname localhost    \
260     --database evergreen    \
261     --admin-user $ADMIN_USER \
262     --admin-pass $ADMIN_PASS;
263
264 if [ $LIVETEST ]; then
265     PG_CMD="
266     git clone --depth 0 https://github.com/theory/pgtap.git \
267     && cd pgtap \
268     && make \
269     && make installcheck
270     "
271     su - postgres -c "$PG_CMD"
272     cd /var/lib/postgresql/pgtap \
273     && make install;
274     echo 'CREATE EXTENSION pgtap;' | su - postgres -c "psql evergreen"
275 fi;
276
277 # Copy apache configs into place and create SSL cert
278 cd /home/opensrf/Evergreen/
279 cp Open-ILS/examples/apache/eg.conf       /etc/apache2/sites-available/
280 cp Open-ILS/examples/apache/eg_vhost.conf /etc/apache2/
281 cp Open-ILS/examples/apache/eg_startup    /etc/apache2/
282
283 mkdir -p /etc/apache2/ssl;
284 if [ ! -f /etc/apache2/ssl/server.key ] ; then
285     echo -e "\n\nConfiguring a new temporary SSL certificate....\n";
286     if [ $YES ]; then
287        yes "" | openssl req -new -x509 -days 365 -nodes -out /etc/apache2/ssl/server.crt -keyout /etc/apache2/ssl/server.key
288     else
289        openssl req -new -x509 -days 365 -nodes -out /etc/apache2/ssl/server.crt -keyout /etc/apache2/ssl/server.key
290     fi;
291 else
292     echo -e "\nkeeping existing ssl/server.key file\n";
293 fi
294
295 a2enmod ssl  
296 a2enmod rewrite
297 a2enmod expires 
298 a2dissite 000-default
299 a2ensite eg.conf
300
301 if [ ! "$(grep 'public.localhost' /etc/hosts)" ]; then
302
303     if [ $YES ]; then
304         echo 'Adding public.localhost and private.localhost to /etc/hosts'
305         echo '127.0.1.2    public.localhost     public' >> /etc/hosts
306         echo '127.0.1.3    private.localhost    private' >> /etc/hosts
307     else
308
309     cat <<EOF
310
311 * Add these lines to /etc/hosts.
312
313 127.0.1.2   public.localhost    public
314 127.0.1.3   private.localhost   private
315
316 EOF
317     fi;
318
319 else
320     echo "INFO: /etc/hosts already has public.localhost line";
321 fi
322
323 if [ $AUTOSTART ]; then
324
325 if [ $LIVETEST ]; then
326     rm /openils/var/log/*.log
327 fi
328
329 OSRF_COMMAND='
330 export LD_LIBRARY_PATH=/openils/lib:/usr/local/lib:/usr/local/lib/dbd:$LD_LIBRARY_PATH \
331 && export PATH=/openils/bin:$PATH \
332 && OSRF_HOSTNAME="dns_hack" /openils/bin/osrf_control --localhost --stop_all  && sleep 3 \
333 && OSRF_HOSTNAME="dns_hack" /openils/bin/osrf_control --localhost --start_all  && sleep 3 \
334 && /openils/bin/autogen.sh /openils/conf/opensrf_core.xml \
335 && echo Finis;
336 '
337 echo Starting services...
338 su - opensrf sh -c "$OSRF_COMMAND";
339
340 echo Modifying APACHE_RUN_USER/APACHE_RUN_GROUP in /etc/apache2/envvars
341 sed -i 's/www-data/opensrf/g' /etc/apache2/envvars
342
343 echo Making sure /var/lock/apache2 is owned by opensrf
344 chown opensrf:opensrf /var/lock/apache2
345
346 echo Modifying KeepAliveTimeout in /etc/apache2/apache2.conf
347 sed -i 's/KeepAliveTimeout .*/KeepAliveTimeout 1/' /etc/apache2/apache2.conf
348
349 echo Restarting Apache
350 /etc/init.d/apache2 restart
351
352 if [ $LIVETEST ]; then
353 # TODO: Eventually move these tests into a Make target within Evergreen
354     cd /home/opensrf/Evergreen
355     echo _.-~= Running pgTAP tests
356     su - postgres -c 'cd /home/opensrf/Evergreen ; pg_prove -vr -d evergreen Open-ILS/src/sql/Pg/t/ ; echo Return Value = $?'
357     echo End of pgTAP tests =~-._
358     echo _.-~= Running settings-tester.pl
359     echo _.-~= Running pgTAP live tests
360     su - postgres -c 'cd /home/opensrf/Evergreen ; pg_prove -vr -d evergreen Open-ILS/src/sql/Pg/live_t/ ; echo Return Value = $?'
361     echo End of pgTAP live tests =~-._
362     echo _.-~= Running settings-tester.pl
363     su - opensrf sh -c 'export PATH=/openils/bin:$PATH ; cd /home/opensrf/Evergreen/Open-ILS/src/support-scripts/ ; ./settings-tester.pl ; echo Return Value = $?'
364     echo End of settings-tester.pl output =~-._
365     echo _.-~= Running perl live tests
366     su - opensrf sh -c 'export PATH=/openils/bin:$PATH ; cd /home/opensrf/Evergreen/Open-ILS/src/perlmods/ ; make livecheck; echo Return Value = $?'
367     echo End of perl live tests =~-._
368     echo _.-~= Gathering log summary
369     echo ''
370     echo 'wc -l *.log:'
371     su - opensrf sh -c 'cd /openils/var/log/ ; wc -l *.log'
372     echo ''
373     echo 'du -sh *.log:'
374     su - opensrf sh -c 'cd /openils/var/log/ ; du -sh *.log'
375     echo ''
376     echo 'perl -ne ''if (/^\[.*?\] (.*?) \[/) { print "$1\n"; }'' osrfsys.log | sort | uniq -c | sort -k2:'
377     (cd /openils/var/log/ ; perl -ne 'if (/^\[.*?\] (.*?) \[/) { print "$1\n"; }' osrfsys.log | sort | uniq -c | sort -k2)
378     echo ''
379     echo End of log summary =~-._
380     echo _.-~= Gathering system information
381     echo ''
382     date
383     echo ''
384     uname -a
385     echo 'select version();' | su - postgres -c 'psql -At'
386     echo ''
387     echo '/proc/meminfo:'
388     cat /proc/meminfo
389     echo ''
390     echo '/proc/cpuinfo:'
391     cat /proc/cpuinfo
392     echo ''
393     echo 'dpkg --list:'
394     dpkg --list
395     echo ''
396     echo 'cpan -l:'
397     sudo cpan -l
398     echo End of system information =~-._
399     date
400 else
401     cat <<EOF
402 * Test the system
403
404 # as opensrf user
405 echo "request open-ils.cstore open-ils.cstore.direct.actor.user.retrieve 1" | srfsh
406 EOF
407 fi;
408
409 else
410
411     cat <<EOF
412 * Start services
413
414 su - opensrf
415 osrf_control --localhost --start-all      && sleep  3;
416 /openils/bin/autogen.sh /openils/conf/opensrf_core.xml;
417
418 * Test the system
419
420 # as opensrf user
421 echo "request open-ils.cstore open-ils.cstore.direct.actor.user.retrieve 1" | srfsh
422
423 * Now finish configuring Apache
424
425 1. s/www-data/opensrf/g in envvars
426 2. KeepAliveTimeout 1 in apache2.conf
427
428
429 EOF
430
431 fi;