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