diff options
-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)" |