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