install-osrf.sh: ensure EG bin path is in $PATH for default user
[sitka/sitka-tools.git] / deployment / install-osrf.sh
... / ...
CommitLineData
1#!/bin/bash
2DEFAULT_USER="sitkastaff"
3HOMEDIR="/home/${DEFAULT_USER}"
4BUILDDIR="${HOMEDIR}/opensrf"
5INSTALLDIR="/srv/openils"
6BRANCH="rel_2_4"
7HOSTNAME="nonprod-28"
8SITKACONF="${HOMEDIR}/sysadmin"
9SITKACONF_BRANCH="eg28"
10
11# test for ejabberd passwords
12if [ -z "$PRIVATE_ROUTER_PASSWD" -o -z "$PRIVATE_OPENSRF_PASSWD" -o -z "$PUBLIC_ROUTER_PASSWD" -o -z "$PUBLIC_OPENSRF_PASSWD" ]
13then
14 echo "Missing ejabberd password(s), no OpenSRF install!"
15 exit
16fi
17
18# as root
19usermod -a -G sudo ${DEFAULT_USER}
20apt-get install git-core build-essential translate-toolkit python-polib bsdmainutils
21
22# as DEFAULT_USER
23if [ ! -d "${SITKACONF}" ]
24then
25 # this will fail unless DEFAULT_USER has read access to the repo
26 su -c "cd ${HOMEDIR} && git clone git+ssh://git@git.sitka.bclibraries.ca/sitka-infra/sysadmin" ${DEFAULT_USER}
27fi
28su -c "cd ${HOMEDIR}/sysadmin && git fetch origin && git checkout ${SITKACONF_BRANCH} && git pull" ${DEFAULT_USER}
29if [ ! -d "${BUILDDIR}/.git" ] ; then
30 su -c "cd ${HOMEDIR} && git clone git://git.evergreen-ils.org/OpenSRF.git opensrf" ${DEFAULT_USER}
31fi
32su -c "cd ${BUILDDIR} && git fetch origin && git checkout ${BRANCH} && git pull" ${DEFAULT_USER}
33
34# as root
35echo "need a placeholder apache2.conf, installing from config repo..."
36if [ -f '/etc/apache2/apache2.conf' ]
37then
38 mv /etc/apache2/apache2.conf /etc/apache2/apache2.conf.bak
39fi
40cp ${SITKACONF}/files/etc/apache2/apache2.conf/${HOSTNAME} /etc/apache2/apache2.conf
41
42# as root
43echo "Installing OpenSRF prerequisites for Ubuntu..."
44cd ${BUILDDIR} && make -f src/extras/Makefile.install ubuntu-trusty
45
46# as DEFAULT_USER
47echo "Configuring and building OpenSRF..."
48su -c "cd ${BUILDDIR} && autoreconf -i" ${DEFAULT_USER}
49su -c "cd ${BUILDDIR} && ./configure --prefix=${INSTALLDIR} --sysconfdir=${INSTALLDIR}/conf" ${DEFAULT_USER}
50su -c "cd ${BUILDDIR} && make" ${DEFAULT_USER}
51
52# as root
53echo "Installing OpenSRF..."
54cd ${BUILDDIR} && make install
55useradd -m -s /bin/bash opensrf
56PATHFILES="/etc/profile /root/.bashrc /home/${DEFAULT_USER}/.bashrc /home/opensrf/.bashrc"
57for PATHFILE in ${PATHFILES} ; do
58 if [[ -e "${PATHFILE}" && ! `egrep "PATH=.*${INSTALLDIR}/bin" "${PATHFILE}"` ]] ; then
59 echo "export PATH=${INSTALLDIR}/bin:\$PATH" >> ${PATHFILE}
60 fi
61done
62chown -R opensrf:opensrf ${INSTALLDIR}
63
64# as root, add the following two lines to /etc/hosts:
65#127.0.1.2 public.localhost public
66#127.0.1.3 private.localhost private
67echo "Updating /etc/hosts..."
68echo -e "127.0.1.2\tpublic.localhost\tpublic\n127.0.1.3\tprivate.localhost\tprivate\n" | \
69 cat - /etc/hosts > /etc/hosts.new && mv /etc/hosts.new /etc/hosts
70
71# as root
72echo "ldconfig stuff..."
73echo "${INSTALLDIR}/lib" > /etc/ld.so.conf.d/opensrf.conf
74ldconfig
75
76# as root
77echo "Setting up ejabberd..."
78cp ${SITKACONF}/files/etc/ejabberd/ejabberd.cfg/${HOSTNAME} /etc/ejabberd/ejabberd.cfg
79chgrp ejabberd /etc/ejabberd/ejabberd.cfg
80chmod 640 /etc/ejabberd/ejabberd.cfg
81/etc/init.d/ejabberd restart && sleep 10 && \
82 ejabberdctl register router private.localhost ${PRIVATE_ROUTER_PASSWD} && \
83 ejabberdctl register opensrf private.localhost ${PRIVATE_OPENSRF_PASSWD} && \
84 ejabberdctl register router public.localhost ${PUBLIC_ROUTER_PASSWD} && \
85 ejabberdctl register opensrf public.localhost ${PUBLIC_OPENSRF_PASSWD}
86
87echo "OpenSRF is installed!"
88
89# websockets install (REQUIRED for web client)
90# XXX a valid SSL cert is required!
91#rm -r /tmp/apache-websocket
92#cd /tmp && git clone https://github.com/disconnect/apache-websocket
93#cd apache-websocket && apxs2 -i -a -c mod_websocket.c
94#sh /usr/share/doc/apache2/examples/setup-instance websockets
95#a2dismod websocket
96#cp ${SITKACONF}/files/etc/apache2-websockets/apache2.conf/${HOSTNAME} /etc/apache2-websockets/apache2.conf
97#cp ${SITKACONF}/files/etc/apache2-websockets/envvars/${HOSTNAME} /etc/apache2-websockets/envvars
98
99#/etc/init.d/apache2-websockets start
100
101echo "websockets is installed!"
102