install-eg.sh: do not set up local log rotation on prod
[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-28"
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="upgrade/eg28/final-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="eg28"
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   esac
27 done
28 shift $(($OPTIND - 1))
29
30 if [[ -n "$PROD" ]] ; then
31   echo 'this is a production install'
32 else
33   echo 'this is NOT a production install'
34 fi
35
36 # as DEFAULT_USER
37
38 # grab Sitka config files
39 if [ ! -d "${SITKACONF}" ]
40 then
41   # this will fail unless DEFAULT_USER has read access to the repo
42   suwrap "cd ${HOMEDIR} && git clone git+ssh://git@git.sitka.bclibraries.ca/sitka-infra/sysadmin" ${DEFAULT_USER}
43 fi
44 suwrap "cd ${SITKACONF} && git fetch origin && git checkout ${SITKACONF_BRANCH} && git pull" ${DEFAULT_USER}
45
46 # checkout EG source
47 if [ ! -d "${BUILDDIR}" ]
48 then
49   suwrap "cd ${HOMEDIR} && git clone git://git.sitka.bclibraries.ca/sitka/evergreen evergreen" ${DEFAULT_USER}
50 fi
51 suwrap "cd ${BUILDDIR} && git fetch origin && git checkout ${BRANCH} && git pull" ${DEFAULT_USER}
52
53 # download and unpack EG release
54 #rm -rf ${BUILDDIR}
55 #suwrap "cd ${HOMEDIR} && wget http://open-ils.org/downloads/${EGRELEASE}.tar.gz && tar xzf ${EGRELEASE}.tar.gz" ${DEFAULT_USER}
56  
57 # as root
58 cd ${BUILDDIR} && make -f Open-ILS/src/extras/Makefile.install ubuntu-trusty
59 #cd ${BUILDDIR} && make -f Open-ILS/src/extras/Makefile.install ubuntu-trusty-developer # required for web client
60 # by default, CPAN needs some manual input at this point; you can just accept all defaults
61  
62 # as DEFAULT_USER
63 suwrap "cd ${BUILDDIR} && autoreconf -i" ${DEFAULT_USER} # not required for release versions
64 suwrap "cd ${BUILDDIR} && ./configure -C --prefix=${INSTALLDIR} --sysconfdir=${INSTALLDIR}/conf --with-opensrf-headers=${INSTALLDIR}/include/ --with-opensrf-libs=${INSTALLDIR}/lib/" ${DEFAULT_USER}
65 suwrap "cd ${BUILDDIR} && make" ${DEFAULT_USER}
66 suwrap "cd ${BUILDDIR}/build/i18n && make LOCALE=fr-CA install && make LOCALE=en-CA install" ${DEFAULT_USER}
67  
68 # as root
69 cd ${BUILDDIR} && make STAFF_CLIENT_VERSION=${VERSION} STAFF_CLIENT_STAMP_ID=${STAMP_ID} install
70 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/
71 chown -R opensrf:opensrf ${INSTALLDIR}
72  
73 # Apache stuff (as root):
74 APACHEFILES="/etc/apache2/eg_vhost.conf /etc/apache2/eg_startup /etc/apache2/sites-available/eg.conf /etc/apache2/envvars"
75 for APACHEFILE in ${APACHEFILES}
76 do
77   mv ${APACHEFILE} ${APACHEFILE}.bak
78   cp ${SITKACONF}/files/${APACHEFILE}/${HOSTNAME} ${APACHEFILE}
79 done
80 #a2dissite 000-default
81 #a2ensite eg.conf
82 #if [ ! -d "/etc/apache2/ssl" ]
83 #then
84 #  mkdir /etc/apache2/ssl
85 #  cd /etc/apache2/ssl && openssl req -new -x509 -days 365 -nodes -out server.crt -keyout server.key
86 #fi
87 # ensure opensrf can run Apache
88 chown -R opensrf:opensrf /var/lock/apache2
89
90 # set up log rotation
91 if [[ ! -n "$PROD" ]] ; then
92   if [ ! -f "/etc/logrotate.d/evergreen" ]
93   then
94     cp ${SITKACONF}/files/etc/logrotate.d/evergreen/${HOSTNAME} /etc/logrotate.d/evergreen
95   fi
96 fi
97  
98 # 0. osrf conf stuff 
99 # FIXME: ensure osrf conf files point at a real, distinct db!
100 OSRFCONFFILES="${INSTALLDIR}/conf/opensrf.xml ${INSTALLDIR}/conf/opensrf_core.xml"
101 for OSRFCONFFILE in ${OSRFCONFFILES}
102 do
103   mv ${OSRFCONFFILE} ${OSRFCONFFILE}.bak
104   cp ${SITKACONF}/files/${OSRFCONFFILE}/${HOSTNAME} ${OSRFCONFFILE}
105 done
106 if [ ! -f "/home/opensrf/.srfsh.xml" ]
107 then
108   cp ${SITKACONF}/files/home/opensrf/.srfsh.xml/${HOSTNAME} /home/opensrf/.srfsh.xml
109 fi 
110
111 # 1. install dojo
112 if [ ! -f "/home/opensrf/dojo-release-1.3.3.tar.gz" ]
113 then
114   cd /home/opensrf && wget http://download.dojotoolkit.org/release-1.3.3/dojo-release-1.3.3.tar.gz
115 fi
116 tar -C ${INSTALLDIR}/var/web/js -xzf /home/opensrf/dojo-release-1.3.3.tar.gz
117 cp -r ${INSTALLDIR}/var/web/js/dojo-release-1.3.3/* ${INSTALLDIR}/var/web/js/dojo/.
118  
119 # 2. set up staff client
120 cd ${INSTALLDIR}/var/web/xul && rm server && rm current
121 cd ${INSTALLDIR}/var/web/xul && ln -s ${STAMP_ID} current && ln -s current/server server
122 for ALT_STAMP_ID in ${ALT_STAMP_IDS}
123 do
124   cd ${INSTALLDIR}/var/web/xul && ln -s current ${ALT_STAMP_ID}
125 done
126  
127 # 3. install circ scripts and opac skins - DEPRECATED
128
129 # 4a. avoid 404s
130 touch ${INSTALLDIR}/var/web/css/skin/default/register_custom.css
131 touch ${INSTALLDIR}/var/web/xul/server/locale/en-CA/patron_custom.properties
132 touch ${INSTALLDIR}/var/web/xul/server/locale/en-CA/common_custom.properties
133 touch ${INSTALLDIR}/var/web/xul/server/locale/en-CA/offline_custom.properties
134 touch ${INSTALLDIR}/var/web/xul/server/locale/en-CA/auth_custom.properties
135 touch ${INSTALLDIR}/var/web/xul/server/locale/en-CA/cat_custom.properties
136 touch ${INSTALLDIR}/var/web/xul/server/locale/en-CA/circ_custom.properties
137 touch ${INSTALLDIR}/var/web/xul/server/locale/en-US/patron_custom.properties
138 touch ${INSTALLDIR}/var/web/xul/server/locale/en-US/common_custom.properties
139 touch ${INSTALLDIR}/var/web/xul/server/locale/en-US/offline_custom.properties
140 touch ${INSTALLDIR}/var/web/xul/server/locale/en-US/auth_custom.properties
141 touch ${INSTALLDIR}/var/web/xul/server/locale/en-US/cat_custom.properties
142 touch ${INSTALLDIR}/var/web/xul/server/locale/en-US/circ_custom.properties
143 touch ${INSTALLDIR}/var/web/xul/server/skin/custom.js
144
145 # 4b. workaround for LP#1461683
146 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
147
148 # 5. locale hack - XXX deprecated?
149 #cd ${INSTALLDIR}/var/web/opac/locale && cp -fdr en-US en-US-bak && cp -fdr en-CA en-US
150  
151 # 6. deletepatron
152 # ensure apache conf contains deletepatron config (location should be ${INSTALLDIR}/var/web/deletepatron)
153 #cd ${INSTALLDIR}/var/web && git clone https://github.com/twirlip/deletepatron.git
154 #cd ${INSTALLDIR}/var/web/deletepatron && git checkout eg22 && find . -name "*.pm" | xargs sed -i -e 's|/openils|/srv/openils|g'
155 apt-get install -y libcgi-session-perl libhtml-template-perl
156
157 # 7. support scripts - XXX deprecated?
158 #cp ${BUILDDIR}/Open-ILS/src/support-scripts/generate_circ_notices.pl ${INSTALLDIR}/bin
159 #cp ${BUILDDIR}/Open-ILS/src/support-scripts/oils_header.pl ${INSTALLDIR}/bin
160
161 # 8. setup start page
162 if [ ! -d "${INSTALLDIR}/var/web/news" ]
163 then
164   mkdir ${INSTALLDIR}/var/web/news
165 fi
166 if [ ! -d "${INSTALLDIR}/var/web/news/media" ]
167 then
168   mkdir ${INSTALLDIR}/var/web/news/media
169 fi
170 NEWSFILES="index.html style.css media/logo.png media/book.png media/policy.png media/dash.png media/delete.png"
171 for NEWSFILE in ${NEWSFILES}
172 do
173   if [ -f "${SITKACONF}/files/${INSTALLDIR}/var/web/news/${NEWSFILE}/${HOSTNAME}" ]
174   then
175     cp ${SITKACONF}/files/${INSTALLDIR}/var/web/news/${NEWSFILE}/${HOSTNAME} ${INSTALLDIR}/var/web/news/${NEWSFILE}
176   fi
177 done
178 if [[ -n "$PROD" ]] ; then
179   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
180   if [ ! -e "/etc/cron.d/news" ] ; then cp ${SITKACONF}/files/etc/cron.d/news/${HOSTNAME} /etc/cron.d/news ; fi
181 fi
182
183 # 8.5 offline patron list
184 if [ ! -d "${INSTALLDIR}/var/data/offline/blocked" ] ; then 
185   # TODO: handle prod - an NFS share should exist
186   if [[ ! -n "$PROD" ]] ; then
187     mkdir -p ${INSTALLDIR}/var/data/offline/blocked
188   fi
189 fi
190 if [ ! -e "${INSTALLDIR}/var/web/standalone/list.txt" ] ; then ln -s ${INSTALLDIR}/var/data/offline/blocked/patron-block-list.txt ${INSTALLDIR}/var/web/standalone/list.txt ; fi
191 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
192
193 cp ${SITKACONF}/files${INSTALLDIR}/var/data/zips.txt/${HOSTNAME} ${INSTALLDIR}/var/data/zips.txt
194
195 # 9. make sure opensrf owns all the stuff we just did
196 chown -R opensrf:opensrf ${INSTALLDIR}
197 chown -R opensrf:opensrf /home/opensrf
198
199 # 10. staff client stuff
200 apt-get install -y nsis unzip
201
202 # 11. integrity checker prereqs
203 apt-get install -y libconfig-simple-perl libgit-repository-perl libdate-manip-perl
204
205 # 12. paper overdue prereqs
206 apt-get install -y python-reportlab python-reportlab-accel