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