Merge branch 'master' into eg310
[sitka/sitka-tools.git] / deployment / install-eg.sh
1 #!/bin/bash
2 # IMPORTANT! This script assumes you have already installed OpenSRF.
3
4 HOSTNAME="nonprod"
5 DEFAULT_USER="opensrf"
6 INSTALL_USER="opensrf"
7 #EGRELEASE="Evergreen-ILS-2.12.beta"
8 #BUILDDIR="/home/${INSTALL_USER}/${EGRELEASE}"
9 BUILDDIR="/home/${INSTALL_USER}/evergreen"
10 INSTALLDIR="/srv/openils"
11 BRANCH="user/jeffdavis/upgrade-303-tpac"
12 STAMP_ID="rel_3_0_3"
13 ALT_STAMP_IDS="3_0_3 rel_3_0_2 3_0_2 rel_3_0_1 3_0_1 rel_3_0_0 3_0_0"
14 VERSION="3.0.3.sitka.beta1"
15 SITKACONF="/home/${DEFAULT_USER}/sysadmin"
16 SITKACONF_BRANCH="eg303"
17 SITKATOOLS="/root/sitka-tools"
18
19 THISHOST=`hostname -s`
20
21 suwrap() {
22   su -s /bin/bash -c "source ~/.bashrc ; $1" $2
23 }
24
25 while getopts ":pecwb" opt ; do
26   case $opt in
27     p ) PROD="prod";;
28     e ) EDI="edi";;
29     c ) CRONTAB="crontab";;
30     w ) WEBCLIENT="webclient";;
31     b ) USEBUNDLE="usebundle";;
32   esac
33 done
34 shift $(($OPTIND - 1))
35
36 if [[ -n "$PROD" ]] ; then
37   echo 'this is a production install'
38   [ "$HOSTNAME" == "nonprod" ] && HOSTNAME="prod"
39 else
40   echo 'this is NOT a production install'
41 fi
42
43 # as DEFAULT_USER
44
45 # grab Sitka config files
46 if [ ! -d "${SITKACONF}" ]
47 then
48   # this will fail unless DEFAULT_USER has read access to the repo
49   suwrap "cd /home/${DEFAULT_USER} && git clone git+ssh://git@git.sitka.bclibraries.ca/sitka-infra/sysadmin" ${DEFAULT_USER}
50 fi
51 suwrap "cd ${SITKACONF} && git fetch origin && git checkout ${SITKACONF_BRANCH} && git pull" ${DEFAULT_USER}
52
53 # checkout EG source
54 if [ ! -d "${BUILDDIR}" ]
55 then
56   suwrap "cd /home/${INSTALL_USER} && git clone git://git.sitka.bclibraries.ca/sitka/evergreen evergreen" ${INSTALL_USER}
57 fi
58 suwrap "cd ${BUILDDIR} && git fetch origin && git checkout ${BRANCH} && git pull" ${INSTALL_USER}
59
60 # download and unpack EG release
61 #rm -rf ${BUILDDIR}
62 #suwrap "cd /home/${INSTALL_USER} && wget http://open-ils.org/downloads/${EGRELEASE}.tar.gz && tar xzf ${EGRELEASE}.tar.gz" ${INSTALL_USER}
63  
64 # as root
65 cd ${BUILDDIR} && make -f Open-ILS/src/extras/Makefile.install ubuntu-trusty
66 if [[ -n "$WEBCLIENT" ]] ; then
67   cd ${BUILDDIR} && make -f Open-ILS/src/extras/Makefile.install ubuntu-trusty-developer # required for web client
68 fi
69 # by default, CPAN needs some manual input at this point; you can just accept all defaults
70  
71 # web client
72 if [[ -n "$WEBCLIENT" ]] ; then
73   if [[ -n "$USEBUNDLE" ]] ; then
74     # use bundled web client dependencies from upstream
75     if [ ! -d "/home/${INSTALL_USER}/web-client-deps" ] ; then
76       suwrap "cd /home/${INSTALL_USER} && git clone git://git.sitka.bclibraries.ca/sitka/web-client-deps web-client-deps" ${INSTALL_USER}
77     fi
78     suwrap "cd /home/${INSTALL_USER}/web-client-deps && git checkout ${STAMP_ID}" ${INSTALL_USER}
79     if [ -d "${BUILDDIR}/Open-ILS/web/js/ui/default/staff/build" ] ; then rm -rf ${BUILDDIR}/Open-ILS/web/js/ui/default/staff/build ; fi
80     suwrap "cp -r /home/${INSTALL_USER}/web-client-deps/build ${BUILDDIR}/Open-ILS/web/js/ui/default/staff/build" ${INSTALL_USER}
81   else
82     # install dependencies
83     cd ${BUILDDIR}/Open-ILS/web/js/ui/default/staff/
84     suwrap "npm install" ${INSTALL_USER}
85     suwrap "bower install" ${INSTALL_USER}
86   fi
87   suwrap "grunt all" ${INSTALL_USER} || { echo 'Could not install files for web-based staff client' ; exit 1; }
88 fi
89
90 # as INSTALL_USER
91 suwrap "cd ${BUILDDIR} && autoreconf -i" ${INSTALL_USER} # not required for release versions
92 suwrap "PATH=${INSTALLDIR}/bin:\$PATH cd ${BUILDDIR} && PATH=${INSTALLDIR}/bin:\$PATH ./configure -C --prefix=${INSTALLDIR} --sysconfdir=${INSTALLDIR}/conf --with-opensrf-headers=${INSTALLDIR}/include/ --with-opensrf-libs=${INSTALLDIR}/lib/" ${INSTALL_USER}
93 suwrap "cd ${BUILDDIR} && make" ${INSTALL_USER}
94 suwrap "cd ${BUILDDIR}/build/i18n && make LOCALE=fr-CA install && make LOCALE=en-CA install" ${INSTALL_USER}
95  
96 # as root
97 cd ${BUILDDIR} && make STAFF_CLIENT_VERSION=${VERSION} STAFF_CLIENT_STAMP_ID=${STAMP_ID} install
98 mv ${INSTALLDIR}/var/web/reports/fm_IDL.xml ${INSTALLDIR}/var/web/reports/fm_IDL.xml.orig && cp ${INSTALLDIR}/conf/fm_IDL.xml ${INSTALLDIR}/var/web/reports/
99  
100 # Apache stuff (as root):
101 APACHEFILES="/etc/apache2/mods-available/mpm_prefork.conf"
102 for APACHEFILE in ${APACHEFILES}
103 do
104   [[ -e "${APACHEFILE}" ]] && mv ${APACHEFILE} ${APACHEFILE}.`date +%Y-%m-%d-%H%M%S`
105   cp ${SITKACONF}/files/${APACHEFILE}/${HOSTNAME} ${APACHEFILE}
106 done
107 cp ${BUILDDIR}/Open-ILS/examples/apache/eg_startup /etc/apache2/eg_startup
108 sed -i 's/export APACHE_RUN_USER=www-data/export APACHE_RUN_USER=opensrf/' /etc/apache2/envvars
109 a2dismod mpm_event
110 a2enmod mpm_prefork
111 a2enmod headers
112 # ensure opensrf can run Apache
113 chown -R opensrf:opensrf /var/lock/apache2
114
115 # More Apache stuff for non-production sites
116 if [[ ! -n "$PROD" ]] ; then
117   if [ ! -d "/etc/apache2/includes" ] ; then
118     mkdir /etc/apache2/includes
119   fi
120   SITECONFIGS="/etc/apache2/sites-available/test-server.conf"
121   for SITECONFIG in ${SITECONFIGS} ; do
122     cp ${SITKACONF}/files/${SITECONFIG}/${HOSTNAME} ${SITECONFIG}
123     sed -i "s|__NONPROD__|${THISHOST}|g" ${SITECONFIG}
124     sed -i "s|__VERSION__|${VERSION}|g" ${SITECONFIG}
125   done
126   a2ensite test-server.conf
127   a2dissite 000-default
128   if [ ! -d "/etc/apache2/ssl/libraries.coop/star.catalogue.libraries.coop" ]
129   then
130     mkdir -p /etc/apache2/ssl/libraries.coop/star.catalogue.libraries.coop
131     cp ${SITKACONF}/files/etc/ssl/apache2/star.catalogue.libraries.coop/star.catalogue.libraries.coop.crt /etc/apache2/ssl/libraries.coop/star.catalogue.libraries.coop/star_catalogue_libraries_coop.crt
132     cp ${SITKACONF}/files/etc/ssl/apache2/star.catalogue.libraries.coop/star.catalogue.libraries.coop.key /etc/apache2/ssl/libraries.coop/star.catalogue.libraries.coop/star_catalogue_libraries_coop.key
133     cp ${SITKACONF}/files/etc/ssl/apache2/star.catalogue.libraries.coop/star.catalogue.libraries.coop.ca /etc/apache2/ssl/libraries.coop/star.catalogue.libraries.coop/star_catalogue_libraries_coop.ca
134   fi
135 fi
136
137 # websockets config
138 if [[ -n "$WEBCLIENT" ]] ; then
139     # use nginx proxy for websockets traffic
140     apt-get install -y nginx
141     cp -b ${SITKACONF}/files/etc/nginx/sites-available/osrf-ws-http-proxy/${HOSTNAME} /etc/nginx/sites-available/osrf-ws-http-proxy
142     ln -s /etc/nginx/sites-available/osrf-ws-http-proxy /etc/nginx/sites-enabled/osrf-ws-http-proxy
143     rm /etc/nginx/sites-enabled/default
144     cp -b ${SITKACONF}/files/etc/apache2/ports.conf/${HOSTNAME} /etc/apache2/ports.conf
145     WSJSFILES="opensrf_ws.js opensrf_ws_shared.js"
146     for WSJSFILE in ${WSJSFILES} ; do
147         # NOTE: this should be unnecessary if we installed OpenSRF with ./configure --with-websockets-port=443
148         sed -i 's/var WEBSOCKET_PORT_SSL = 7682;/var WEBSOCKET_PORT_SSL = 443;/g' ${INSTALLDIR}/lib/javascript/$WSJSFILE
149     done
150     # apache2-websockets
151     if [[ ! -n "$PROD" ]] ; then
152         if [ ! -d "/etc/apache2-websockets/ssl" ] ; then
153             cd /etc/apache2-websockets/ && ln -s /etc/apache2/ssl
154         fi
155     fi
156     if [ ! -d "/etc/apache2-websockets/includes" ] ; then
157         mkdir /etc/apache2-websockets/includes
158     fi
159     for WSINCLUDE in `ls /etc/apache2/includes` ; do
160         ln -s /etc/apache2/includes/${WSINCLUDE} /etc/apache2-websockets/includes/
161     done
162     for WSSITE in `ls /etc/apache2/sites-available` ; do
163         ln -s /etc/apache2/sites-available/${WSSITE} /etc/apache2-websockets/sites-available/
164     done
165     for WSSITEENABLED in `ls /etc/apache2/sites-enabled` ; do
166         ln -s /etc/apache2-websockets/sites-available/${WSSITEENABLED} /etc/apache2-websockets/sites-enabled/
167     done
168     if [[ -d "/etc/apache2-websockets/ssl" ]] ; then
169         rm -rf /etc/apache2-websockets/ssl
170     fi
171     cd /etc/apache2-websockets && ln -s /etc/apache2/ssl
172 fi
173
174 # install default crontab, if specified
175 if [[ -c "$CRONTAB" ]]; then
176   if [ ! -f "/etc/cron.d/evergreen-dailies" ] ; then
177     cp ${SITKACONF}/files/etc/cron.d/evergreen-dailies/${HOSTNAME} /etc/cron.d/evergreen-dailies
178   fi
179 fi
180
181 # set up log rotation
182 if [[ ! -n "$PROD" ]] ; then
183   if [ ! -f "/etc/logrotate.d/evergreen" ]
184   then
185     cp ${SITKACONF}/files/etc/logrotate.d/evergreen/${HOSTNAME} /etc/logrotate.d/evergreen
186   fi
187 fi
188
189 # action trigger filters (prod only)
190 if [[ -n "$PROD" ]] ; then
191   if [ -f "${INSTALLDIR}/conf/action_trigger_filters.json" ] ; then
192     mv ${INSTALLDIR}/conf/action_trigger_filters.json ${INSTALLDIR}/conf/action_trigger_filters.json.`date +%Y-%m-%d-%H%M%S`
193   fi
194   cp ${SITKACONF}/files/${INSTALLDIR}/conf/action_trigger_filters.json/${HOSTNAME} ${INSTALLDIR}/conf/action_trigger_filters.json
195 fi
196  
197 # 0. osrf conf stuff 
198 # FIXME: ensure osrf conf files point at a real, distinct db!
199 OSRFCONFFILES="${INSTALLDIR}/conf/opensrf.xml ${INSTALLDIR}/conf/opensrf_core.xml"
200 for OSRFCONFFILE in ${OSRFCONFFILES}
201 do
202   mv ${OSRFCONFFILE} ${OSRFCONFFILE}.`date +%Y-%m-%d-%H%M%S`
203   cp ${SITKACONF}/files/${OSRFCONFFILE}/${HOSTNAME} ${OSRFCONFFILE}
204   sed -i "s|__HOSTNAME__|${THISHOST}|g" ${OSRFCONFFILE}
205 done
206 if [ ! -f "/home/opensrf/.srfsh.xml" ]
207 then
208   cp ${SITKACONF}/files/home/opensrf/.srfsh.xml/${HOSTNAME} /home/opensrf/.srfsh.xml
209 fi 
210
211 # 1. install dojo
212 if [ ! -f "/home/opensrf/dojo-release-1.3.3.tar.gz" ]
213 then
214   cd /home/opensrf && wget http://download.dojotoolkit.org/release-1.3.3/dojo-release-1.3.3.tar.gz
215 fi
216 tar -C ${INSTALLDIR}/var/web/js -xzf /home/opensrf/dojo-release-1.3.3.tar.gz
217 cp -r ${INSTALLDIR}/var/web/js/dojo-release-1.3.3/* ${INSTALLDIR}/var/web/js/dojo/.
218 # FIXME stock dojo is probably superfluous when we use the following Evergreen-specific tarball...
219 if [ ! -f "/home/opensrf/dojo.tgz" ] ; then
220   cd /home/opensrf && wget http://evergreen-ils.org/downloads/dojo.tgz
221 fi
222 tar -C ${INSTALLDIR}/var/web/js/dojo/ -zxf /home/opensrf/dojo.tgz
223  
224 # 2. set up staff client
225 cd ${INSTALLDIR}/var/web/xul && rm server && rm current
226 cd ${INSTALLDIR}/var/web/xul && ln -s ${STAMP_ID} current && ln -s current/server server
227 for ALT_STAMP_ID in ${ALT_STAMP_IDS}
228 do
229   cd ${INSTALLDIR}/var/web/xul && ln -s current ${ALT_STAMP_ID}
230 done
231  
232 # 3. install circ scripts and opac skins - DEPRECATED
233
234 # 4a. avoid 404s
235 touch ${INSTALLDIR}/var/web/css/skin/default/register_custom.css
236 touch ${INSTALLDIR}/var/web/xul/server/locale/en-CA/patron_custom.properties
237 touch ${INSTALLDIR}/var/web/xul/server/locale/en-CA/common_custom.properties
238 touch ${INSTALLDIR}/var/web/xul/server/locale/en-CA/offline_custom.properties
239 touch ${INSTALLDIR}/var/web/xul/server/locale/en-CA/auth_custom.properties
240 touch ${INSTALLDIR}/var/web/xul/server/locale/en-CA/cat_custom.properties
241 touch ${INSTALLDIR}/var/web/xul/server/locale/en-CA/circ_custom.properties
242 touch ${INSTALLDIR}/var/web/xul/server/locale/en-US/patron_custom.properties
243 touch ${INSTALLDIR}/var/web/xul/server/locale/en-US/common_custom.properties
244 touch ${INSTALLDIR}/var/web/xul/server/locale/en-US/offline_custom.properties
245 touch ${INSTALLDIR}/var/web/xul/server/locale/en-US/auth_custom.properties
246 touch ${INSTALLDIR}/var/web/xul/server/locale/en-US/cat_custom.properties
247 touch ${INSTALLDIR}/var/web/xul/server/locale/en-US/circ_custom.properties
248 touch ${INSTALLDIR}/var/web/xul/server/skin/custom.js
249
250 # 4b. workaround for LP#1461683
251 cd ${INSTALLDIR}/var/web/xul/server/locale/en-CA && mv multiclass_search_help.html multiclass_search_help.html.orig && ln -s ../en-US/multiclass_search_help.html
252
253 # 5. locale hack - XXX deprecated?
254 #cd ${INSTALLDIR}/var/web/opac/locale && cp -fdr en-US en-US-bak && cp -fdr en-CA en-US
255  
256 # 6. deletepatron
257 # ensure apache conf contains deletepatron config (location should be ${INSTALLDIR}/var/web/deletepatron)
258 if [[ ! -d "${INSTALLDIR}/var/web/deletepatron" ]] ; then
259   NEW_DELETEPATRON_INSTALL="true"
260   cd ${INSTALLDIR}/var/web && git clone https://github.com/twirlip/deletepatron.git
261 fi
262 cd ${INSTALLDIR}/var/web/deletepatron && git checkout eg22
263 if [[ -n "$NEW_DELETEPATRON_INSTALL" ]] ; then
264   find ${INSTALLDIR}/var/web/deletepatron -name "*.pm" | xargs sed -i -e 's|/openils|/srv/openils|g'
265 fi
266 apt-get install -y libcgi-session-perl libhtml-template-perl
267
268 # 7. support scripts
269 cp ${BUILDDIR}/Open-ILS/src/support-scripts/generate_circ_notices.pl ${INSTALLDIR}/bin
270 cp ${BUILDDIR}/Open-ILS/src/support-scripts/oils_header.pl ${INSTALLDIR}/bin
271 cp ${BUILDDIR}/Open-ILS/src/support-scripts/badge_score_generator.pl ${INSTALLDIR}/bin
272
273 # 7.5 EDI (optional)
274 if [[ -n "$EDI" ]] ; then
275   cp -r ${BUILDDIR}/Open-ILS/src/edi_translator ${INSTALLDIR}/var/edi
276   cd ${INSTALLDIR}/var/edi && ./install.sh
277   cp ${BUILDDIR}/Open-ILS/src/support-scripts/edi_pusher.pl ${INSTALLDIR}/bin
278   cp ${BUILDDIR}/Open-ILS/src/support-scripts/edi_fetcher.pl ${INSTALLDIR}/bin
279   cp ${SYSADMIN}/files/${INSTALLDIR}/bin/edi_per_account_fetcher.sh ${INSTALLDIR}/bin/edi_per_account_fetcher.sh
280 fi
281
282 # 8. setup start page
283 if [ ! -d "${INSTALLDIR}/var/web/news" ]
284 then
285   mkdir ${INSTALLDIR}/var/web/news
286 fi
287 if [ ! -d "${INSTALLDIR}/var/web/news/media" ]
288 then
289   mkdir ${INSTALLDIR}/var/web/news/media
290 fi
291 NEWSFILES="index.html style.css media/logo.png media/book.png media/policy.png media/dash.png media/delete.png"
292 for NEWSFILE in ${NEWSFILES}
293 do
294   if [ -f "${SITKACONF}/files/${INSTALLDIR}/var/web/news/${NEWSFILE}/${HOSTNAME}" ]
295   then
296     cp ${SITKACONF}/files/${INSTALLDIR}/var/web/news/${NEWSFILE}/${HOSTNAME} ${INSTALLDIR}/var/web/news/${NEWSFILE}
297   fi
298 done
299 if [[ -n "$PROD" ]] ; then
300   if [ ! -e "${INSTALLDIR}/var/web/news/wikipull.pl" ] ; then cp ${SITKACONF}/files/${INSTALLDIR}/var/web/news/wikipull.pl/${HOSTNAME} ${INSTALLDIR}/var/web/news/wikipull.pl ; fi
301   if [ ! -e "/etc/cron.d/news" ] ; then cp ${SITKACONF}/files/etc/cron.d/news/${HOSTNAME} /etc/cron.d/news ; fi
302 else
303   # nonprod server, auto-update splash page with install info
304   TODAY=`date +'%A %d %B %Y'`
305   sed -i "s|__THISHOST__|${THISHOST}|g" ${INSTALLDIR}/var/web/news/index.html
306   sed -i "s|__TODAY__|${TODAY}|g" ${INSTALLDIR}/var/web/news/index.html
307   sed -i "s|__VERSION__|${VERSION}|g" ${INSTALLDIR}/var/web/news/index.html
308   sed -i "s|__BRANCH__|${BRANCH}|g" ${INSTALLDIR}/var/web/news/index.html
309 fi
310
311 # 8.5 offline patron list
312 if [ ! -d "${INSTALLDIR}/var/data/offline/blocked" ] ; then 
313   # TODO: handle prod - an NFS share should exist
314   if [[ ! -n "$PROD" ]] ; then
315     mkdir -p ${INSTALLDIR}/var/data/offline/blocked
316   fi
317 fi
318 if [ ! -e "${INSTALLDIR}/var/web/standalone/list.txt" ] ; then ln -sf ${INSTALLDIR}/var/data/offline/blocked/patron-block-list.txt ${INSTALLDIR}/var/web/standalone/list.txt ; fi
319 if [ ! -e "${INSTALLDIR}/bin/update-offline-blocked-list.sh" ] ; then cp ${SITKATOOLS}/maintenance/update-offline-blocked-list.sh ${INSTALLDIR}/bin/update-offline-blocked-list.sh ; fi
320
321 cp ${SITKACONF}/files${INSTALLDIR}/var/data/zips.txt/${HOSTNAME} ${INSTALLDIR}/var/data/zips.txt
322
323 # install legacy OverDrive API integration
324 cp -r ${SITKATOOLS}/overdrive-eg-opac/build/* ${INSTALLDIR}/var/web/js/ui/default/opac
325 ODAPI_LIBS="bc mb"
326 for ODAPI_LIB in ${ODAPI_LIBS} ; do
327   cp ${SITKACONF}/files/${INSTALLDIR}/var/web/js/ui/default/opac/${ODAPI_LIB}/od_config.js ${INSTALLDIR}/var/web/js/ui/default/opac/${ODAPI_LIB}/od_config.js
328 done
329
330 # install mobile PAC
331 cd ${INSTALLDIR}/var/web/opac/extras && git clone git://git.sitka.bclibraries.ca/sitka/mobile-evergreen-opac.git mobile
332
333 # 9. make sure opensrf owns all the stuff we just did
334 echo 'managing file permissions...'
335 if [[ ! -n "$PROD" ]] ; then
336   chown -R opensrf:opensrf ${INSTALLDIR} 2>/dev/null
337 else
338   for file in `ls -1 ${INSTALLDIR} | grep -v var` ; do chown -R opensrf:opensrf ${INSTALLDIR}/$file ; done
339   chown opensrf:opensrf ${INSTALLDIR}/var
340   for file in `ls -1 ${INSTALLDIR}/var | egrep -v '(data|tmp|web)'` ; do chown -R opensrf:opensrf ${INSTALLDIR}/var/$file ; done
341   chown opensrf:opensrf ${INSTALLDIR}/var/data ${INSTALLDIR}/var/web
342   for file in `ls -1 ${INSTALLDIR}/var/data | grep -v offline` ; do chown -R opensrf:opensrf ${INSTALLDIR}/var/data/$file ; done
343   for file in `ls -1 ${INSTALLDIR}/var/web | grep -v reporter` ; do chown -R opensrf:opensrf ${INSTALLDIR}/var/web/$file ; done
344 fi
345 chown -R opensrf:opensrf /home/opensrf
346 SKINDIRS="${INSTALLDIR}/var/skins ${INSTALLDIR}/var/web/css/skin"
347 for SKINDIR in ${SKINDIRS} ; do
348   if [[ ! -d "${SKINDIR}" ]] ; then mkdir ${SKINDIR} ; fi
349   chmod 777 ${SKINDIR}
350   chown -R ${DEFAULT_USER}:${DEFAULT_USER} ${SKINDIR}
351 done
352 chown -R ${DEFAULT_USER}:${DEFAULT_USER} ${INSTALLDIR}/conf/kpac ${INSTALLDIR}/var/web/images/kpac
353
354 # 10. staff client stuff
355 apt-get install -y nsis unzip
356
357 # 11. integrity checker prereqs
358 apt-get install -y libconfig-simple-perl libgit-repository-perl libdate-manip-perl
359
360 # 12. paper overdue prereqs
361 apt-get install -y python-reportlab python-reportlab-accel unifont
362
363 echo 'Evergreen is installed!'
364 if [[ -n "$WEBCLIENT" ]] ; then
365   echo 'Remember to start the websockets service: /etc/init.d/apache2-websockets start'
366 fi
367