shellcheck, static usb ethnet addresses, fix vpn config
[distro-setup] / brc2
diff --git a/brc2 b/brc2
index eae5aa93439b60f921cc061cacee567cf47d2c1f..05de0a3f1cf93cbc19db5213794c83b6a129807f 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,6 +2639,7 @@ wgkey() {
 host-info-all() {
   host-info-update
   bindpushb8
+  ssh iank@li.b8.nz conflink
   wrt-setup
 }
 
@@ -2649,7 +2650,7 @@ host-info-all() {
 host-info-update() {
 
   local -A vpn_ips host_ips host_macs nonvpn_ips all_ips
-  local -a root_hosts nonroot_hosts
+  local -a root_hosts nonroot_hosts host_usbs
 
   # the hosts with no mac
   root_hosts=( bk je li b8.nz )
@@ -2689,9 +2690,11 @@ host-info-update() {
     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
 
   {
@@ -2724,22 +2727,24 @@ EOF
   } | cedit /p/c/subdir_files/.ssh/config || [[ $? == 1 ]]
 
   {
-    echo "cat <<EOF"
+    # hack to please emacs parser
+    here_begin="cat <<EOF"
+    echo "$here_begin"
     for host in ${!vpn_ips[@]}; do
       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
+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
+option src              wan
+option target           ACCEPT
+option dest_port        $i_port
 EOF
     done
     echo "EOF"
@@ -2752,11 +2757,16 @@ EOF
   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
-      # root machines dont run transmission
+      # root machines dont actually need vpn, but
+      # the classification still helps with other
+      # configurations.
       continue
     fi
     ipsuf=${vpn_ips[$host]}
     wghole $host $ipsuf
+    sd /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
 [Unit]
 Description=OpenVPN tunnel for %I
@@ -2816,6 +2826,7 @@ EOF
     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"
@@ -2842,29 +2853,32 @@ EOF
   echo checking for stray files:
 
   initial_dir="$PWD"
-  cd /a/bin/ds/machine_specific
-  ngset
-  files=( */filesystem/etc/systemd/system/openvpn-client-tr@.service )
-  ngreset
-  cd "$initial_dir"
-  for f in "${files[@]}"; do
-    host=${f%%/*}
-    if [[ ! ${vpn_ips[$host]} ]]; then
-      e rm /a/bin/ds/machine_specific/$host/filesystem/etc/systemd/system/openvpn-client-tr@.service
-    fi
-  done
+  while read -r dir path; do
+    cd $dir
+    ngset
+    files=( */$path )
+    ngreset
+    cd "$initial_dir"
+    for f in "${files[@]}"; do
+      host=${f%%/*}
+      if [[ ! ${vpn_ips[$host]} ]]; then
+        e rm $dir/$f
+      fi
+    done
+  done <<'EOF'
+/a/bin/ds/machine_specific filesystem/etc/systemd/system/openvpn-client-tr@.service
+/p/c/machine_specific filesystem/etc/wireguard/wghole.conf
+EOF
 
-  cd /p/c/machine_specific
-  ngset
-  files=( */filesystem/etc/wireguard/wghole.conf )
-  ngreset
-  cd $initial_dir
+  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 /p/c/machine_specific/$host/filesystem/etc/wireguard/wghole.conf
+      e rm $f
+      e ssh root@li.b8.nz rm -f $f
     fi
   done
+
 }
 
 # usage host ipsuf [extrahost]