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