install-eg.sh: stamp ID aliases
[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="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"
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  
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   if `cmp -s ${SITKACONF}/files/${APACHEFILE}/${HOSTNAME} ${APACHEFILE}` ; then
81     echo "${APACHEFILE} is unchanged, so not updating"
82   else
83     mv ${APACHEFILE} ${APACHEFILE}.bak
84     cp ${SITKACONF}/files/${APACHEFILE}/${HOSTNAME} ${APACHEFILE}
85   fi
86 done
87 #if [ ! -d "/etc/apache2/ssl" ]
88 #then
89 #  mkdir /etc/apache2/ssl
90 #  cd /etc/apache2/ssl && openssl req -new -x509 -days 365 -nodes -out server.crt -keyout server.key
91 #fi
92 # ensure opensrf can run Apache
93 chown -R opensrf:opensrf /var/lock/apache2
94
95 # More Apache stuff for non-production sites (we manage this with Puppet on prod)
96 if [[ ! -n "$PROD" ]] ; then
97   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"
98   for SITECONFIG in ${SITECONFIGS} ; do
99     mv ${SITECONFIG} ${SITECONFIG}.bak
100     cp ${SITKACONF}/files/${SITECONFIG}/${HOSTNAME} ${SITECONFIG}
101     sed -i "s|__NONPROD__|${THISHOST}|g" ${SITECONFIG}
102   done
103   a2ensite eg.conf
104   a2ensite 499-star.catalogue.libraries.coop.conf
105 fi
106
107 # install default crontab, if specified
108 if [[ -c "$CRONTAB" ]]; then
109   if [ ! -f "/etc/cron.d/evergreen-dailies" ] ; then
110     cp ${SITKACONF}/files/etc/cron.d/evergreen-dailies/${HOSTNAME} /etc/cron.d/evergreen-dailies
111   fi
112 fi
113
114 # set up log rotation
115 if [[ ! -n "$PROD" ]] ; then
116   if [ ! -f "/etc/logrotate.d/evergreen" ]
117   then
118     cp ${SITKACONF}/files/etc/logrotate.d/evergreen/${HOSTNAME} /etc/logrotate.d/evergreen
119   fi
120 fi
121  
122 # 0. osrf conf stuff 
123 # FIXME: ensure osrf conf files point at a real, distinct db!
124 OSRFCONFFILES="${INSTALLDIR}/conf/opensrf.xml ${INSTALLDIR}/conf/opensrf_core.xml"
125 for OSRFCONFFILE in ${OSRFCONFFILES}
126 do
127   mkdir -p /tmp/${OSRFCONFFILE}
128   cp ${SITKACONF}/files/${OSRFCONFFILE}/${HOSTNAME} /tmp/${OSRFCONFFILE}/${HOSTNAME}
129   sed -i "S|__HOSTNAME__|${THISHOST}|g" /tmp/${OSRFCONFFILE}/${HOSTNAME}
130   if `cmp -s ${SITKACONF}/files/${OSRFCONFFILE}/${HOSTNAME} /tmp/${OSRFCONFFILE}/${HOSTNAME}` ; then
131     echo "${OSRFCONFFILE} is unchanged, so not updating"
132   else
133     mv ${OSRFCONFFILE} ${OSRFCONFFILE}.bak
134     cp /tmp/${OSRFCONFFILE}/${HOSTNAME} ${OSRFCONFFILE}
135   fi
136 done
137 if [ ! -f "/home/opensrf/.srfsh.xml" ]
138 then
139   cp ${SITKACONF}/files/home/opensrf/.srfsh.xml/${HOSTNAME} /home/opensrf/.srfsh.xml
140 fi 
141
142 # 1. install dojo
143 if [ ! -f "/home/opensrf/dojo-release-1.3.3.tar.gz" ]
144 then
145   cd /home/opensrf && wget http://download.dojotoolkit.org/release-1.3.3/dojo-release-1.3.3.tar.gz
146 fi
147 tar -C ${INSTALLDIR}/var/web/js -xzf /home/opensrf/dojo-release-1.3.3.tar.gz
148 cp -r ${INSTALLDIR}/var/web/js/dojo-release-1.3.3/* ${INSTALLDIR}/var/web/js/dojo/.
149 # FIXME stock dojo is probably superfluous when we use the following Evergreen-specific tarball...
150 if [ ! -f "/home/opensrf/dojo.tgz" ] ; then
151   cd /home/opensrf && wget http://evergreen-ils.org/downloads/dojo.tgz
152 fi
153 tar -C ${INSTALLDIR}/var/web/js/dojo/ -zxf /home/opensrf/dojo.tgz
154  
155 # 2. set up staff client
156 cd ${INSTALLDIR}/var/web/xul && rm server && rm current
157 cd ${INSTALLDIR}/var/web/xul && ln -s ${STAMP_ID} current && ln -s current/server server
158 for ALT_STAMP_ID in ${ALT_STAMP_IDS}
159 do
160   cd ${INSTALLDIR}/var/web/xul && ln -s current ${ALT_STAMP_ID}
161 done
162  
163 # 3. install circ scripts and opac skins - DEPRECATED
164
165 # 4a. avoid 404s
166 touch ${INSTALLDIR}/var/web/css/skin/default/register_custom.css
167 touch ${INSTALLDIR}/var/web/xul/server/locale/en-CA/patron_custom.properties
168 touch ${INSTALLDIR}/var/web/xul/server/locale/en-CA/common_custom.properties
169 touch ${INSTALLDIR}/var/web/xul/server/locale/en-CA/offline_custom.properties
170 touch ${INSTALLDIR}/var/web/xul/server/locale/en-CA/auth_custom.properties
171 touch ${INSTALLDIR}/var/web/xul/server/locale/en-CA/cat_custom.properties
172 touch ${INSTALLDIR}/var/web/xul/server/locale/en-CA/circ_custom.properties
173 touch ${INSTALLDIR}/var/web/xul/server/locale/en-US/patron_custom.properties
174 touch ${INSTALLDIR}/var/web/xul/server/locale/en-US/common_custom.properties
175 touch ${INSTALLDIR}/var/web/xul/server/locale/en-US/offline_custom.properties
176 touch ${INSTALLDIR}/var/web/xul/server/locale/en-US/auth_custom.properties
177 touch ${INSTALLDIR}/var/web/xul/server/locale/en-US/cat_custom.properties
178 touch ${INSTALLDIR}/var/web/xul/server/locale/en-US/circ_custom.properties
179 touch ${INSTALLDIR}/var/web/xul/server/skin/custom.js
180
181 # 4b. workaround for LP#1461683
182 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
183
184 # 5. locale hack - XXX deprecated?
185 #cd ${INSTALLDIR}/var/web/opac/locale && cp -fdr en-US en-US-bak && cp -fdr en-CA en-US
186  
187 # 6. deletepatron
188 # ensure apache conf contains deletepatron config (location should be ${INSTALLDIR}/var/web/deletepatron)
189 if [[ ! -d "${INSTALLDIR}/var/web/deletepatron" ]] ; then
190   NEW_DELETEPATRON_INSTALL="true"
191   cd ${INSTALLDIR}/var/web && git clone https://github.com/twirlip/deletepatron.git
192 fi
193 cd ${INSTALLDIR}/var/web/deletepatron && git checkout eg22
194 if [[ -n "$NEW_DELETEPATRON_INSTALL" ]] ; then
195   find ${INSTALLDIR}/var/web/deletepatron -name "*.pm" | xargs sed -i -e 's|/openils|/srv/openils|g'
196 fi
197 apt-get install -y libcgi-session-perl libhtml-template-perl
198
199 # 7. support scripts
200 cp ${BUILDDIR}/Open-ILS/src/support-scripts/generate_circ_notices.pl ${INSTALLDIR}/bin
201 cp ${BUILDDIR}/Open-ILS/src/support-scripts/oils_header.pl ${INSTALLDIR}/bin
202
203 # 7.5 EDI (optional)
204 if [[ -n "$EDI" ]] ; then
205   cp -r ${BUILDDIR}/Open-ILS/src/edi_translator ${INSTALLDIR}/var/edi
206   cd ${INSTALLDIR}/var/edi && ./install.sh
207   cp ${BUILDDIR}/Open-ILS/src/support-scripts/edi_pusher.pl ${INSTALLDIR}/bin
208   cp ${BUILDDIR}/Open-ILS/src/support-scripts/edi_fetcher.pl ${INSTALLDIR}/bin
209   cp ${SYSADMIN}/files/${INSTALLDIR}/bin/edi_per_account_fetcher.sh ${INSTALLDIR}/bin/edi_per_account_fetcher.sh
210 fi
211
212 # 8. setup start page
213 if [ ! -d "${INSTALLDIR}/var/web/news" ]
214 then
215   mkdir ${INSTALLDIR}/var/web/news
216 fi
217 if [ ! -d "${INSTALLDIR}/var/web/news/media" ]
218 then
219   mkdir ${INSTALLDIR}/var/web/news/media
220 fi
221 NEWSFILES="index.html style.css media/logo.png media/book.png media/policy.png media/dash.png media/delete.png"
222 for NEWSFILE in ${NEWSFILES}
223 do
224   if [ -f "${SITKACONF}/files/${INSTALLDIR}/var/web/news/${NEWSFILE}/${HOSTNAME}" ]
225   then
226     cp ${SITKACONF}/files/${INSTALLDIR}/var/web/news/${NEWSFILE}/${HOSTNAME} ${INSTALLDIR}/var/web/news/${NEWSFILE}
227   fi
228 done
229 if [[ -n "$PROD" ]] ; then
230   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
231   if [ ! -e "/etc/cron.d/news" ] ; then cp ${SITKACONF}/files/etc/cron.d/news/${HOSTNAME} /etc/cron.d/news ; fi
232 else
233   # nonprod server, auto-update splash page with install info
234   TODAY=`date +'%A %d %B %Y'`
235   sed -i "s|__THISHOST__|${THISHOST}|g" ${INSTALLDIR}/var/web/news/index.html
236   sed -i "s|__TODAY__|${TODAY}|g" ${INSTALLDIR}/var/web/news/index.html
237   sed -i "s|__VERSION__|${VERSION}|g" ${INSTALLDIR}/var/web/news/index.html
238   sed -i "s|__BRANCH__|${BRANCH}|g" ${INSTALLDIR}/var/web/news/index.html
239 fi
240
241 # 8.5 offline patron list
242 if [ ! -d "${INSTALLDIR}/var/data/offline/blocked" ] ; then 
243   # TODO: handle prod - an NFS share should exist
244   if [[ ! -n "$PROD" ]] ; then
245     mkdir -p ${INSTALLDIR}/var/data/offline/blocked
246   fi
247 fi
248 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
249 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
250
251 cp ${SITKACONF}/files${INSTALLDIR}/var/data/zips.txt/${HOSTNAME} ${INSTALLDIR}/var/data/zips.txt
252
253 cp -r ${SITKATOOLS}/overdrive-eg-opac/build/* ${INSTALLDIR}/var/web/js/ui/default/opac
254 ODAPI_LIBS="bc mb"
255 for ODAPI_LIB in ${ODAPI_LIBS} ; do
256   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
257 done
258
259 # install mobile PAC
260 cd ${INSTALLDIR}/var/web/opac/extras && git clone git://git.sitka.bclibraries.ca/sitka/mobile-evergreen-opac.git mobile
261
262 # 9. make sure opensrf owns all the stuff we just did
263 echo 'managing file permissions...'
264 chown -R opensrf:opensrf ${INSTALLDIR} 2>/dev/null
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 chown -R sitkastaff:sitkastaff ${INSTALLDIR}/conf/kpac ${INSTALLDIR}/var/web/images/kpac
273
274 # 10. staff client stuff
275 apt-get install -y nsis unzip
276
277 # 11. integrity checker prereqs
278 apt-get install -y libconfig-simple-perl libgit-repository-perl libdate-manip-perl
279
280 # 12. paper overdue prereqs
281 apt-get install -y python-reportlab python-reportlab-accel unifont