From e18ed518c7b13fa4911c739865fd97e744e0dea7 Mon Sep 17 00:00:00 2001 From: Red5d Date: Sun, 20 Jul 2014 14:19:58 -0400 Subject: [PATCH] Calculate correct netmask I've added a netmask cidr calculator function from here: http://www.linuxquestions.org/questions/programming-9/bash-cidr-calculator-646701/ Just tested this on Digital Ocean system and it works. The netmask is set correctly after the reboot and networking works. --- install.sh | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/install.sh b/install.sh index ff7cfaa..a592faf 100755 --- a/install.sh +++ b/install.sh @@ -267,17 +267,28 @@ postbootstrap_configuration() { read ignored netmask <&${grepfd} read ignored gateway <&${grepfd} exec {grepfd}<&- - case ${netmask} in - 255.255.255.0) - prefixlen=24 - ;; - 255.255.240.0) - prefixlen=20 - ;; - 255.255.0.0) - prefixlen=16 - ;; - esac + mask2cidr() { + nbits=0 + IFS=. + for dec in $1 ; do + case $dec in + 255) let nbits+=8;; + 254) let nbits+=7;; + 252) let nbits+=6;; + 248) let nbits+=5;; + 240) let nbits+=4;; + 224) let nbits+=3;; + 192) let nbits+=2;; + 128) let nbits+=1;; + 0);; + *) echo "Error: $dec is not recognised"; exit 1 + esac + done + echo "$nbits" + } + + prefixlen=$(mask2cidr ${netmask}) + cat > /archroot/etc/systemd/network/internet.network <