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