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