From 4750707795d8a2c3a518b3f14414cd4a3c05aa70 Mon Sep 17 00:00:00 2001 From: Ivan Rako Date: Tue, 22 Mar 2005 14:31:48 +0000 Subject: [PATCH] r21: --- functions.sh | 46 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/functions.sh b/functions.sh index 5bb7ae6..2f91b82 100644 --- a/functions.sh +++ b/functions.sh @@ -1,7 +1,11 @@ # by ddzeko & ico, Fri, 18 Mar 2005 14:44:08 +0100 cp_get_ifaddr() { [ "$CP_SCRIPT_DEBUG" ] && set -vx - local ifaddr interface + local ifaddr interface echo_return + echo_return="$CP_ECHO_RETURN" # since we're making our own calls + # in our own way we need to set CP_ECHO_RETURN the way we want it + # but preserving initial state so it could be used afterwards + CP_ECHO_RETURN="" interface="$1" if [ -z "$interface" ]; then @@ -12,6 +16,7 @@ cp_get_ifaddr() { if ! ifconfig $interface 2> /dev/null >> /dev/null; then echo "cp_get_ifaddr: $interface: No such interface" 1>&2 + CP_ECHO_RETURN="$echo_return" return 1 fi @@ -19,17 +24,23 @@ cp_get_ifaddr() { if [ -z $ifaddr ]; then echo "cp_get_ifaddr: $interface: No such ipaddress" 1>&2 + CP_ECHO_RETURN="$echo_return" return 1 fi RET="$ifaddr" - [ -z "$CP_ECHO_RETURN" ] || echo $RET + [ -z "$echo_return" ] || echo $RET + CP_ECHO_RETURN="$echo_return" } # by ddzeko & ico, Fri, 18 Mar 2005 14:44:08 +0100 cp_get_ifmask() { [ "$CP_SCRIPT_DEBUG" ] && set -vx - local ifmask interface + local ifmask interface echo_return + echo_return="$CP_ECHO_RETURN" # since we're making our own calls + # in our own way we need to set CP_ECHO_RETURN the way we want it + # but preserving initial state so it could be used afterwards + CP_ECHO_RETURN="" interface="$1" if [ -z "$interface" ]; then @@ -40,6 +51,7 @@ cp_get_ifmask() { if ! ifconfig $interface 2> /dev/null >> /dev/null; then echo "cp_get_ifmask: $interface: No such interface" 1>&2 + CP_ECHO_RETURN="$echo_return" return 1 fi @@ -47,15 +59,23 @@ cp_get_ifmask() { if [ -z "$ifmask" ]; then echo "cp_get_ifmask: $interface: No such netmask" 1>&2 + CP_ECHO_RETURN="$echo_return" return 1 fi RET="$ifmask" - [ -z "$CP_ECHO_RETURN" ] || echo $RET + [ -z "$echo_return" ] || echo $RET + CP_ECHO_RETURN="$echo_return" } # by ddzeko, Mon, 21 Mar 2005 07:00:22 +0100 cp_get_ifdefault() { + local echo_return + echo_return="$CP_ECHO_RETURN" # since we're making our own calls + # in our own way we need to set CP_ECHO_RETURN the way we want it + # but preserving initial state so it could be used afterwards + CP_ECHO_RETURN="" + [ "$CP_SCRIPT_DEBUG" ] && set -vx RET="" case $1 in @@ -64,7 +84,8 @@ cp_get_ifdefault() { *) echo "cp_get_ifdefault: Argument required (dev or addr)" >&2 ;; esac [ -z "$RET" -a "$1" -a "$CP_VERBOSE" ] && echo "cp_get_ifdefault: No default route" >&2 - [ -z "$CP_ECHO_RETURN" ] || echo $RET + [ -z "$echo_return" ] || echo $RET + CP_ECHO_RETURN="$echo_return" [ -z "$RET" ] && return 1 } @@ -86,19 +107,23 @@ cp_get_netaddr() { if ! ifconfig $interface 2> /dev/null >> /dev/null; then echo "cp_get_netaddr: $interface: No such interface" 1>&2 - goto return1 + CP_ECHO_RETURN="$echo_return" + return 1 fi cp_get_ifaddr "$interface" ipaddress="$RET" if [ -z $ipaddress ]; then echo "cp_get_netaddr: $interface: No such ipaddress" 1>&2 - goto return1 + CP_ECHO_RETURN="$echo_return" + return 1 fi cp_get_ifmask "$interface" netmask="$RET" if [ -z $netmask ]; then echo "cp_get_netaddr: $interface: No such netmask" 1>&2 + CP_ECHO_RETURN="$echo_return" + return 1 fi if [ "$netmask" = "255.255.255.255" ]; then @@ -110,11 +135,6 @@ cp_get_netaddr() { RET="$cidr" [ -z "$echo_return" ] || echo $RET CP_ECHO_RETURN="$echo_return" - return 0 - - return1: - CP_ECHO_RETURN="$echo_return" - return 1 } # by ico, Tue, 15 Mar 2005 14:04:21 +0100 @@ -123,7 +143,6 @@ cp_backup_conffile() { local file_bak if [ -z "$1" ]; then - echo "Usage: cp_backup_conffile " 1>&2 return 1 fi if [ ! -f "$1" ]; then @@ -224,7 +243,6 @@ cp_safe_file_replace () { [ "$CP_SCRIPT_DEBUG" ] && set -vx local new old if [ -z "$2" ]; then - echo "Usage: cp_safe_file_replace " 1>&2 return 1 fi new="$1" -- 1.7.10.4