diff options
author | tv <tv@shackspace.de> | 2015-08-06 19:37:27 +0200 |
---|---|---|
committer | tv <tv@shackspace.de> | 2015-08-06 19:37:27 +0200 |
commit | f4589158572ab35969b9bccf801ea07e115705e1 (patch) | |
tree | 8fc740eda2a54d9fad076e461ded91bb6944199f /cac | |
parent | 0fc9cbeba4060380f698f51bb74081e2fcefadf3 (diff) |
cac: import netmask_to_prefix from stockholm
Diffstat (limited to 'cac')
-rwxr-xr-x | cac | 16 |
1 files changed, 15 insertions, 1 deletions
@@ -45,6 +45,20 @@ sed ' s/~/%7e/g ' } +netmask_to_prefix() {( +#! /bin/sh +set -euf + +netmask=$1 + +binaryNetmask=$(echo $1 | sed 's/^/obase=2;/;s/\./;/g' | bc | tr -d \\n) +binaryPrefix=$(echo $binaryNetmask | sed -n 's/^\(1*\)0*$/\1/p') +if ! echo $binaryPrefix | grep -q .; then + echo $0: bad netmask: $netmask >&2 + exit 4 +fi +printf %s $binaryPrefix | tr -d 0 | wc -c +)} # cac_resources_cache=${cac_resources_cache-$HOME/tmp/cac_resources_cache.json} @@ -196,7 +210,7 @@ __cac_cli__generatenetworking() {( gateway=$(echo $server | jq -r .gateway) nameserver=8.8.8.8 netmask=$(echo $server | jq -r .netmask) - prefix=$(netmask-to-prefix $netmask) + prefix=$(netmask_to_prefix $netmask) #printf '# Generated file: %s generatenetworking %s %s\n' "$0" "$1" "$2" #printf '# on %s\n' "$(date -Is)" |