summaryrefslogtreecommitdiffstats
path: root/networking-configuration
diff options
context:
space:
mode:
authortv <tv@shackspace.de>2015-05-20 22:05:38 +0200
committertv <tv@shackspace.de>2015-05-20 22:05:38 +0200
commit1cc154e1a25d4adaeb312370155417e910f20b1d (patch)
treebb83147686aa25a74b1b9e825d383c7adb244117 /networking-configuration
parent3cc354008a76f061ab4708922b7c0f3a8d37097b (diff)
lib/net.sh: add net_netmask_to_prefix
Diffstat (limited to 'networking-configuration')
-rwxr-xr-xnetworking-configuration16
1 files changed, 3 insertions, 13 deletions
diff --git a/networking-configuration b/networking-configuration
index 77b9a45be..0e105b45f 100755
--- a/networking-configuration
+++ b/networking-configuration
@@ -5,6 +5,7 @@
set -euf
. ./lib/cac.sh
+. ./lib/net.sh
cac_servername=$1
hostname=$2
@@ -31,7 +32,7 @@ print_networking_configuraton() {
gateway=$(echo $server | jq -r .gateway)
nameserver=8.8.8.8
netmask=$(echo $server | jq -r .netmask)
- prefixLength=$(netmaskToPrefixLengh $netmask)
+ prefix=$(net_netmask_to_prefix $netmask)
# TODO generate all config and put it into a temp dir, then rsync that
#
@@ -43,7 +44,7 @@ print_networking_configuraton() {
printf ' networking.interfaces.enp2s1.ip4 = [\n'
printf ' {\n'
printf ' address = "%s";\n' $address
- printf ' prefixLength = %d;\n' $prefixLength
+ printf ' prefixLength = %d;\n' $prefix
printf ' }\n'
printf ' ];\n'
printf ' networking.defaultGateway = "%s";\n' $gateway
@@ -53,15 +54,4 @@ print_networking_configuraton() {
printf '}\n'
}
-netmaskToPrefixLengh() {
- 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
-}
-
-
main "$@"