Further updates to install scripts for EG 2.4.0 and OpenSRF 2.2.0
[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-24"
5 DEFAULT_USER="sitkastaff"
6 HOMEDIR="/home/${DEFAULT_USER}"
7 BUILDDIR="${HOMEDIR}/evergreen"
8 INSTALLDIR="/srv/openils"
9 BRANCH="user/jeffdavis/sitka-24-beta1"
10 VERSION="2.4.0.sitka.0"
11 STAMP_ID="2_4_0_sitka_0"
12 ALT_STAMP_IDS="rel_2_4_0_sitka_0 2_4_0_sitka_0 rel_2_4_0_sitka_0"
13 SITKACONF="${HOMEDIR}/sysadmin"
14 DEPLOYDIR="/home/opensrf/deploy"
15 OPACSKIN="${DEPLOYDIR}/opacskin"
16 OILSPOLICY="${DEPLOYDIR}/oilspolicy"
17 TPACS="${DEPLOYDIR}/deploykit"
18
19 suwrap() {
20   su -s /bin/bash -l -c "source ~/.bashrc ; $1" $2
21 }
22
23 # as DEFAULT_USER
24
25 # grab Sitka config files
26 if [ ! -d "${SITKACONF}" ]
27 then
28   # this will fail unless DEFAULT_USER has read access to the repo
29   suwrap "cd ${HOMEDIR} && git clone git+ssh://git@git.sitka.bclibraries.ca/sitka-infra/sysadmin" ${DEFAULT_USER}
30 fi
31 suwrap "cd ${SITKACONF} && git pull" ${DEFAULT_USER}
32
33 # checkout EG source
34 if [ ! -d "${BUILDDIR}" ]
35 then
36   suwrap "cd ${HOMEDIR} && git clone git://git.sitka.bclibraries.ca/sitka/evergreen evergreen" ${DEFAULT_USER}
37 fi
38 suwrap "cd ${BUILDDIR} && git checkout ${BRANCH}" ${DEFAULT_USER}
39  
40 # as root
41 cd ${BUILDDIR} && make -f Open-ILS/src/extras/Makefile.install ubuntu-precise
42 # by default, CPAN needs some manual input at this point; you can just accept all defaults
43  
44 # as DEFAULT_USER
45 suwrap "cd ${BUILDDIR} && autoreconf -i" ${DEFAULT_USER}
46 suwrap "cd ${BUILDDIR} && ./configure -C --prefix=${INSTALLDIR} --sysconfdir=${INSTALLDIR}/conf --with-opensrf-headers=${INSTALLDIR}/include/ --with-opensrf-libs=${INSTALLDIR}/lib/ --with-dbi=/usr/lib/dbd/" ${DEFAULT_USER}
47 suwrap "cd ${BUILDDIR} && make" ${DEFAULT_USER}
48 suwrap "cd ${BUILDDIR}/build/i18n && make install_all_locales" ${DEFAULT_USER}
49  
50 # as root
51 cd ${BUILDDIR} && make STAFF_CLIENT_STAMP_ID=${STAMP_ID} STAFF_CLIENT_VERSION=${VERSION} install
52 chown -R opensrf:opensrf ${INSTALLDIR}
53  
54 # Apache stuff (as root):
55 APACHEFILES="/etc/apache2/eg_vhost.conf /etc/apache2/eg_startup /etc/apache2/sites-available/eg.conf"
56 for APACHEFILE in ${APACHEFILES}
57 do
58   cp ${SITKACONF}/files/${APACHEFILE}/${HOSTNAME} ${APACHEFILE}
59 done
60 a2dissite default
61 a2ensite eg.conf
62 mkdir /etc/apache2/ssl
63 cd /etc/apache2/ssl && openssl req -new -x509 -days 365 -nodes -out server.crt -keyout server.key
64  
65 # TODO: set up log rotation
66  
67 # as opensrf
68  
69 # 0. osrf conf stuff 
70 # FIXME: ensure osrf conf files point at a real, distinct db!
71 OSRFCONFFILES="${INSTALLDIR}/conf/opensrf.xml ${INSTALLDIR}/conf/opensrf_core.xml"
72 for OSRFCONFFILE in ${OSRFCONFFILES}
73 do
74   rm ${OSRFCONFFILE}
75   cp ${SITKACONF}/files/${OSRFCONFFILE}/${HOSTNAME} ${OSRFCONFFILE}
76 done
77 cp ${SITKACONF}/files/home/opensrf/.srfsh.xml/${HOSTNAME} ${HOMEDIR}/.srfsh.xml
78  
79 # 1. install dojo
80 cd /home/opensrf && wget http://download.dojotoolkit.org/release-1.3.3/dojo-release-1.3.3.tar.gz
81 tar -C ${INSTALLDIR}/var/web/js -xzf /home/opensrf/dojo-release-1.3.3.tar.gz
82 cp -r ${INSTALLDIR}/var/web/js/dojo-release-1.3.3/* ${INSTALLDIR}/var/web/js/dojo/.
83  
84 # 2. set up staff client
85 cd ${INSTALLDIR}/var/web/xul && ln -s ${STAMP_ID} current && ln -s current/server server
86 for ALT_STAMP_ID in ${ALT_STAMP_IDS}
87 do
88   cd ${INSTALLDIR}/var/web/xul && ln -s current ${ALT_STAMP_ID}
89 done
90  
91 # 3. install circ scripts and opac skins
92
93 # (a) setup deploy directory
94 if [ ! -d "${DEPLOYDIR}" ]
95 then
96   mkdir ${DEPLOYDIR}
97 fi
98
99 # (b) bclibraries skin
100 if [ ! -d "${OPACSKIN}" ]
101 then
102   cd ${DEPLOYDIR} && git clone git://git.sitka.bclibraries.ca/sitka/opacskin.git
103 fi
104 cd ${OPACSKIN} && git checkout -b bclibraries && \
105   cd ${INSTALLDIR}/var/web/opac/skin && mv default orig-default && \
106   rsync -a --exclude=.git ${OPACSKIN} ${INSTALLDIR}/var/web/opac/skin/bclibraries && \
107   ln -s ${INSTALLDIR}/var/web/opac/skin/bclibraries ${INSTALLDIR}/var/web/opac/skin/default
108
109 # (c) TPAC stuff
110 apt-get install rake erubis ruby-git
111 if [ ! -d "${TPACS}" ]; then
112   cd ${DEPLOYDIR} && git clone git://git.sitka.bclibraries.ca/sitka/deploykit.git
113 fi
114 cd ${TPACS} && git pull
115 cd ${TPACS}/deploykit && mv config.yml.sample config.yml
116 if [ ! -d "/etc/apache2/includes" ]; then
117   mkdir /etc/apache2/includes
118 fi
119 if [ ! -d "/srv/openils/var/skins" ]; then
120   mkdir /srv/openils/var/skins
121 fi
122 # TODO: use rake to build AND deploy properly!
123 #cd ${TPACS}/deploykit && rake tpac:all && \
124 #  for TPACSKIN in `ls -1 ${TPACS}/deploykit/build`; do mkdir -p /srv/openils/var/skins/${TPACSKIN}/opac && \
125 #    cp -r build/${TPACSKIN}/templates/opac/* /srv/openils/var/skins/${TPACSKIN}/opac/ && \
126 #    cp ${TPACS}/build/${TPACSKIN}/apache2/${TPACSKIN}.conf /etc/apache2/sites-available/ && \
127 #    cp ${TPACS}/build/${TPACSKIN}/apache2/${TPACSKIN}.conf-include /etc/apache2/includes/ ; done
128
129 # (d) circ scripts
130 if [ ! -d "${OILSPOLICY}" ]
131 then
132   cd ${DEPLOYDIR} && git clone git://git.sitka.bclibraries.ca/sitka/oilspolicy.git
133 fi
134 cd ${OILSPOLICY} && git pull && rsync -a --exclude=.git ${OILSPOLICY} ${INSTALLDIR}/var
135  
136 # 4. avoid 404s
137 touch ${INSTALLDIR}/var/web/css/skin/default/register_custom.css
138 touch ${INSTALLDIR}/var/web/xul/server/locale/en-CA/patron_custom.properties
139 touch ${INSTALLDIR}/var/web/xul/server/locale/en-CA/common_custom.properties
140 touch ${INSTALLDIR}/var/web/xul/server/locale/en-CA/offline_custom.properties
141 touch ${INSTALLDIR}/var/web/xul/server/locale/en-CA/auth_custom.properties
142 touch ${INSTALLDIR}/var/web/xul/server/locale/en-CA/cat_custom.properties
143 touch ${INSTALLDIR}/var/web/xul/server/locale/en-CA/circ_custom.properties
144 touch ${INSTALLDIR}/var/web/xul/server/locale/en-US/patron_custom.properties
145 touch ${INSTALLDIR}/var/web/xul/server/locale/en-US/common_custom.properties
146 touch ${INSTALLDIR}/var/web/xul/server/locale/en-US/offline_custom.properties
147 touch ${INSTALLDIR}/var/web/xul/server/locale/en-US/auth_custom.properties
148 touch ${INSTALLDIR}/var/web/xul/server/locale/en-US/cat_custom.properties
149 touch ${INSTALLDIR}/var/web/xul/server/locale/en-US/circ_custom.properties
150 touch ${INSTALLDIR}/var/web/xul/server/skin/custom.js
151
152 # 5. locale hack
153 cd ${INSTALLDIR}/var/web/opac/locale && cp -fdr en-US en-US-bak && cp -fdr en-CA en-US
154  
155 # 6. deletepatron
156 # ensure apache conf contains deletepatron config (location should be ${INSTALLDIR}/var/web/deletepatron)
157 cd ${INSTALLDIR}/var/web && git clone https://github.com/twirlip/deletepatron.git
158 cd ${INSTALLDIR}/var/web/deletepatron && git checkout eg22 && find . -name *.pm | xargs sed -i -e 's|/openils|/srv/openils|g'
159 apt-get install libcgi-session-perl libhtml-template-perl
160
161 # 7. support scripts
162 cp ${BUILDDIR}/Open-ILS/src/support-scripts/generate_circ_notices.pl ${INSTALLDIR}/bin
163 cp ${BUILDDIR}/Open-ILS/src/support-scripts/oils_header.pl ${INSTALLDIR}/bin
164
165 # 8. setup start page
166 if [ ! -d "${INSTALLDIR}/var/web/news" ]
167 then
168   mkdir ${INSTALLDIR}/var/web/news
169 fi
170 NEWSFILES="index.html style.css"
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
179 # 9. make sure opensrf owns all the stuff we just did
180 chown -R opensrf:opensrf ${INSTALLDIR}
181 chown -R opensrf:opensrf /home/opensrf
182 chown -R opensrf:opensrf /var/lock/apache2
183
184 # 10. staff client stuff
185 apt-get install nsis unzip