Better handling of non-prod Apache config; smarter regex for matching template values
[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}"
ae9cb412
JD
7#EGRELEASE="Evergreen-ILS-2.8.beta"
8#BUILDDIR="${HOMEDIR}/${EGRELEASE}"
9BUILDDIR="${HOMEDIR}/evergreen"
0155bbac 10INSTALLDIR="/srv/openils"
fae89064 11BRANCH="production/sitka_2_8_tpac"
df5285f4
JD
12STAMP_ID="rel_2_8_1"
13ALT_STAMP_IDS="2_8_1 rel_2_8_beta 2_8_beta rel_2_8_0 2_8_0"
4115cc36 14VERSION="2.8.1.sitka.0"
0155bbac 15SITKACONF="${HOMEDIR}/sysadmin"
fae89064 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";;
24057702
JD
29 esac
30done
31shift $(($OPTIND - 1))
32
33if [[ -n "$PROD" ]] ; then
34 echo 'this is a production install'
35else
36 echo 'this is NOT a production install'
37fi
38
0155bbac
JD
39# as DEFAULT_USER
40
41# grab Sitka config files
42if [ ! -d "${SITKACONF}" ]
43then
44 # this will fail unless DEFAULT_USER has read access to the repo
e724d7db 45 suwrap "cd ${HOMEDIR} && git clone git+ssh://git@git.sitka.bclibraries.ca/sitka-infra/sysadmin" ${DEFAULT_USER}
0155bbac 46fi
902a19b7 47suwrap "cd ${SITKACONF} && git fetch origin && git checkout ${SITKACONF_BRANCH} && git pull" ${DEFAULT_USER}
0155bbac
JD
48
49# checkout EG source
ae9cb412
JD
50if [ ! -d "${BUILDDIR}" ]
51then
52 suwrap "cd ${HOMEDIR} && git clone git://git.sitka.bclibraries.ca/sitka/evergreen evergreen" ${DEFAULT_USER}
53fi
54suwrap "cd ${BUILDDIR} && git fetch origin && git checkout ${BRANCH} && git pull" ${DEFAULT_USER}
71f85432
JD
55
56# download and unpack EG release
ae9cb412
JD
57#rm -rf ${BUILDDIR}
58#suwrap "cd ${HOMEDIR} && wget http://open-ils.org/downloads/${EGRELEASE}.tar.gz && tar xzf ${EGRELEASE}.tar.gz" ${DEFAULT_USER}
0155bbac
JD
59
60# as root
71f85432 61cd ${BUILDDIR} && make -f Open-ILS/src/extras/Makefile.install ubuntu-trusty
4115cc36 62#cd ${BUILDDIR} && make -f Open-ILS/src/extras/Makefile.install ubuntu-trusty-developer # required for web client
0155bbac
JD
63# by default, CPAN needs some manual input at this point; you can just accept all defaults
64
65# as DEFAULT_USER
ae9cb412 66suwrap "cd ${BUILDDIR} && autoreconf -i" ${DEFAULT_USER} # not required for release versions
f4c3759b 67suwrap "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 68suwrap "cd ${BUILDDIR} && make" ${DEFAULT_USER}
691245a2 69suwrap "cd ${BUILDDIR}/build/i18n && make LOCALE=fr-CA install && make LOCALE=en-CA install" ${DEFAULT_USER}
0155bbac
JD
70
71# as root
4115cc36 72cd ${BUILDDIR} && make STAFF_CLIENT_VERSION=${VERSION} STAFF_CLIENT_STAMP_ID=${STAMP_ID} install
ae9cb412 73mv ${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
74chown -R opensrf:opensrf ${INSTALLDIR}
75
76# Apache stuff (as root):
605401cc 77APACHEFILES="/etc/apache2/eg_vhost.conf /etc/apache2/eg_startup /etc/apache2/envvars"
0155bbac
JD
78for APACHEFILE in ${APACHEFILES}
79do
bd41f68d 80 mv ${APACHEFILE} ${APACHEFILE}.bak
0155bbac
JD
81 cp ${SITKACONF}/files/${APACHEFILE}/${HOSTNAME} ${APACHEFILE}
82done
ae9cb412
JD
83#if [ ! -d "/etc/apache2/ssl" ]
84#then
85# mkdir /etc/apache2/ssl
86# cd /etc/apache2/ssl && openssl req -new -x509 -days 365 -nodes -out server.crt -keyout server.key
87#fi
71f85432
JD
88# ensure opensrf can run Apache
89chown -R opensrf:opensrf /var/lock/apache2
7d30f3bf 90
605401cc
JD
91# More Apache stuff for non-production sites (we manage this with Puppet on prod)
92if [[ ! -n "$PROD" ]] ; then
93 SITECONFIGS="/etc/apache2/includes/498-ssl-star.catalogue.libraries.coop-include /etc/apache2/includes/499-rewrites.conf-include /etc/apache2/sites-available/eg.conf /etc/apache2/sites-available/499-star.catalogue.libraries.coop.conf"
94 for SITECONFIG in ${SITECONFIGS} ; do
95 mv ${SITECONFIG} ${SITECONFIG}.bak
96 cp ${SITKACONF}/files/${SITECONFIG}/${HOSTNAME} ${SITECONFIG}
97 sed -i "s|__NONPROD__|${THISHOST}|g" ${SITECONFIG}
98 done
99 a2ensite eg.conf
100fi
101
26b3ea66 102# set up log rotation
702f0bd2
JD
103if [[ ! -n "$PROD" ]] ; then
104 if [ ! -f "/etc/logrotate.d/evergreen" ]
105 then
106 cp ${SITKACONF}/files/etc/logrotate.d/evergreen/${HOSTNAME} /etc/logrotate.d/evergreen
107 fi
26b3ea66 108fi
0155bbac 109
0155bbac
JD
110# 0. osrf conf stuff
111# FIXME: ensure osrf conf files point at a real, distinct db!
112OSRFCONFFILES="${INSTALLDIR}/conf/opensrf.xml ${INSTALLDIR}/conf/opensrf_core.xml"
113for OSRFCONFFILE in ${OSRFCONFFILES}
114do
51a4755a 115 mv ${OSRFCONFFILE} ${OSRFCONFFILE}.bak
0155bbac
JD
116 cp ${SITKACONF}/files/${OSRFCONFFILE}/${HOSTNAME} ${OSRFCONFFILE}
117done
661d99f4 118if [ ! -f "/home/opensrf/.srfsh.xml" ]
9d46f12d 119then
661d99f4 120 cp ${SITKACONF}/files/home/opensrf/.srfsh.xml/${HOSTNAME} /home/opensrf/.srfsh.xml
9d46f12d
JD
121fi
122
0155bbac 123# 1. install dojo
abcafeff 124if [ ! -f "/home/opensrf/dojo-release-1.3.3.tar.gz" ]
51a4755a
JD
125then
126 cd /home/opensrf && wget http://download.dojotoolkit.org/release-1.3.3/dojo-release-1.3.3.tar.gz
127fi
0155bbac
JD
128tar -C ${INSTALLDIR}/var/web/js -xzf /home/opensrf/dojo-release-1.3.3.tar.gz
129cp -r ${INSTALLDIR}/var/web/js/dojo-release-1.3.3/* ${INSTALLDIR}/var/web/js/dojo/.
4b074e2e
JD
130# FIXME stock dojo is probably superfluous when we use the following Evergreen-specific tarball...
131if [ ! -f "/home/opensrf/dojo.tgz" ] ; then
132 cd /home/opensrf && wget http://evergreen-ils.org/downloads/dojo.tgz
133fi
134tar -C ${INSTALLDIR}/var/web/js/dojo/ -zxf /home/opensrf/dojo.tgz
0155bbac
JD
135
136# 2. set up staff client
9d46f12d 137cd ${INSTALLDIR}/var/web/xul && rm server && rm current
0155bbac 138cd ${INSTALLDIR}/var/web/xul && ln -s ${STAMP_ID} current && ln -s current/server server
03b5e41f
JD
139for ALT_STAMP_ID in ${ALT_STAMP_IDS}
140do
141 cd ${INSTALLDIR}/var/web/xul && ln -s current ${ALT_STAMP_ID}
142done
0155bbac 143
9d46f12d 144# 3. install circ scripts and opac skins - DEPRECATED
71f85432 145
96b76bbb
JD
146# 4a. avoid 404s
147touch ${INSTALLDIR}/var/web/css/skin/default/register_custom.css
148touch ${INSTALLDIR}/var/web/xul/server/locale/en-CA/patron_custom.properties
149touch ${INSTALLDIR}/var/web/xul/server/locale/en-CA/common_custom.properties
150touch ${INSTALLDIR}/var/web/xul/server/locale/en-CA/offline_custom.properties
151touch ${INSTALLDIR}/var/web/xul/server/locale/en-CA/auth_custom.properties
152touch ${INSTALLDIR}/var/web/xul/server/locale/en-CA/cat_custom.properties
153touch ${INSTALLDIR}/var/web/xul/server/locale/en-CA/circ_custom.properties
154touch ${INSTALLDIR}/var/web/xul/server/locale/en-US/patron_custom.properties
155touch ${INSTALLDIR}/var/web/xul/server/locale/en-US/common_custom.properties
156touch ${INSTALLDIR}/var/web/xul/server/locale/en-US/offline_custom.properties
157touch ${INSTALLDIR}/var/web/xul/server/locale/en-US/auth_custom.properties
158touch ${INSTALLDIR}/var/web/xul/server/locale/en-US/cat_custom.properties
159touch ${INSTALLDIR}/var/web/xul/server/locale/en-US/circ_custom.properties
160touch ${INSTALLDIR}/var/web/xul/server/skin/custom.js
161
162# 4b. workaround for LP#1461683
163cd ${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
164
165# 5. locale hack - XXX deprecated?
166#cd ${INSTALLDIR}/var/web/opac/locale && cp -fdr en-US en-US-bak && cp -fdr en-CA en-US
0155bbac
JD
167
168# 6. deletepatron
169# ensure apache conf contains deletepatron config (location should be ${INSTALLDIR}/var/web/deletepatron)
437b75c1
JD
170if [[ ! -d "${INSTALLDIR}/var/web/deletepatron" ]] ; then
171 NEW_DELETEPATRON_INSTALL="true"
172 cd ${INSTALLDIR}/var/web && git clone https://github.com/twirlip/deletepatron.git
173fi
174cd ${INSTALLDIR}/var/web/deletepatron && git checkout eg22
175if [[ -n "$NEW_DELETEPATRON_INSTALL" ]] ; then
176 find ${INSTALLDIR}/var/web/deletepatron -name "*.pm" | xargs sed -i -e 's|/openils|/srv/openils|g'
177fi
ae9cb412 178apt-get install -y libcgi-session-perl libhtml-template-perl
0155bbac 179
f3b555fc
JD
180# 7. support scripts
181cp ${BUILDDIR}/Open-ILS/src/support-scripts/generate_circ_notices.pl ${INSTALLDIR}/bin
22b9d1ac 182cp ${BUILDDIR}/Open-ILS/src/support-scripts/oils_header.pl ${INSTALLDIR}/bin
f3b555fc
JD
183
184# 7.5 EDI (optional)
185if [[ -n "$EDI" ]] ; then
186 cp -r ${BUILDDIR}/Open-ILS/src/edi_translator ${INSTALLDIR}/var/edi
187 cd ${INSTALLDIR}/var/edi && ./install.sh
188 cp ${BUILDDIR}/Open-ILS/src/support-scripts/edi_pusher.pl ${INSTALLDIR}/bin
189 cp ${BUILDDIR}/Open-ILS/src/support-scripts/edi_fetcher.pl ${INSTALLDIR}/bin
190 cp ${SYSADMIN}/files/${INSTALLDIR}/bin/edi_per_account_fetcher.sh ${INSTALLDIR}/bin/edi_per_account_fetcher.sh
191fi
0155bbac 192
c05e3516
JD
193# 8. setup start page
194if [ ! -d "${INSTALLDIR}/var/web/news" ]
195then
196 mkdir ${INSTALLDIR}/var/web/news
197fi
24057702
JD
198if [ ! -d "${INSTALLDIR}/var/web/news/media" ]
199then
200 mkdir ${INSTALLDIR}/var/web/news/media
201fi
202NEWSFILES="index.html style.css media/logo.png media/book.png media/policy.png media/dash.png media/delete.png"
c05e3516
JD
203for NEWSFILE in ${NEWSFILES}
204do
205 if [ -f "${SITKACONF}/files/${INSTALLDIR}/var/web/news/${NEWSFILE}/${HOSTNAME}" ]
206 then
207 cp ${SITKACONF}/files/${INSTALLDIR}/var/web/news/${NEWSFILE}/${HOSTNAME} ${INSTALLDIR}/var/web/news/${NEWSFILE}
208 fi
209done
24057702
JD
210if [[ -n "$PROD" ]] ; then
211 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
212 if [ ! -e "/etc/cron.d/news" ] ; then cp ${SITKACONF}/files/etc/cron.d/news/${HOSTNAME} /etc/cron.d/news ; fi
5edb204e
JD
213else
214 # nonprod server, auto-update splash page with install info
5edb204e 215 TODAY=`date +'%A %d %B %Y'`
605401cc
JD
216 sed -i "s|__THISHOST__|${THISHOST}|g" ${INSTALLDIR}/var/web/news/index.html
217 sed -i "s|__TODAY__|${TODAY}|g" ${INSTALLDIR}/var/web/news/index.html
218 sed -i "s|__VERSION__|${VERSION}|g" ${INSTALLDIR}/var/web/news/index.html
219 sed -i "s|__BRANCH__|${BRANCH}|g" ${INSTALLDIR}/var/web/news/index.html
24057702 220fi
c05e3516 221
341cf34e 222# 8.5 offline patron list
24057702
JD
223if [ ! -d "${INSTALLDIR}/var/data/offline/blocked" ] ; then
224 # TODO: handle prod - an NFS share should exist
225 if [[ ! -n "$PROD" ]] ; then
226 mkdir -p ${INSTALLDIR}/var/data/offline/blocked
227 fi
228fi
437b75c1 229if [ ! -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
230if [ ! -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
231
f37d71da 232cp ${SITKACONF}/files${INSTALLDIR}/var/data/zips.txt/${HOSTNAME} ${INSTALLDIR}/var/data/zips.txt
661d99f4 233
02bd66d5
JD
234cp -r ${SITKATOOLS}/overdrive-eg-opac/build/* ${INSTALLDIR}/var/web/js/ui/default/opac
235ODAPI_LIBS="bc mb"
236for ODAPI_LIB in ${ODAPI_LIBS} ; do
d8761dca 237 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
238done
239
ea5fbaea
JD
240# install mobile PAC
241cd ${INSTALLDIR}/var/web/opac/extras && git clone git://git.sitka.bclibraries.ca/sitka/mobile-evergreen-opac.git mobile
242
c05e3516 243# 9. make sure opensrf owns all the stuff we just did
0155bbac 244chown -R opensrf:opensrf ${INSTALLDIR}
d4e88b8a 245chown -R opensrf:opensrf /home/opensrf
7f126d3b
JD
246SKINDIRS="${INSTALLDIR}/var/skins ${INSTALLDIR}/var/web/css/skin"
247for SKINDIR in ${SKINDIRS} ; do
248 if [[ ! -d "${SKINDIR}" ]] ; then mkdir ${SKINDIR} ; fi
249 chmod 777 ${SKINDIR}
250 chown -R sitkastaff:sitkastaff ${SKINDIR}
251done
0155bbac 252
d4e88b8a 253# 10. staff client stuff
ae9cb412 254apt-get install -y nsis unzip
089f11fb
JD
255
256# 11. integrity checker prereqs
ae9cb412 257apt-get install -y libconfig-simple-perl libgit-repository-perl libdate-manip-perl
ee1de43f
JD
258
259# 12. paper overdue prereqs
5e12a76f 260apt-get install -y python-reportlab python-reportlab-accel unifont