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