Skip to content
Snippets Groups Projects
Select Git revision
  • master default
  • build-env
  • bz2
  • portal
  • db-rlp09
  • proinfo_rlp09
  • v1.4.0
  • v1.3.13-buildpackage
  • v1.3.13-client
  • v1.3.12-buildpackage
  • v1.3.12-collect
  • v1.3.13-collect
  • v1.3.11-collect
  • v1.3.10-collect
  • v1.3.11-buildpackage
  • v1.3.10-client
  • v1.3.11-client
  • v1.3.12-client
  • v1.3.10-buildpackage
  • v1.2.0-buildpackage
  • v1.2.0-collect
  • v1.2.0-client
  • v1.1.1-buildpackage
  • v1.1.1-client
  • v1.1.1-collect
  • v1.1.0-client
26 results

common.sh

Blame
  • common.sh 3.70 KiB
    #!/bin/bash
    # Copyright (C) 2004-2009 Centro de Computacao Cientifica e Software Livre
    # Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
    #
    # This file is part of client, it is used to store common functions
    #
    # common.sh 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.
    
    
    #------------------------------------------------------------------------------
    # Function: getProxyConf
    # Load the proxy configuration.
    function getProxyConf()
    {
        # Use collect variable, if defined. Otherwise use the client one
        if ! test -z "${PREFIX}"; then
            PROXYCONF="${PREFIX}/client/conf/proxy"
        else
            PROXYCONF="${dirname}/conf/proxy"
        fi
    
        # Obtain proxy configuration by reading the proxy file
        phost=$(grep "^phost=" ${PROXYCONF} 2> /dev/null | cut -f2 -d=)
        pport=$(grep "^pport=" ${PROXYCONF} 2> /dev/null | cut -f2 -d=)
        puid=$(grep "^puid=" ${PROXYCONF} 2> /dev/null | cut -f2 -d=)
        ppasswd=$(grep "^ppasswd=" ${PROXYCONF} 2> /dev/null | cut -f2 -d=)
    
        # If there is any proxy information, add a message to log
        if test -n "${phost}${pport}${puid}${ppasswd}"; then
            printf "Proxy configuration being used.\n" >> ${log}
            # If there is a valued system proxy variable, print a warning to log
            if test -n "${http_proxy}"; then
                printf "WARNING: The proxy file is " >> ${log}
                printf "empty but http_proxy isn't.\n" >> ${log}
            fi
        fi
    }
    
    function tryWget(){
        getProxyConf
        if test -z "$phost"; then
            PROXY=""
        else
            PROXY="http://${phost}:${pport}"
        fi
    
        PROXYPASSWD="--proxy-password"
        if which wget &> /dev/null; then
            WGETBIN="$(which wget)"
            WGETVERSION="$(${WGETBIN} --version | head -n1 | cut -d' ' -f3)"
            WGETVER1="$(echo ${WGETVERSION} | cut -d'.' -f1)"
            WGETVER2="$(echo ${WGETVERSION} | cut -d'.' -f2)"
            # If the system wget(1) is older than the 1.10 version, use
            # the option "--proxy-passwd" to pass the proxy password to wget(1)
            if test ${WGETVER1} -lt 1 -o ${WGETVER1} -eq 1 -a ${WGETVER2} -lt 10
            then
                PROXYPASSWD="--proxy-passwd"
            fi
        else
            WGETBIN="${PREFIX}/bin/wget"
        fi
    
        http_proxy="${PROXY}" ${WGETBIN} --tries=${UPDATETRIES} \
                                         --timeout=${UPDATETIMEOUT} \
                                         --proxy-user="${puid}" \
                                         ${PROXYPASSWD}="${ppasswd}" \
                                         $* || return 1
    }
    
    #------------------------------------------------------------------------------
    # Function: getNetworkInterface
    # Get the network interface which the client must bind to (in case there is
    # more than one default route) and the collect will use to obtain the MAC
    # address.
    function getNetworkInterface()
    {
        for interface in $(/sbin/route | grep default | awk '{print $NF}'); do
            # Send ICMP ECHO_REQUEST to root server I or J
            if ping -c 1 -I ${interface} 192.36.148.17 &> /dev/null ||
               ping -c 1 -I ${interface} 192.58.128.30 &> /dev/null ; then
                break
            fi
        done
    }