host info updates
[distro-setup] / brc2
diff --git a/brc2 b/brc2
index de12005348a0efa2fad4e0e1f2952902cb4d912d..3edbae0f26a47871cf1e0d733f570d0b935f8995 100644 (file)
--- a/brc2
+++ b/brc2
@@ -172,7 +172,7 @@ slemacs() {
 
 sle() { # sl emacs
   local f=/home/iank/.emacs.d/init.el
-  sl --sl-test-cmd ". /etc/os-release ; printf %s \${VERSION//[^a-zA-Z0-9]/}; test -e $f && stat -c%Y $f" --sl-test-hook slemacs "$@"
+  sl --sl-test-cmd "sed -rn '/^VERSION=/{s/^.*=//;s/[^[:alnum:]]//gp}' /etc/os-release; test -e $f && stat -c%Y $f" --sl-test-hook slemacs "$@"
 }
 ccomp ssh sle
 
@@ -2639,7 +2639,7 @@ wgkey() {
 host-info-all() {
   host-info-update
   bindpushb8
-  ssh li.b8.nz conflink
+  ssh iank@li.b8.nz conflink
   wrt-setup
 }
 
@@ -2687,12 +2687,15 @@ host-info-update() {
       # hosts is that it is for the User part, the IdentityFile part is
       # redundant to *.b8.nz. Also note ${host}i, we only setup those for vpn hosts, but there is no harm in overspecifying here.
       root_hosts+=($host ${host}i $host.b8.nz ${host}i.b8.nz)
+      root_hosts_a[$host]=t  # a for associative array
     else
       nonroot_hosts+=($host ${host}i)
     fi
-
     host_ips[$host]=$ip
-    host_macs[$host]=$mac
+    if [[ $mac ]]; then
+      host_macs[$host]=$mac
+    fi
+
   done </p/c/host-info
 
   {
@@ -2732,17 +2735,17 @@ EOF
       ipsuf=${vpn_ips[$host]}
       i_port=$(( 2200 + ipsuf ))
       cat <<EOF
-      config redirect
-      option name ssh$host
-      option src              wan
-      option src_dport        $i_port
-      option dest_port        22
-      option dest_ip          \$l.$ipsuf
-      option dest             lan
-      config rule
-      option src              wan
-      option target           ACCEPT
-      option dest_port        $i_port
+config redirect
+option name ssh$host
+option src              wan
+option src_dport        $i_port
+option dest_port        22
+option dest_ip          \$l.$ipsuf
+option dest             lan
+config rule
+option src              wan
+option target           ACCEPT
+option dest_port        $i_port
 EOF
     done
     echo "EOF"
@@ -2754,7 +2757,7 @@ EOF
   # shellcheck disable=SC2016 # shellcheck doesnt know this is sed
   sedi '/edits below here are made automatically/,$d' /p/c/machine_specific/li/filesystem/etc/wireguard/wgmail.conf
   for host in ${!vpn_ips[@]}; do
-    if [[ ${root_ips[$host]} ]]; then
+    if [[ ${root_hosts_a[$host]} ]]; then
       # root machines dont actually need vpn, but
       # the classification still helps with other
       # configurations.
@@ -2762,7 +2765,7 @@ EOF
     fi
     ipsuf=${vpn_ips[$host]}
     wghole $host $ipsuf
-    sd /b/ds/machine_specific/li/filesystem/etc/openvpn/client-config-hole/$host <<EOF
+    u /b/ds/machine_specific/li/filesystem/etc/openvpn/client-config-hole/$host <<EOF
 ifconfig-push 10.5.5.${vpn_ips[$host]} 255.255.255.0
 EOF
     u /a/bin/ds/machine_specific/$host/filesystem/etc/systemd/system/openvpn-client-tr@.service <<EOF
@@ -2817,13 +2820,14 @@ EOF
 
   {
     echo "cat <<EOF"
-    for host in ${!host_ips[@]}; do
+    for host in ${!host_macs[@]}; do
       ipsuf=${host_ips[$host]}
       echo "dhcp-host=${host_macs[$host]},set:$host,\$l.$ipsuf,$host"
     done
     echo "EOF"
   } | u /p/c/dnsmasq-data
 
+
   b8_ip=$(dig +short b8.nz @iankelling.org | tail -1)
   if [[ ! $b8_ip ]]; then
     echo "$0: error: got empty b8.nz ip. returning 1"
@@ -2867,15 +2871,23 @@ EOF
 /p/c/machine_specific filesystem/etc/wireguard/wghole.conf
 EOF
 
-  files=(/b/ds/machine_specific/li/filesystem/etc/openvpn/client-config-hole/* )
+  files=( /b/ds/machine_specific/li/filesystem/etc/openvpn/client-config-hole/* )
   for f in "${files[@]}"; do
-    host=${f##/*}
+    host=${f##*/}
     if [[ ! ${vpn_ips[$host]} ]]; then
       e rm $f
       e ssh root@li.b8.nz rm -f $f
     fi
   done
 
+
+  {
+    printf "%s" "Host * "
+    sed -n '/^Host /h;/^IdentityFile .*\/home/{g;s/^Host//;s/ / !/gp}' ~/.ssh/config | tr '\n' ' '
+    echo "IdentityFile ~/.ssh/work"
+  } | cedit work-identity ~/.ssh/config || [[ $? == 1 ]]
+
+
 }
 
 # usage host ipsuf [extrahost]