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