X-Git-Url: http://ftp.carnet.hr/carnet-debian/scm?a=blobdiff_plain;f=functions.sh;h=520007eeed2477a1d85264711bbf2f4fe6af1ee5;hb=7034f689abd0368dc6eaa1440773d8f79d8fe98e;hp=2094e0a066e4007a0e2ace6a1840aa9bb82a58a3;hpb=f04eccdf6856210fdac3eaabf4f98134945e3060;p=carnet-tools-cn.git diff --git a/functions.sh b/functions.sh index 2094e0a..520007e 100644 --- a/functions.sh +++ b/functions.sh @@ -17,13 +17,13 @@ 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 + return 2 fi ifaddr="`/sbin/ifconfig $interface | awk '/inet/{ printf("%s\n",substr($2,index($2,":")+1)) }'`" if [ -z $ifaddr ]; then - echo "cp_get_ifaddr: $interface: No such ipaddress" 1>&2 + echo "cp_get_ifaddr: $interface: No ip address found" 1>&2 CP_ECHO_RETURN="$echo_return" return 1 fi @@ -58,7 +58,7 @@ cp_get_ifmask() { ifmask="`/sbin/ifconfig $interface | awk '/Mask/{if($3~/Mask/)a=$3;else if ($4~/Mask/)a=$4;printf ("%s\n", substr(a,index(a,":")+1))}'`" if [ -z "$ifmask" ]; then - echo "cp_get_ifmask: $interface: No such netmask" 1>&2 + echo "cp_get_ifmask: $interface: No netmask found" 1>&2 CP_ECHO_RETURN="$echo_return" return 1 fi @@ -114,14 +114,14 @@ cp_get_netaddr() { cp_get_ifaddr "$interface" ipaddress="$RET" if [ -z $ipaddress ]; then - echo "cp_get_netaddr: $interface: No such ipaddress" 1>&2 + echo "cp_get_netaddr: $interface: No IP address found" 1>&2 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 + echo "cp_get_netaddr: $interface: No netmask found" 1>&2 CP_ECHO_RETURN="$echo_return" return 1 fi @@ -137,12 +137,12 @@ cp_get_netaddr() { CP_ECHO_RETURN="$echo_return" } -# by ico, Tue, 15 Mar 2005 14:04:21 +0100 -cp_backup_conffile() { - cp_check_and_backup "$@" +cp_check_and_backup() { + cp_backup_conffile -r "$@" } -cp_check_and_backup() { +# by ico, Tue, 15 Mar 2005 14:04:21 +0100 +cp_backup_conffile() { [ "$CP_SCRIPT_DEBUG" ] && set -vx local file_bak check did @@ -155,7 +155,7 @@ cp_check_and_backup() { fi if [ ! -f "$1" ]; then echo "cp_backup_conffile: $1: No such file" 1>&2 - return 1 + return 2 fi if [ -z "$2" ]; then file_bak="/var/backups/`basename $1`.bak" @@ -182,6 +182,7 @@ cp_check_and_backup() { } # by jelly, Tue, 15 Mar 2005 14:04:21 +0100 +# modified by ico, Mon, 6 Jun 2005 11:58:08 +0200 # A sed wrapper, to use instead of perl -pi -e # - relatively safe in-place s///g # - takes care of symlinks and ownership @@ -189,7 +190,11 @@ cp_check_and_backup() { # cp_check_and_sed() { [ "$CP_SCRIPT_DEBUG" ] && set -vx - local s sedcmd ret i + local s sedcmd grepret ret i + if [ -z "$3" ]; then + echo "Usage: cp_check_and_sed [file ...]" 2>&1 + return 1 + fi s="$1" shift sedcmd="$1" @@ -198,9 +203,17 @@ cp_check_and_sed() { for i in "$@" do [ -e "$i" ] || continue - egrep -q "$s" "$i" || continue + if ! egrep -q "$s" "$i"; then + grepret=1 + continue + fi [ -h "$i" ] && i=$(readlink -f "$i") sed "$sedcmd" "$i" > "$i.dpkg-tmp" + if [ ! "$?" = "0" ]; then + rm "$i.dpkg-tmp" + echo "cp_check_and_sed: Problem with sed" 1>&2 + return 5 + fi if ! cmp -s "$i" "$i.dpkg-tmp" 2>&1 >/dev/null; then cp_mv "$i.dpkg-tmp" "$i" else @@ -208,6 +221,7 @@ cp_check_and_sed() { fi ret=0 done + [ "$ret" -eq 2 -a "$grepret"] && ret=1 || true return $ret } @@ -272,6 +286,7 @@ cp_mv () { fi mv "$new" "$old" } + # by ddzeko, Mon, 21 Mar 2005 13:35:42 +0100 cp_yes_no () { [ "$CP_SCRIPT_DEBUG" ] && set -vx @@ -349,7 +364,7 @@ cp_get_ldap_suffix() { if [ ! -f /etc/ldap/slapd.conf ]; then echo "cp_get_ldap_suffix: /etc/ldap/slapd.conf: No such file" >&2 - return 1 + return 2 fi RET="`awk '/^suffix/ { exit } @@ -379,7 +394,7 @@ cp_get_ldap_realm() { if [ ! -f /etc/ldap/slapd.conf ]; then echo "cp_get_ldap_realm: /etc/ldap/slapd.conf: No such file" >&2 - return 1 + return 2 fi cp_get_ldap_suffix || true @@ -389,3 +404,4 @@ cp_get_ldap_realm() { [ -z "$echo_return" ] || echo $RET CP_ECHO_RETURN="$echo_return" } +