unify dns related config, change some dns settings
[distro-setup] / brc2
diff --git a/brc2 b/brc2
index aa370ac58b5ce13a74a9172c5760a367e7e3e471..9e2b5483c5a5ae229ca6fcf992b46085ae38c5bc 100644 (file)
--- a/brc2
+++ b/brc2
@@ -840,6 +840,7 @@ mpvrpc-loadfile() {
 # q quit
 # ret next
 #
+# todo: enter should also unpause
 beetag()  {
   local last_genre_i fstring tag id char new_item char_i genre tag remove doplay i j random path
   local do_rare_genres read_wait help line lsout tmp ls_line skip_lookback
@@ -2055,6 +2056,7 @@ apache-apply() {
 }
 # strip out the apache license from a file.
 apache-strip() {
+  # shellcheck disable=SC2044 # meh
   for f in $(find . -type f -maxdepth 1); do if head -n1 "$f"| grep -E '^#!/bin/bash\b' &>/dev/null; then { head -n 20 $f | tac | sed '/^# limitations under the License.$/,/^# Copyright.*Ian Kelling$/d' | tac; tail -n+21 $f; } |sponge $f; fi ; done
 }
 
@@ -2628,19 +2630,52 @@ wgkey() {
   umask $umask_orig
 }
 
-declare -A vpn_ips
-vpn_ips[kd]=2
-# note: 1, 4, 5 are occupied by mail wireguard
-vpn_ips[x3]=8
-vpn_ips[sy]=12
-vpn_ips[x2]=13
-vpn_ips[kw]=27
-vpn_ips[bo]=28
-vpn_ips[frodo]=34
-vpn_ips[s23b]=49
+host-info-update() {
+
+  local -A vpn_ips host_ips host_macs nonvpn_ips
+  local -a root_hosts nonroot_hosts
+
+  # the hosts with no mac
+  root_hosts=( bk je li b8.nz )
+  for h in ${root_hosts[@]}; do
+    root_hosts+=(${h}ex)
+  done
+  root_hosts+=(cmc)
+
+  while read -r ip host mac opts; do
+    if [[ $ip == *#*  || ! $host ]]; then continue; fi
+    if [[ $opts == vpn ]]; then
+      vpn_ips[$host]=$ip
+    else
+      nonvpn_ips[$host]=$ip
+    fi
+
+
+    if [[ $opts == user=root ]]; then
+      root_hosts+=($host i$host)
+    else
+      nonroot_hosts+=($host i$host)
+    fi
+
+    host_ips[$host]=$ip
+    host_macs[$host]=$mac
+  done </p/c/host-info
+
+  cedit /p/c/subdir_files/.ssh/config <<EOF || [[ $? == 1 ]]
+Host ${nonroot_hosts[@]}
+User iank
+IdentityFile ~/.ssh/home
+
+Host ${root_hosts[@]}
+IdentityFile ~/.ssh/home
+EOF
+
+
+  grep -E '^[a-z0-9]+[[:space:]]' /p/c/machine_specific/vps/bind-initial/db.b8.nz | awk '{print $1,$3}'
 
-vpn-ips-update() {
   local host ipsuf f files
+
+  sedi '/edits below here are made automatically/,$d' /p/c/machine_specific/li/filesystem/etc/wireguard/wgmail.conf
   for host in ${!vpn_ips[@]}; do
     ipsuf=${vpn_ips[$host]}
     wghole $host $ipsuf
@@ -2685,15 +2720,28 @@ EOF
   done
 
   {
-    for host in ${!vpn_ips[@]}; do
-      ipsuf=${vpn_ips[$host]}
-      cat <<EOF
-local-data-ptr: "10.2.0.$ipsuf $host.b8.nz"
-EOF
+    echo "cat <<EOF"
+    for host in ${!host_ips[@]}; do
+      ipsuf=${host_ips[$host]}
+      echo 'local-data-ptr: "$l.'$ipsuf $host.b8.nz'"'
+    done
+    echo "EOF"
+  } | u /p/ptr-data
+
+  {
+    echo "cat <<EOF"
+    for host in ${!host_ips[@]}; do
+      ipsuf=${host_ips[$host]}
+      echo "dhcp-host=${host_macs[$host]},set:$host,\$l.7,$host"
     done
-  } | u /b/ds/ptr-data
+    echo "EOF"
+  } | u /p/dnsmaq-data
 
   {
+    for host in ${!nonvpn_ips[@]}; do
+      ipsuf=${nonvpn_ips[$host]}
+      echo "$host      A       10.2.0.$ipsuf"
+    done
     for host in ${!vpn_ips[@]}; do
       ipsuf=${vpn_ips[$host]}
       cat <<EOF
@@ -2729,8 +2777,7 @@ EOF
   for f in "${files[@]}"; do
     host=${f%%/*}
     if [[ ! ${vpn_ips[$host]} ]]; then
-      e /p/c/machine_specific/$host/filesystem/etc/wireguard/wghole.conf
-      e cedit -s $host /p/c/machine_specific/li/filesystem/etc/wireguard/wgmail.conf '<<<""'
+      e rm /p/c/machine_specific/$host/filesystem/etc/wireguard/wghole.conf
     fi
   done
 }