2 DEFAULT_USER="sitkastaff"
3 HOMEDIR="/home/${DEFAULT_USER}"
4 BUILDDIR="${HOMEDIR}/opensrf"
5 INSTALLDIR="/srv/openils"
8 SITKACONF="${HOMEDIR}/sysadmin"
9 SITKACONF_BRANCH="eg210"
11 THISHOST=`hostname -s`
13 # test for ejabberd passwords
14 if [ -z "$PRIVATE_ROUTER_PASSWD" -o -z "$PRIVATE_OPENSRF_PASSWD" -o -z "$PUBLIC_ROUTER_PASSWD" -o -z "$PUBLIC_OPENSRF_PASSWD" ]
16 echo "Missing ejabberd password(s), no OpenSRF install!"
20 while getopts ":p" opt ; do
25 shift $(($OPTIND - 1))
27 if [[ -n "$PROD" ]] ; then
28 echo 'this is a production install'
30 echo 'this is NOT a production install'
33 usermod -a -G sudo ${DEFAULT_USER}
34 apt-get install git-core build-essential translate-toolkit python-polib bsdmainutils
37 if [ ! -d "${SITKACONF}" ]
39 # this will fail unless DEFAULT_USER has read access to the repo
40 su -c "cd ${HOMEDIR} && git clone git+ssh://git@git.sitka.bclibraries.ca/sitka-infra/sysadmin" ${DEFAULT_USER}
42 su -c "cd ${HOMEDIR}/sysadmin && git fetch origin && git checkout ${SITKACONF_BRANCH} && git pull" ${DEFAULT_USER}
43 if [ ! -d "${BUILDDIR}/.git" ] ; then
44 su -c "cd ${HOMEDIR} && git clone git://git.evergreen-ils.org/OpenSRF.git opensrf" ${DEFAULT_USER}
46 su -c "cd ${BUILDDIR} && git fetch origin && git checkout ${BRANCH} && git pull" ${DEFAULT_USER}
49 echo "need a placeholder apache2.conf, installing from config repo..."
50 if [ -f '/etc/apache2/apache2.conf' ]
52 mv /etc/apache2/apache2.conf /etc/apache2/apache2.conf.bak
54 cp ${SITKACONF}/files/etc/apache2/apache2.conf/${HOSTNAME} /etc/apache2/apache2.conf
55 sed -i "s|__HOSTNAME__|${THISHOST}|g" /etc/apache2/apache2.conf
58 echo "Installing OpenSRF prerequisites for Ubuntu..."
59 cd ${BUILDDIR} && make -f src/extras/Makefile.install ubuntu-trusty
62 echo "Configuring and building OpenSRF..."
63 su -c "cd ${BUILDDIR} && autoreconf -i" ${DEFAULT_USER}
64 su -c "cd ${BUILDDIR} && ./configure --prefix=${INSTALLDIR} --sysconfdir=${INSTALLDIR}/conf" ${DEFAULT_USER}
65 su -c "cd ${BUILDDIR} && make" ${DEFAULT_USER}
68 echo "Installing OpenSRF..."
69 cd ${BUILDDIR} && make install
70 useradd -m -s /bin/bash opensrf
71 PATHFILES="/etc/profile /root/.bashrc /home/${DEFAULT_USER}/.bashrc /home/opensrf/.bashrc"
72 for PATHFILE in ${PATHFILES} ; do
73 if [[ ! -e "${PATHFILE}" || ! `egrep "PATH=.*${INSTALLDIR}/bin" "${PATHFILE}"` ]] ; then
74 echo "export PATH=${INSTALLDIR}/bin:\$PATH" >> ${PATHFILE}
77 chown ${DEFAULT_USER}:${DEFAULT_USER} /home/${DEFAULT_USER}/.bashrc
78 #chown -R opensrf:opensrf ${INSTALLDIR}
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
83 if [[ ! -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
90 echo 'WARNING: If this is a new production server, you will need to manually update /etc/hosts!'
94 echo "ldconfig stuff..."
95 echo "${INSTALLDIR}/lib" > /etc/ld.so.conf.d/opensrf.conf
99 echo "Setting up ejabberd..."
100 cp ${SITKACONF}/files/etc/ejabberd/ejabberd.cfg/${HOSTNAME} /etc/ejabberd/ejabberd.cfg
101 sed -i "s|__HOSTNAME__|${THISHOST}|g" /etc/ejabberd/ejabberd.cfg
102 chgrp ejabberd /etc/ejabberd/ejabberd.cfg
103 chmod 640 /etc/ejabberd/ejabberd.cfg
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}
110 echo "OpenSRF is installed!"
112 # websockets install (REQUIRED for web client)
113 # XXX a valid SSL cert is required!
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
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
122 #/etc/init.d/apache2-websockets start
124 #echo "websockets is installed!"