From 2473784c8538aba6e1f9d581deaa09d13bb95fe5 Mon Sep 17 00:00:00 2001 From: Gavin Li Date: Mon, 5 Jan 2015 20:07:14 -0800 Subject: [PATCH] add interfaces parsing script --- install.sh | 103 +++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 96 insertions(+), 7 deletions(-) diff --git a/install.sh b/install.sh index b784d51..532819c 100755 --- a/install.sh +++ b/install.sh @@ -74,6 +74,10 @@ log() { echo "[$(date)]" "$@" >&2 } +extract_embedded_file() { + gawk -e '$0=="!!!!"{p=0};p;$0=="!!!!"n{p=1}' n="${1}" "${script_path}" +} + mask_to_prefix() { local prefix=0 netmask=${1} for octet in ${netmask//./ }; do @@ -134,12 +138,8 @@ install_compat_package() { EOF mkdir -p ${workdir}/usr/bin/ - cat > ${workdir}/usr/bin/parse-debian-interfaces <<-EOF - #!/bin/bash - set -eu - set -o pipefail - echo ENIENIENIENI > /dev/kmsg - EOF + extract_embedded_file parse-debian-interfaces > \ + ${workdir}/usr/bin/parse-debian-interfaces chmod 0755 ${workdir}/usr/bin/parse-debian-interfaces ( cd ${workdir} && bsdtar -cf compat.pkg.tar * ) @@ -418,6 +418,10 @@ postbootstrap_configuration() { rm /archroot/etc/shadow.new ) + # copy interfaces file + mkdir -p /archroot/etc/network/ + cp /etc/network/interfaces /archroot/etc/network/interfaces + # set up internet network local eni=/etc/network/interfaces { @@ -673,7 +677,92 @@ elif [ "${script_path}" = "/installer/script.sh" ]; then else installer_main "$@" fi -exit 0 # in case junk appended +exit 0 + +: < fn + else + return + addr = iface_getprop("gateway", suffix) + if (addr) + print "Gateway=" addr > fn + split(iface_getprop("dns", suffix), dnss, "|") + for (i = 1; i in dnss; i++) + print "DNS=" dnss[i] > fn +} + +function netmask_to_prefix(mask, cmps, bit, pfx) { + if (mask ~ /\./) { + pfx = 0 + split(mask, cmps, ".") + do { + bit = and(cmps[rshift(pfx, 3) + 1], + lshift(1, 7 - and(pfx, 7))) + } while (bit && ++pfx < 32) + } else { + pfx = mask + } + return pfx +} + +BEGIN { + netdir = "/run/systemd/network" + if (system("mkdir -p " netdir) != 0) + exit 1 +} + +$1 == "iface" { + iface_name = $2 + iface_family = $3 + iface_type = $4 + active = (iface_type == "static") && + (iface_family == "inet" || iface_family == "inet6") +} + +active && ($1 ~ /^(address|netmask|gateway)$/) { + ($1 == "netmask") && ($2 = netmask_to_prefix($2)) + iface_setprop($1, $2) +} + +active && $1 == "dns-nameservers" { + joined = "" + for (i = 2; $i; i++) + joined = joined ? joined "|" $i : $i + iface_setprop("dns", joined) +} + +END { + for (iface_name in interfaces) { + fn = netdir "/" iface_name ".network" + print "# Generated by parse-debian-interfaces" > fn + print "" > fn + print "[Match]" > fn + print "Name=" iface_name > fn + print "" > fn + print "[Network]" > fn + iface_dump(4, fn) + iface_dump(6, fn) + close(fn) + } +} +!!!! +EMBED ################# # END OF SCRIPT #