diff options
author | Natanael Copa <ncopa@alpinelinux.org> | 2010-08-16 14:36:40 +0000 |
---|---|---|
committer | Natanael Copa <ncopa@alpinelinux.org> | 2010-08-16 14:36:40 +0000 |
commit | 39cf5d784a583be27d0b383257d1676f7a3824f3 (patch) | |
tree | fbb7941e1bb7a178b20abc763932287c8fd67ac8 | |
parent | 326f0bacf85f595f1d23b44ea7da81f15f395d3b (diff) | |
download | alpine-conf-39cf5d784a583be27d0b383257d1676f7a3824f3.zip |
setup-interfaces: fix for bb 1.17.1. accept /mask together with address
And print summary of the interface configuration
-rwxr-xr-x | libalpine.sh.in | 6 | ||||
-rwxr-xr-x | setup-interfaces.in | 25 |
2 files changed, 21 insertions, 10 deletions
diff --git a/libalpine.sh.in b/libalpine.sh.in index 3a25302..36d2a93 100755 --- a/libalpine.sh.in +++ b/libalpine.sh.in @@ -67,12 +67,6 @@ default_read() { } -invalid_ip() { - [ "$1" ] || return 0 - ! ipcalc -s -m $1/0 > /dev/null -} - - cfg_add() { [ -z "$NOCOMMIT" ] && lbu_add "$@" } diff --git a/setup-interfaces.in b/setup-interfaces.in index df8f231..aad042d 100755 --- a/setup-interfaces.in +++ b/setup-interfaces.in @@ -41,7 +41,11 @@ config_iface() { local address local netmask local gateway - while invalid_ip $address ; do + + # use ipcalc to validate the address. we do accept /mask + # we are no interested in the result, only error code, so + # we send result to /dev/null + while ! ipcalc -s -m $address >/dev/null 2>&1; do address=`get_default_addr $iface` [ -z "$address" ] && address="dhcp" echon "Ip address for $iface? (or 'dhcp') [$address] " @@ -55,14 +59,23 @@ config_iface() { fi done - while invalid_ip $netmask ; do + # extract netmask if entered together with address + if [ "$address" != "${address%%/*}" ]; then + netmask=$(ipcalc -s -m $address | cut -d= -f2) + fi + + # use ipcalc -m to validate netmask. we dont accept <addr>/mask suffix + # so we pass on a dummy mask to ipcalc. + while ! ipcalc -s -m $netmask/0 >/dev/null 2>&1; do netmask=`get_default_mask $address` echon "Netmask? [$netmask] " default_read netmask "$netmask" [ "$netmask" = "abort" ] && return done - while invalid_ip $gateway ; do + # use ipcalc -m to validate netmask. we dont accept <addr>/mask suffix + # so we pass on a dummy mask to ipcalc. + while ! ipcalc -s -m $gateway/0 >/dev/null 2>&1; do gateway=`get_default_gateway $iface` [ -z "$gateway" ] && gateway=none echon "Gateway? (or 'none') [$gateway] " @@ -73,9 +86,13 @@ config_iface() { done echo "type=static" > $iface.conf - echo "address=$address" >> $iface.conf + echo "address=${address%%/*}" >> $iface.conf #strip off /mask if there echo "netmask=$netmask" >> $iface.conf echo "gateway=$gateway" >> $iface.conf + + # print summary + echo "Configuration for $iface:" + sed 's/^/ /' $iface.conf rm $iface.noconf } |