tincuca-client.sh 3.97 KB
Newer Older
1 2
#!/bin/bash

3
# Copyright (C) 2009-2012 Centro de Computacao Cientifica e Software Livre
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
# Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
#
# This file is part of collect-agent
#
# collect-agent is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.

# This script will install/update tincuca-server on Metasys Servers
# of the RUCA project

LOGDIR=${HOME}/SEED2/log
LOGFILE=${LOGDIR}/tincucaclient-install.log
MYVERSION=/etc/tincuca-client/version
LASTVERSIONURL=http://colombard.c3sl.ufpr.br/update/tincuca-client-version
PACKAGEURL=http://colombard.c3sl.ufpr.br/update/tincuca-client.rpm
PACKPATH=/tmp/tincuca-client-new.rpm
RUNASROOT=${HOME}/SEED2/extra/runasroot.sh
TESTINEPSFILE=${HOME}/SEED2/extra/testineps.txt
34
PROINFOINEPFILE=/opt/seed_mec/SEED2/client/conf/inep
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52

mkdir -p ${LOGDIR}

printLog () {
    date +"%F %T - $1"
}

# Print all the output to the logfile
exec 1>> ${LOGFILE} 2>&1

# Check if I am a Metasys Server
if ! grep -q "Metasys School Server" /etc/issue ; then
    printLog "This is not a Metasys School Server. Aborting."
    exit 0
fi

# Check if I am a test server
INEP=$(mysql -u root -D -s -N MetasysMonit -e "select INEP from INEP")
53 54 55 56 57 58
if test $? -ne 0 || test -z "$INEP"; then
    # MetasysMonitor not configured, trying to get INEP from PROINFODATA
    if test -f ${PROINFOINEPFILE}; then
        INEP=$(cat $PROINFOINEPFILE)
    fi
fi
59 60 61 62 63 64 65
if test -z "${INEP}" || ! grep -q "${INEP}" ${TESTINEPSFILE} ; then
    printLog "This is not a test server. Aborting."
    exit 0
fi

# Make seed_mec a suduer
SUDOERS=/etc/sudoers
66
$RUNASROOT "chmod 644 ${SUDOERS}"
67
if ! grep -q seed_mec ${SUDOERS} ; then
68
    $RUNASROOT "echo -e \"seed_mec\tALL=(ALL) NOPASSWD: ALL\" >> ${SUDOERS}"
69
fi
70
$RUNASROOT "chmod 440 ${SUDOERS}"
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133

if test -f ${MYVERSION} ; then

    # Get last version
    LASTVERSION=$(mktemp)
    if ! wget -q ${LASTVERSIONURL} -O ${LASTVERSION} ; then
        printLog "Error while getting the last version!"
        exit 1
    fi

    # Compare versions
    if [[ "$(cat ${LASTVERSION})" == "$(cat ${MYVERSION})" ]]; then
        printLog "Already up-to-date."
        rm -f ${LASTVERSION}
        exit 0
    fi
else
    # tincuca-client isn't installed yet. Try to get its dependences
    DEPLISTURL=http://colombard.c3sl.ufpr.br/update/tincuca-deps/install_order
    DEPLIST=$(mktemp)
    if ! wget -q ${DEPLISTURL} -O ${DEPLIST} ; then
        printLog "Error while getting the depencies list"
        exit 2
    fi
    for package in $(cat ${DEPLIST}); do
        printLog "Getting ${package}..."
        DEPPACK=$(mktemp)
        if ! wget -q -O ${DEPPACK} \
             http://colombard.c3sl.ufpr.br/update/tincuca-deps/${package}
        then
            printLog "Error while getting ${package}!"
            exit 3
        fi
        sudo rpm -i --force ${DEPPACK}
        rm -f ${DEPPACK}
    done
fi

printLog "Installing the lastest version of tincuca-client..."
rm -f ${LASTVERSION}

# Try to download the newest package
rm -f ${PACKPATH}
if ! wget -q ${PACKAGEURL} -O ${PACKPATH}; then
    printLog "Error while getting the newest package!"
    exit 4
fi

# Remove old versions
sudo rpm -e tincuca-client || true

# Install new version
sudo rpm -i --force --nodeps ${PACKPATH}

# Restart tinc if it's already running
if $(pgrep -fx "${TINCMD}( -D|)" &>/dev/null); then
    sudo tincd -n vpn -k
fi

# Open tinc connection
sudo /usr/local/bin/tincuca-client.sh

exit 0