From 5c074bb051d2f1792c441c58679f6a57588ee7ac Mon Sep 17 00:00:00 2001 From: Astro Date: Sun, 7 Nov 2021 00:23:21 +0100 Subject: [PATCH] pkgs/ap: fix multiple issues --- nix/pkgs/ap.nix | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/nix/pkgs/ap.nix b/nix/pkgs/ap.nix index 5eea5f4..3e57358 100644 --- a/nix/pkgs/ap.nix +++ b/nix/pkgs/ap.nix @@ -53,13 +53,17 @@ let switchHostInterface = let - hostPorts = builtins.attrValues ( - filterAttrs (_: { type, ... }: type == "host") - openwrtModel.ports + hostPorts = sort builtins.lessThan ( + map ({ interface, ... }: interface) ( + builtins.attrValues ( + filterAttrs (_: { type, ... }: type == "host") + openwrtModel.ports + ) + ) ); in if hostPorts == [] then throw "No host ports found for OpenWRT model ${hostConfig.model}" - else (builtins.head hostPorts).interface; + else builtins.head hostPorts; switchPortIndices = f: map ({ index, ... }: index) ( @@ -143,7 +147,7 @@ in '' ssh root@192.168.1.1 \ "ash -e -x" <<__SSH__ '' else '' - ssh root@{{ pillar['hosts-inet']['mgmt'][hostName] }} \ + ssh root@${config.site.net.mgmt.hosts4.${hostName}} \ "ash -e -x" <<__SSH__ ''} @@ -157,7 +161,7 @@ in '' # System configuration uci batch <<__UCI__ - set system.@system[0].hostName=${hostName} + set system.@system[0].hostname=${hostName} set dhcp.@dnsmasq[0].enabled=0 set system.@system[0].log_ip=${config.site.net.mgmt.hosts4.logging} set system.@system[0].log_proto=udp @@ -202,9 +206,9 @@ in '' set network.mgmt.netmask=${self.lib.netmasks.${elemAt ( builtins.split "/" config.site.net.mgmt.subnet4 ) 2}} - set network.mgmt.gateway=${config.site.net.mgmt.hosts4."mgmt-gw"} - set network.mgmt.ip6addr=${config.site.net.mgmt.hosts6.dn42.${hostName}} - set network.mgmt.ip6gw=${config.site.net.mgmt.hosts6.dn42."mgmt-gw"} + set network.mgmt.gateway=${config.site.net.mgmt.hosts4.mgmt-gw} + set network.mgmt.ip6addr=${config.site.net.mgmt.hosts6.dn42.${hostName}}/64 + set network.mgmt.ip6gw=${config.site.net.mgmt.hosts6.dn42.mgmt-gw} delete network.mgmt.dns add_list network.mgmt.dns=${config.site.net.serv.hosts4.dnscache} add_list network.mgmt.dns=${config.site.net.serv.hosts6.dn42.dnscache} @@ -277,7 +281,7 @@ in '' cat >/usr/sbin/wifi-on-link.sh <<__SH__ #!/bin/sh - if (ping -c 1 -W 3 {{ pillar['hosts-inet']['mgmt']['mgmt-gw'] }}) ; then + if (ping -c 1 -W 3 ${config.site.net.mgmt.hosts4.mgmt-gw}) ; then REACHABLE=y else REACHABLE=n @@ -289,11 +293,11 @@ in '' UP=n fi - {%- if conf.get("error-led") %} - ERROR_LED=/sys/class/leds/{{ conf["error-led"] }}/brightness + if [ -e /sys/class/leds/blue:dome ] ; then + ERROR_LED=/sys/class/leds/blue:dome/brightness [ \\\$REACHABLE = y ] && echo 0 > \\\$ERROR_LED [ \\\$REACHABLE = n ] && echo 1 > \\\$ERROR_LED - {%- endif %} + fi [ \\\$REACHABLE = y ] && [ \\\$UP = n ] && wifi up [ \\\$REACHABLE = n ] && [ \\\$UP = y ] && wifi down