# 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
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
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
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
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
*) 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
}
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
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
local file_bak
if [ -z "$1" ]; then
- echo "Usage: cp_backup_conffile <file>" 1>&2
return 1
fi
if [ ! -f "$1" ]; then
[ "$CP_SCRIPT_DEBUG" ] && set -vx
local new old
if [ -z "$2" ]; then
- echo "Usage: cp_safe_file_replace <new-file> <target-file>" 1>&2
return 1
fi
new="$1"