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