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