pkgs/ap: fix multiple issues

This commit is contained in:
Astro 2021-11-07 00:23:21 +01:00
parent db4d075af2
commit 5c074bb051
1 changed files with 17 additions and 13 deletions

View File

@ -53,13 +53,17 @@ let
switchHostInterface = switchHostInterface =
let let
hostPorts = builtins.attrValues ( hostPorts = sort builtins.lessThan (
filterAttrs (_: { type, ... }: type == "host") map ({ interface, ... }: interface) (
openwrtModel.ports builtins.attrValues (
filterAttrs (_: { type, ... }: type == "host")
openwrtModel.ports
)
)
); );
in if hostPorts == [] in if hostPorts == []
then throw "No host ports found for OpenWRT model ${hostConfig.model}" then throw "No host ports found for OpenWRT model ${hostConfig.model}"
else (builtins.head hostPorts).interface; else builtins.head hostPorts;
switchPortIndices = f: switchPortIndices = f:
map ({ index, ... }: index) ( map ({ index, ... }: index) (
@ -143,7 +147,7 @@ in ''
ssh root@192.168.1.1 \ ssh root@192.168.1.1 \
"ash -e -x" <<__SSH__ "ash -e -x" <<__SSH__
'' else '' '' else ''
ssh root@{{ pillar['hosts-inet']['mgmt'][hostName] }} \ ssh root@${config.site.net.mgmt.hosts4.${hostName}} \
"ash -e -x" <<__SSH__ "ash -e -x" <<__SSH__
''} ''}
@ -157,7 +161,7 @@ in ''
# System configuration # System configuration
uci batch <<__UCI__ uci batch <<__UCI__
set system.@system[0].hostName=${hostName} set system.@system[0].hostname=${hostName}
set dhcp.@dnsmasq[0].enabled=0 set dhcp.@dnsmasq[0].enabled=0
set system.@system[0].log_ip=${config.site.net.mgmt.hosts4.logging} set system.@system[0].log_ip=${config.site.net.mgmt.hosts4.logging}
set system.@system[0].log_proto=udp set system.@system[0].log_proto=udp
@ -202,9 +206,9 @@ in ''
set network.mgmt.netmask=${self.lib.netmasks.${elemAt ( set network.mgmt.netmask=${self.lib.netmasks.${elemAt (
builtins.split "/" config.site.net.mgmt.subnet4 builtins.split "/" config.site.net.mgmt.subnet4
) 2}} ) 2}}
set network.mgmt.gateway=${config.site.net.mgmt.hosts4."mgmt-gw"} 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.ip6addr=${config.site.net.mgmt.hosts6.dn42.${hostName}}/64
set network.mgmt.ip6gw=${config.site.net.mgmt.hosts6.dn42."mgmt-gw"} set network.mgmt.ip6gw=${config.site.net.mgmt.hosts6.dn42.mgmt-gw}
delete network.mgmt.dns delete network.mgmt.dns
add_list network.mgmt.dns=${config.site.net.serv.hosts4.dnscache} add_list network.mgmt.dns=${config.site.net.serv.hosts4.dnscache}
add_list network.mgmt.dns=${config.site.net.serv.hosts6.dn42.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__ cat >/usr/sbin/wifi-on-link.sh <<__SH__
#!/bin/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 REACHABLE=y
else else
REACHABLE=n REACHABLE=n
@ -289,11 +293,11 @@ in ''
UP=n UP=n
fi fi
{%- if conf.get("error-led") %} if [ -e /sys/class/leds/blue:dome ] ; then
ERROR_LED=/sys/class/leds/{{ conf["error-led"] }}/brightness ERROR_LED=/sys/class/leds/blue:dome/brightness
[ \\\$REACHABLE = y ] && echo 0 > \\\$ERROR_LED [ \\\$REACHABLE = y ] && echo 0 > \\\$ERROR_LED
[ \\\$REACHABLE = n ] && echo 1 > \\\$ERROR_LED [ \\\$REACHABLE = n ] && echo 1 > \\\$ERROR_LED
{%- endif %} fi
[ \\\$REACHABLE = y ] && [ \\\$UP = n ] && wifi up [ \\\$REACHABLE = y ] && [ \\\$UP = n ] && wifi up
[ \\\$REACHABLE = n ] && [ \\\$UP = y ] && wifi down [ \\\$REACHABLE = n ] && [ \\\$UP = y ] && wifi down