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