install-osrf.sh: fix bug in Apache websockets setup
[sitka/sitka-tools.git] / deployment / install-osrf.sh
CommitLineData
0155bbac 1#!/bin/bash
8da49eaf 2DEFAULT_USER="opensrf"
0155bbac 3HOMEDIR="/home/${DEFAULT_USER}"
0f2c1897
JD
4BUILDDIR="${HOMEDIR}/opensrf"
5INSTALLDIR="/srv/openils"
8da49eaf 6BRANCH="rel_3_0"
79b2efa0 7HOSTNAME="nonprod"
0155bbac 8SITKACONF="${HOMEDIR}/sysadmin"
a42f2670 9SITKACONF_BRANCH="master"
0155bbac 10
a826c73b
JD
11THISHOST=`hostname -s`
12
913bfe44 13while getopts ":pwj" opt ; do
e3bcc9bb
JD
14 case $opt in
15 p ) PROD="prod";;
6298f1c5 16 w ) WEBSOCKETS="websockets";;
913bfe44 17 j ) SKIP_EJABBERD_REG="skip_ejabberd_reg";;
e3bcc9bb
JD
18 esac
19done
20shift $(($OPTIND - 1))
21
913bfe44 22# test for ejabberd passwords
23if [ -z "$PRIVATE_ROUTER_PASSWD" -o -z "$PRIVATE_OPENSRF_PASSWD" -o -z "$PUBLIC_ROUTER_PASSWD" -o -z "$PUBLIC_OPENSRF_PASSWD" ]
24then
25 if [[ ! -n "$SKIP_EJABBERD_REG" ]] ; then
26 echo "Missing ejabberd password(s), no OpenSRF install!"
27 exit
28 fi
29fi
30
7b2b5e72
JD
31# always use a proxy for websockets traffic
32if [[ -n "$WEBSOCKETS" ]] ; then
33 WSPORT="--with-websockets-port=443"
34else
35 WSPORT=""
36fi
37
e3bcc9bb
JD
38if [[ -n "$PROD" ]] ; then
39 echo 'this is a production install'
34f86bbc 40 [ "$HOSTNAME" == "nonprod" ] && HOSTNAME="prod"
e3bcc9bb
JD
41else
42 echo 'this is NOT a production install'
43fi
0155bbac
JD
44# as root
45usermod -a -G sudo ${DEFAULT_USER}
46apt-get install git-core build-essential translate-toolkit python-polib bsdmainutils
47
48# as DEFAULT_USER
49if [ ! -d "${SITKACONF}" ]
50then
51 # this will fail unless DEFAULT_USER has read access to the repo
e2ad4781 52 su -c "cd ${HOMEDIR} && git clone git+ssh://git@git.sitka.bclibraries.ca/sitka-infra/sysadmin" ${DEFAULT_USER}
0155bbac 53fi
e2ad4781 54su -c "cd ${HOMEDIR}/sysadmin && git fetch origin && git checkout ${SITKACONF_BRANCH} && git pull" ${DEFAULT_USER}
0f2c1897 55if [ ! -d "${BUILDDIR}/.git" ] ; then
e2ad4781 56 su -c "cd ${HOMEDIR} && git clone git://git.evergreen-ils.org/OpenSRF.git opensrf" ${DEFAULT_USER}
e724d7db 57fi
e2ad4781 58su -c "cd ${BUILDDIR} && git fetch origin && git checkout ${BRANCH} && git pull" ${DEFAULT_USER}
0155bbac
JD
59
60# as root
15e3aada
JD
61echo "need a placeholder apache2.conf, installing from config repo..."
62if [ -f '/etc/apache2/apache2.conf' ]
63then
64 mv /etc/apache2/apache2.conf /etc/apache2/apache2.conf.bak
65fi
66cp ${SITKACONF}/files/etc/apache2/apache2.conf/${HOSTNAME} /etc/apache2/apache2.conf
e6bc584b 67sed -i "s|__HOSTNAME__|${THISHOST}|g" /etc/apache2/apache2.conf
15e3aada
JD
68
69# as root
0155bbac 70echo "Installing OpenSRF prerequisites for Ubuntu..."
61bfabc2 71cd ${BUILDDIR} && make -f src/extras/Makefile.install ubuntu-trusty
0155bbac
JD
72
73# as DEFAULT_USER
74echo "Configuring and building OpenSRF..."
e2ad4781 75su -c "cd ${BUILDDIR} && autoreconf -i" ${DEFAULT_USER}
7b2b5e72 76su -c "cd ${BUILDDIR} && ./configure --prefix=${INSTALLDIR} --sysconfdir=${INSTALLDIR}/conf ${WSPORT}" ${DEFAULT_USER}
e2ad4781 77su -c "cd ${BUILDDIR} && make" ${DEFAULT_USER}
0155bbac
JD
78
79# as root
80echo "Installing OpenSRF..."
0f2c1897 81cd ${BUILDDIR} && make install
0155bbac 82useradd -m -s /bin/bash opensrf
f5c7692c 83PATHFILES="/etc/profile /root/.bashrc /home/${DEFAULT_USER}/.bashrc /home/opensrf/.bashrc"
21e6d31c 84for PATHFILE in ${PATHFILES} ; do
1cbdd07d 85 if [[ ! -e "${PATHFILE}" || ! `egrep "PATH=.*${INSTALLDIR}/bin" "${PATHFILE}"` ]] ; then
21e6d31c
JD
86 echo "export PATH=${INSTALLDIR}/bin:\$PATH" >> ${PATHFILE}
87 fi
88done
6e29c057 89chown ${DEFAULT_USER}:${DEFAULT_USER} /home/${DEFAULT_USER}/.bashrc
ad42e546
JD
90if [[ ! -n "$PROD" ]] ; then
91 chown -R opensrf:opensrf ${INSTALLDIR}
92fi
0155bbac
JD
93
94# as root, add the following two lines to /etc/hosts:
95#127.0.1.2 public.localhost public
96#127.0.1.3 private.localhost private
f2df3033
JD
97if [[ ! -n "$PROD" ]] ; then
98 if [[ ! `grep public.localhost /etc/hosts` ]] ; then
99 echo "Updating /etc/hosts..."
100 echo -e "127.0.1.2\tpublic.localhost\tpublic\n127.0.1.3\tprivate.localhost\tprivate\n" | \
101 cat - /etc/hosts > /etc/hosts.new && mv /etc/hosts.new /etc/hosts
102 fi
103else
104 echo 'WARNING: If this is a new production server, you will need to manually update /etc/hosts!'
105fi
0155bbac
JD
106
107# as root
108echo "ldconfig stuff..."
109echo "${INSTALLDIR}/lib" > /etc/ld.so.conf.d/opensrf.conf
110ldconfig
111
112# as root
113echo "Setting up ejabberd..."
e83deee7 114cp ${SITKACONF}/files/etc/ejabberd/ejabberd.cfg/${HOSTNAME} /etc/ejabberd/ejabberd.cfg
ebdf29b9 115sed -i "s|__HOSTNAME__|${THISHOST}|g" /etc/ejabberd/ejabberd.cfg
0155bbac
JD
116chgrp ejabberd /etc/ejabberd/ejabberd.cfg
117chmod 640 /etc/ejabberd/ejabberd.cfg
913bfe44 118/etc/init.d/ejabberd stop && /etc/init.d/ejabberd start
119if [[ ! -n "$SKIP_EJABBERD_REG" ]] ; then
120 sleep 5
e83deee7
JD
121 ejabberdctl register router private.localhost ${PRIVATE_ROUTER_PASSWD} && \
122 ejabberdctl register opensrf private.localhost ${PRIVATE_OPENSRF_PASSWD} && \
123 ejabberdctl register router public.localhost ${PUBLIC_ROUTER_PASSWD} && \
124 ejabberdctl register opensrf public.localhost ${PUBLIC_OPENSRF_PASSWD}
913bfe44 125fi
0155bbac
JD
126
127echo "OpenSRF is installed!"
61bfabc2
JD
128
129# websockets install (REQUIRED for web client)
130# XXX a valid SSL cert is required!
6298f1c5
JD
131if [[ -n "$WEBSOCKETS" ]] ; then
132 rm -r /tmp/apache-websocket
133 cd /tmp && git clone https://github.com/disconnect/apache-websocket
134 cd apache-websocket && apxs2 -i -a -c mod_websocket.c
135 sh /usr/share/doc/apache2/examples/setup-instance websockets
136 a2dismod websocket
137 cp ${SITKACONF}/files/etc/apache2-websockets/apache2.conf/${HOSTNAME} /etc/apache2-websockets/apache2.conf
a6b7e5e9 138 sed -i "s|__THISHOST__|${THISHOST}|g" /etc/apache2-websockets/apache2.conf
6298f1c5 139 cp ${SITKACONF}/files/etc/apache2-websockets/envvars/${HOSTNAME} /etc/apache2-websockets/envvars
61bfabc2 140
6298f1c5 141 #/etc/init.d/apache2-websockets start
61bfabc2 142
6298f1c5
JD
143 #echo "websockets is installed!"
144fi