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