Add websockets/web client install to OpenSRF and Evergreen install scripts
[sitka/sitka-tools.git] / deployment / install-eg.sh
CommitLineData
0155bbac
JD
1#!/bin/bash
2# IMPORTANT! This script assumes you have already installed OpenSRF.
3
79b2efa0 4HOSTNAME="nonprod"
0155bbac
JD
5DEFAULT_USER="sitkastaff"
6HOMEDIR="/home/${DEFAULT_USER}"
91062c75 7#EGRELEASE="Evergreen-ILS-2.10.beta"
ae9cb412
JD
8#BUILDDIR="${HOMEDIR}/${EGRELEASE}"
9BUILDDIR="${HOMEDIR}/evergreen"
0155bbac 10INSTALLDIR="/srv/openils"
b754e26f 11BRANCH="production/sitka_2_10_tpac"
40915bb6 12STAMP_ID="rel_2_10_2"
b367a212 13ALT_STAMP_IDS="rel_2_10_2_sitka_0 2_10_2_sitka_0 2_10_2 rel_2_10_1 2_10_1 rel_2_10_0 2_10_0 rel_2_10_beta 2_10_beta"
40915bb6 14VERSION="2.10.2.sitka.0"
0155bbac 15SITKACONF="${HOMEDIR}/sysadmin"
25c99192 16SITKACONF_BRANCH="master"
341cf34e 17SITKATOOLS="/root/sitka-tools"
0155bbac 18
605401cc
JD
19THISHOST=`hostname -s`
20
e724d7db 21suwrap() {
e2ad4781 22 su -s /bin/bash -c "source ~/.bashrc ; $1" $2
e724d7db
JD
23}
24
24057702
JD
25while getopts ":p" opt ; do
26 case $opt in
27 p ) PROD="prod";;
f3b555fc 28 e ) EDI="edi";;
286e0b2b 29 c ) CRONTAB="crontab";;
6298f1c5 30 w ) WEBSOCKETS="websockets";;
24057702
JD
31 esac
32done
33shift $(($OPTIND - 1))
34
35if [[ -n "$PROD" ]] ; then
36 echo 'this is a production install'
37else
38 echo 'this is NOT a production install'
39fi
40
0155bbac
JD
41# as DEFAULT_USER
42
43# grab Sitka config files
44if [ ! -d "${SITKACONF}" ]
45then
46 # this will fail unless DEFAULT_USER has read access to the repo
e724d7db 47 suwrap "cd ${HOMEDIR} && git clone git+ssh://git@git.sitka.bclibraries.ca/sitka-infra/sysadmin" ${DEFAULT_USER}
0155bbac 48fi
902a19b7 49suwrap "cd ${SITKACONF} && git fetch origin && git checkout ${SITKACONF_BRANCH} && git pull" ${DEFAULT_USER}
0155bbac
JD
50
51# checkout EG source
ae9cb412
JD
52if [ ! -d "${BUILDDIR}" ]
53then
54 suwrap "cd ${HOMEDIR} && git clone git://git.sitka.bclibraries.ca/sitka/evergreen evergreen" ${DEFAULT_USER}
55fi
56suwrap "cd ${BUILDDIR} && git fetch origin && git checkout ${BRANCH} && git pull" ${DEFAULT_USER}
71f85432
JD
57
58# download and unpack EG release
ae9cb412
JD
59#rm -rf ${BUILDDIR}
60#suwrap "cd ${HOMEDIR} && wget http://open-ils.org/downloads/${EGRELEASE}.tar.gz && tar xzf ${EGRELEASE}.tar.gz" ${DEFAULT_USER}
0155bbac
JD
61
62# as root
71f85432 63cd ${BUILDDIR} && make -f Open-ILS/src/extras/Makefile.install ubuntu-trusty
4115cc36 64#cd ${BUILDDIR} && make -f Open-ILS/src/extras/Makefile.install ubuntu-trusty-developer # required for web client
0155bbac
JD
65# by default, CPAN needs some manual input at this point; you can just accept all defaults
66
67# as DEFAULT_USER
ae9cb412 68suwrap "cd ${BUILDDIR} && autoreconf -i" ${DEFAULT_USER} # not required for release versions
f4c3759b 69suwrap "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/" ${DEFAULT_USER}
e724d7db 70suwrap "cd ${BUILDDIR} && make" ${DEFAULT_USER}
691245a2 71suwrap "cd ${BUILDDIR}/build/i18n && make LOCALE=fr-CA install && make LOCALE=en-CA install" ${DEFAULT_USER}
0155bbac
JD
72
73# as root
4115cc36 74cd ${BUILDDIR} && make STAFF_CLIENT_VERSION=${VERSION} STAFF_CLIENT_STAMP_ID=${STAMP_ID} install
ae9cb412 75mv ${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/
0155bbac
JD
76
77# Apache stuff (as root):
605401cc 78APACHEFILES="/etc/apache2/eg_vhost.conf /etc/apache2/eg_startup /etc/apache2/envvars"
0155bbac
JD
79for APACHEFILE in ${APACHEFILES}
80do
40ce1f36
JD
81 mv ${APACHEFILE} ${APACHEFILE}.`date +%Y-%m-%d-%H%M%S`
82 cp ${SITKACONF}/files/${APACHEFILE}/${HOSTNAME} ${APACHEFILE}
0155bbac 83done
71f85432
JD
84# ensure opensrf can run Apache
85chown -R opensrf:opensrf /var/lock/apache2
7d30f3bf 86
605401cc
JD
87# More Apache stuff for non-production sites (we manage this with Puppet on prod)
88if [[ ! -n "$PROD" ]] ; then
09cde232
JD
89 if [ ! -d "/etc/apache2/includes" ] ; then
90 mkdir /etc/apache2/includes
91 fi
3148afad 92 SITECONFIGS="/etc/apache2/includes/498-ssl-star.catalogue.libraries.coop-include /etc/apache2/includes/499-rewrites.conf-include /etc/apache2/includes/default.conf-include /etc/apache2/sites-available/eg.conf /etc/apache2/sites-available/499-star.catalogue.libraries.coop.conf /etc/apache2/sites-available/test-server.conf"
605401cc
JD
93 for SITECONFIG in ${SITECONFIGS} ; do
94 mv ${SITECONFIG} ${SITECONFIG}.bak
95 cp ${SITKACONF}/files/${SITECONFIG}/${HOSTNAME} ${SITECONFIG}
96 sed -i "s|__NONPROD__|${THISHOST}|g" ${SITECONFIG}
3148afad 97 sed -i "s|__VERSION__|${VERSION}|g" ${SITECONFIG}
605401cc 98 done
884250a7
JD
99 if [ ! -d "/etc/apache2/ssl/libraries.coop/star.catalogue.libraries.coop" ]
100 then
101 mkdir -p /etc/apache2/ssl/libraries.coop/star.catalogue.libraries.coop
102 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
103 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
104 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
105 fi
605401cc 106 a2ensite eg.conf
077e0b77 107 a2ensite 499-star.catalogue.libraries.coop.conf
3148afad 108 a2ensite test-server.conf
605401cc
JD
109fi
110
286e0b2b
JD
111# install default crontab, if specified
112if [[ -c "$CRONTAB" ]]; then
113 if [ ! -f "/etc/cron.d/evergreen-dailies" ] ; then
114 cp ${SITKACONF}/files/etc/cron.d/evergreen-dailies/${HOSTNAME} /etc/cron.d/evergreen-dailies
115 fi
116fi
117
26b3ea66 118# set up log rotation
702f0bd2
JD
119if [[ ! -n "$PROD" ]] ; then
120 if [ ! -f "/etc/logrotate.d/evergreen" ]
121 then
122 cp ${SITKACONF}/files/etc/logrotate.d/evergreen/${HOSTNAME} /etc/logrotate.d/evergreen
123 fi
26b3ea66 124fi
bcd0a18c
JD
125
126# action trigger filters (prod only)
127if [[ -n "$PROD" ]] ; then
128 if [ -f "${INSTALLDIR}/conf/action_trigger_filters.json" ] ; then
129 mv ${INSTALLDIR}/conf/action_trigger_filters.json ${INSTALLDIR}/conf/action_trigger_filters.json.`date +%Y-%m-%d-%H%M%S`
130 fi
131 cp ${SITKACONF}/files/${INSTALLDIR}/conf/action_trigger_filters.json/${HOSTNAME} ${INSTALLDIR}/conf/action_trigger_filters.json
132fi
0155bbac 133
0155bbac
JD
134# 0. osrf conf stuff
135# FIXME: ensure osrf conf files point at a real, distinct db!
136OSRFCONFFILES="${INSTALLDIR}/conf/opensrf.xml ${INSTALLDIR}/conf/opensrf_core.xml"
137for OSRFCONFFILE in ${OSRFCONFFILES}
138do
40ce1f36
JD
139 mv ${OSRFCONFFILE} ${OSRFCONFFILE}.`date +%Y-%m-%d-%H%M%S`
140 cp ${SITKACONF}/files/${OSRFCONFFILE}/${HOSTNAME} ${OSRFCONFFILE}
141 sed -i "s|__HOSTNAME__|${THISHOST}|g" ${OSRFCONFFILE}
0155bbac 142done
661d99f4 143if [ ! -f "/home/opensrf/.srfsh.xml" ]
9d46f12d 144then
661d99f4 145 cp ${SITKACONF}/files/home/opensrf/.srfsh.xml/${HOSTNAME} /home/opensrf/.srfsh.xml
9d46f12d
JD
146fi
147
0155bbac 148# 1. install dojo
abcafeff 149if [ ! -f "/home/opensrf/dojo-release-1.3.3.tar.gz" ]
51a4755a
JD
150then
151 cd /home/opensrf && wget http://download.dojotoolkit.org/release-1.3.3/dojo-release-1.3.3.tar.gz
152fi
0155bbac
JD
153tar -C ${INSTALLDIR}/var/web/js -xzf /home/opensrf/dojo-release-1.3.3.tar.gz
154cp -r ${INSTALLDIR}/var/web/js/dojo-release-1.3.3/* ${INSTALLDIR}/var/web/js/dojo/.
4b074e2e
JD
155# FIXME stock dojo is probably superfluous when we use the following Evergreen-specific tarball...
156if [ ! -f "/home/opensrf/dojo.tgz" ] ; then
157 cd /home/opensrf && wget http://evergreen-ils.org/downloads/dojo.tgz
158fi
159tar -C ${INSTALLDIR}/var/web/js/dojo/ -zxf /home/opensrf/dojo.tgz
0155bbac
JD
160
161# 2. set up staff client
9d46f12d 162cd ${INSTALLDIR}/var/web/xul && rm server && rm current
0155bbac 163cd ${INSTALLDIR}/var/web/xul && ln -s ${STAMP_ID} current && ln -s current/server server
03b5e41f
JD
164for ALT_STAMP_ID in ${ALT_STAMP_IDS}
165do
166 cd ${INSTALLDIR}/var/web/xul && ln -s current ${ALT_STAMP_ID}
167done
0155bbac 168
9d46f12d 169# 3. install circ scripts and opac skins - DEPRECATED
71f85432 170
96b76bbb
JD
171# 4a. avoid 404s
172touch ${INSTALLDIR}/var/web/css/skin/default/register_custom.css
173touch ${INSTALLDIR}/var/web/xul/server/locale/en-CA/patron_custom.properties
174touch ${INSTALLDIR}/var/web/xul/server/locale/en-CA/common_custom.properties
175touch ${INSTALLDIR}/var/web/xul/server/locale/en-CA/offline_custom.properties
176touch ${INSTALLDIR}/var/web/xul/server/locale/en-CA/auth_custom.properties
177touch ${INSTALLDIR}/var/web/xul/server/locale/en-CA/cat_custom.properties
178touch ${INSTALLDIR}/var/web/xul/server/locale/en-CA/circ_custom.properties
179touch ${INSTALLDIR}/var/web/xul/server/locale/en-US/patron_custom.properties
180touch ${INSTALLDIR}/var/web/xul/server/locale/en-US/common_custom.properties
181touch ${INSTALLDIR}/var/web/xul/server/locale/en-US/offline_custom.properties
182touch ${INSTALLDIR}/var/web/xul/server/locale/en-US/auth_custom.properties
183touch ${INSTALLDIR}/var/web/xul/server/locale/en-US/cat_custom.properties
184touch ${INSTALLDIR}/var/web/xul/server/locale/en-US/circ_custom.properties
185touch ${INSTALLDIR}/var/web/xul/server/skin/custom.js
186
187# 4b. workaround for LP#1461683
188cd ${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
71f85432
JD
189
190# 5. locale hack - XXX deprecated?
191#cd ${INSTALLDIR}/var/web/opac/locale && cp -fdr en-US en-US-bak && cp -fdr en-CA en-US
0155bbac
JD
192
193# 6. deletepatron
194# ensure apache conf contains deletepatron config (location should be ${INSTALLDIR}/var/web/deletepatron)
437b75c1
JD
195if [[ ! -d "${INSTALLDIR}/var/web/deletepatron" ]] ; then
196 NEW_DELETEPATRON_INSTALL="true"
197 cd ${INSTALLDIR}/var/web && git clone https://github.com/twirlip/deletepatron.git
198fi
199cd ${INSTALLDIR}/var/web/deletepatron && git checkout eg22
200if [[ -n "$NEW_DELETEPATRON_INSTALL" ]] ; then
201 find ${INSTALLDIR}/var/web/deletepatron -name "*.pm" | xargs sed -i -e 's|/openils|/srv/openils|g'
202fi
ae9cb412 203apt-get install -y libcgi-session-perl libhtml-template-perl
0155bbac 204
f3b555fc
JD
205# 7. support scripts
206cp ${BUILDDIR}/Open-ILS/src/support-scripts/generate_circ_notices.pl ${INSTALLDIR}/bin
22b9d1ac 207cp ${BUILDDIR}/Open-ILS/src/support-scripts/oils_header.pl ${INSTALLDIR}/bin
f3b555fc
JD
208
209# 7.5 EDI (optional)
210if [[ -n "$EDI" ]] ; then
211 cp -r ${BUILDDIR}/Open-ILS/src/edi_translator ${INSTALLDIR}/var/edi
212 cd ${INSTALLDIR}/var/edi && ./install.sh
213 cp ${BUILDDIR}/Open-ILS/src/support-scripts/edi_pusher.pl ${INSTALLDIR}/bin
214 cp ${BUILDDIR}/Open-ILS/src/support-scripts/edi_fetcher.pl ${INSTALLDIR}/bin
215 cp ${SYSADMIN}/files/${INSTALLDIR}/bin/edi_per_account_fetcher.sh ${INSTALLDIR}/bin/edi_per_account_fetcher.sh
216fi
0155bbac 217
c05e3516
JD
218# 8. setup start page
219if [ ! -d "${INSTALLDIR}/var/web/news" ]
220then
221 mkdir ${INSTALLDIR}/var/web/news
222fi
24057702
JD
223if [ ! -d "${INSTALLDIR}/var/web/news/media" ]
224then
225 mkdir ${INSTALLDIR}/var/web/news/media
226fi
227NEWSFILES="index.html style.css media/logo.png media/book.png media/policy.png media/dash.png media/delete.png"
c05e3516
JD
228for NEWSFILE in ${NEWSFILES}
229do
230 if [ -f "${SITKACONF}/files/${INSTALLDIR}/var/web/news/${NEWSFILE}/${HOSTNAME}" ]
231 then
232 cp ${SITKACONF}/files/${INSTALLDIR}/var/web/news/${NEWSFILE}/${HOSTNAME} ${INSTALLDIR}/var/web/news/${NEWSFILE}
233 fi
234done
24057702
JD
235if [[ -n "$PROD" ]] ; then
236 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
237 if [ ! -e "/etc/cron.d/news" ] ; then cp ${SITKACONF}/files/etc/cron.d/news/${HOSTNAME} /etc/cron.d/news ; fi
5edb204e
JD
238else
239 # nonprod server, auto-update splash page with install info
5edb204e 240 TODAY=`date +'%A %d %B %Y'`
605401cc
JD
241 sed -i "s|__THISHOST__|${THISHOST}|g" ${INSTALLDIR}/var/web/news/index.html
242 sed -i "s|__TODAY__|${TODAY}|g" ${INSTALLDIR}/var/web/news/index.html
243 sed -i "s|__VERSION__|${VERSION}|g" ${INSTALLDIR}/var/web/news/index.html
244 sed -i "s|__BRANCH__|${BRANCH}|g" ${INSTALLDIR}/var/web/news/index.html
24057702 245fi
c05e3516 246
341cf34e 247# 8.5 offline patron list
24057702
JD
248if [ ! -d "${INSTALLDIR}/var/data/offline/blocked" ] ; then
249 # TODO: handle prod - an NFS share should exist
250 if [[ ! -n "$PROD" ]] ; then
251 mkdir -p ${INSTALLDIR}/var/data/offline/blocked
252 fi
253fi
437b75c1 254if [ ! -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
341cf34e
JD
255if [ ! -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
256
f37d71da 257cp ${SITKACONF}/files${INSTALLDIR}/var/data/zips.txt/${HOSTNAME} ${INSTALLDIR}/var/data/zips.txt
661d99f4 258
02bd66d5
JD
259cp -r ${SITKATOOLS}/overdrive-eg-opac/build/* ${INSTALLDIR}/var/web/js/ui/default/opac
260ODAPI_LIBS="bc mb"
261for ODAPI_LIB in ${ODAPI_LIBS} ; do
d8761dca 262 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
02bd66d5
JD
263done
264
ea5fbaea
JD
265# install mobile PAC
266cd ${INSTALLDIR}/var/web/opac/extras && git clone git://git.sitka.bclibraries.ca/sitka/mobile-evergreen-opac.git mobile
267
c05e3516 268# 9. make sure opensrf owns all the stuff we just did
b7afc39d 269echo 'managing file permissions...'
af205db8
JD
270if [[ ! -n "$PROD" ]] ; then
271 chown -R opensrf:opensrf ${INSTALLDIR} 2>/dev/null
272else
273 for file in `ls -1 ${INSTALLDIR} | grep -v var` ; do chown -R opensrf:opensrf ${INSTALLDIR}/$file ; done
274 chown opensrf:opensrf ${INSTALLDIR}/var
275 for file in `ls -1 ${INSTALLDIR}/var | egrep -v '(data|tmp|web)'` ; do chown -R opensrf:opensrf ${INSTALLDIR}/var/$file ; done
276 chown opensrf:opensrf ${INSTALLDIR}/var/data ${INSTALLDIR}/var/web
277 for file in `ls -1 ${INSTALLDIR}/var/data | grep -v offline` ; do chown -R opensrf:opensrf ${INSTALLDIR}/var/data/$file ; done
278 for file in `ls -1 ${INSTALLDIR}/var/web | grep -v reporter` ; do chown -R opensrf:opensrf ${INSTALLDIR}/var/web/$file ; done
279fi
d4e88b8a 280chown -R opensrf:opensrf /home/opensrf
7f126d3b
JD
281SKINDIRS="${INSTALLDIR}/var/skins ${INSTALLDIR}/var/web/css/skin"
282for SKINDIR in ${SKINDIRS} ; do
283 if [[ ! -d "${SKINDIR}" ]] ; then mkdir ${SKINDIR} ; fi
284 chmod 777 ${SKINDIR}
285 chown -R sitkastaff:sitkastaff ${SKINDIR}
286done
b7afc39d 287chown -R sitkastaff:sitkastaff ${INSTALLDIR}/conf/kpac ${INSTALLDIR}/var/web/images/kpac
0155bbac 288
d4e88b8a 289# 10. staff client stuff
ae9cb412 290apt-get install -y nsis unzip
089f11fb
JD
291
292# 11. integrity checker prereqs
ae9cb412 293apt-get install -y libconfig-simple-perl libgit-repository-perl libdate-manip-perl
ee1de43f
JD
294
295# 12. paper overdue prereqs
5e12a76f 296apt-get install -y python-reportlab python-reportlab-accel unifont
6298f1c5
JD
297
298# web client
299if [[ -n "$WEBSOCKETS" ]] ; then
300 cd ${BUILDDIR}/Open-ILS/web/js/ui/default/staff/
301 npm install
302 bower install
303 grunt all
304 echo 'Remember to start the websockets service: /etc/init.d/apache2-websockets start'
305fi
306
307echo 'Evergreen is installed!'
308