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