From d5e219dbf5ce69d6eac1f26eb7d1c590120952e3 Mon Sep 17 00:00:00 2001 From: hygienic-books Date: Sat, 11 Nov 2023 01:17:14 +0100 Subject: [PATCH] feat(iso): Add bash-only CIDR calculator function (#21) --- setup.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/setup.sh b/setup.sh index c6404b7..c606a9e 100644 --- a/setup.sh +++ b/setup.sh @@ -36,6 +36,17 @@ trap '[ "$?" -ne 77 ] || exit 77' ERR declare zpool_drive efi_drive boot_drive part_schema +function calculate_prefix_from_netmask () { + # https://stackoverflow.com/a/50419919 + c='0' + x='0'"$(printf -- '%o' ${1//./ })" + while [ "${x}" -gt '0' ]; do + # Modulo then bitwise-shift x and store as new x + let c+="$(( x % 2 ))" 'x>>=1' + done + printf -- '%s' '/'"${c}"; +} + function setup_env_vars () { printf -- '%s\n' \ 'We will go over a series of questions to create an answer file with' \