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