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