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