fixes
authorIan Kelling <ian@iankelling.org>
Wed, 4 Nov 2020 23:16:24 +0000 (18:16 -0500)
committerIan Kelling <ian@iankelling.org>
Wed, 4 Nov 2020 23:16:24 +0000 (18:16 -0500)
brc
brc2
filesystem/etc/systemd/system/openvpn-client-tr@.service
filesystem/etc/systemd/system/vpn-static-ip@.service [new file with mode: 0644]
mail-setup
vpn-static-ip [new file with mode: 0755]

diff --git a/brc b/brc
index 8d05863df83b950e3939b5ee534188b6918b873a..d450cc6c7e8eece0da6704174cac5c964613402b 100644 (file)
--- a/brc
+++ b/brc
@@ -328,6 +328,16 @@ a() {
   echo -n "$x" | xclip
 }
 
+# a1 = awk {print $1}
+for field in {1..20}; do
+  eval a$field"() { awk '{print \$$field}'; }"
+done
+# h1 = head -n1
+for num in {1..9}; do
+  eval h$num"() { head -n$num}; }"
+done
+
+
 b() {
   # backwards
   c -
@@ -1070,6 +1080,11 @@ r() {
   #  exit "$@" 2>/dev/null
 }
 
+# reapply bashrc
+reb() {
+  source ~/.bashrc
+}
+
 rl() {
   readlink -f "$@"
 }
diff --git a/brc2 b/brc2
index 773b3bb67383ccf091d1be934c8e2d2034fbc60a..6f28a8b0a263654c4373c181de7bf05ba4286479 100644 (file)
--- a/brc2
+++ b/brc2
@@ -338,10 +338,20 @@ bindpush() {
     m sl $h <<'EOF'
 source ~/.bashrc
 m dnsup
+EOF
+  done
+}
+bindpushb8() {
+  lipush
+  for h in li bk; do
+    m sl $h <<'EOF'
+source ~/.bashrc
+m dnsup
 m dnsb8
 EOF
   done
 }
+
 dnsup() {
   conflink
   m ser reload bind9
@@ -502,20 +512,20 @@ dup() {
   ran_d=false
   system-status _
   case $PS1 in
-    *\]D\ *)
+    *[\ \]]D\ *)
       pushd /
       /b/ds/distro-begin || return $?
       /b/ds/distro-end || return $?
       popd
       ran_d=true
       ;;&
-    *\]DB\ *)
+    *[\ \]]DB\ *)
       pushd /
       /b/ds/distro-begin || return $?
       popd
       ran_d=true
       ;;
-    *\]DE\ *)
+    *[\ \]]DE\ *)
       pushd /
       /b/ds/distro-end || return $?
       popd
@@ -883,7 +893,19 @@ lom() {
 # mu personality. for original, just run mp. for 2, run mp 2.
 # this is partly duplicated in mail-setup
 mp() {
-  killall mu ||:
+  local dead=false
+  for s in {1..5}; do
+    if ! killall mu; then
+      dead=true
+      break
+    fi
+    sleep 1
+  done
+  if ! $dead; then
+    echo error: mu not dead
+    m psg mu
+    return 1
+  fi
   suf=$1
   set -- /m/mucache ~/.cache/mu /m/.mu ~/.config/mu
   while (($#)); do
@@ -1254,11 +1276,6 @@ tu() {
   $s /a/exe/teeu "$@"
 }
 
-# a1 = awk {print $1}
-for field in {1..20}; do
-  eval a$field"() { awk '{print \$$field}'; }"
-done
-
 enn() {
   local ecmd pid
 
@@ -1267,7 +1284,7 @@ enn() {
     s $ecmd "$@"
     return
   fi
-  pid=$(pgrep -f "/usr/sbin/exim4 -bd -q30m -C /etc/exim4/my.conf"|a1)
+  pid=$(pgrep -f "/usr/sbin/exim4 -bd -q30m -C /etc/exim4/my.conf"|h1)
   m s nsenter -t $pid -n -m $ecmd "$@"
 }
 
@@ -1288,6 +1305,10 @@ vpncmd() {
 vpnf() {
   vpncmd sudo --preserve-env=PATH -E -u iank abrowser -no-remote -P vpn &r
 }
+vpn2f() {
+  vpncmd sudo --preserve-env=PATH -E -u iank abrowser -no-remote -P vpn2 &r
+}
+
 vpni() {
   vpncmd sudo --preserve-env=PATH -E -u iank "$@"
 }
index 5ba2c919457b499a58047cd695f23f620d24c26e..fdd71b18baf7a978460ada885e181b7767527a14 100644 (file)
@@ -1,6 +1,7 @@
 [Unit]
 Description=OpenVPN tunnel for %I
-After=syslog.target network-online.target
+After=syslog.target network-online.target vpn-static-ip@%i.service
+Requires=vpn-static-ip@%i.service
 Wants=network-online.target
 Documentation=man:openvpn(8)
 Documentation=https://community.openvpn.net/openvpn/wiki/Openvpn24ManPage
diff --git a/filesystem/etc/systemd/system/vpn-static-ip@.service b/filesystem/etc/systemd/system/vpn-static-ip@.service
new file mode 100644 (file)
index 0000000..7af3793
--- /dev/null
@@ -0,0 +1,7 @@
+[Unit]
+Description=vpn-static-ip
+
+
+[Service]
+Type=oneshot
+ExecStart=/b/ds/vpn-static-ip /etc/openvpn/client/%i.conf
index 2437ea67bf613c2fde7c7de585deb35780806549..cb9f67777d63134ad46cb059cbffee07901fed69 100755 (executable)
 
 # todo: mailtest-check failure on remote hosts is not going to alert me.
 # sort that out.
-
+# todo: test that mail is dkim signing in our mail test.
+# todo: send sending from all domains
+# todo: test mail failure as well as success.
+# todo: we should monitor spamhaus etc to make sure we dont get blacklisted.
 
 # background: I want to run exim in a network namespace so it can send
 # and receive through a vpn. This is needed so it can do ipv6, because
diff --git a/vpn-static-ip b/vpn-static-ip
new file mode 100755 (executable)
index 0000000..ae92d3c
--- /dev/null
@@ -0,0 +1,26 @@
+#!/bin/bash
+if ! test "$BASH_VERSION"; then echo "error: shell is not bash" >&2; exit 1; fi
+shopt -s inherit_errexit 2>/dev/null ||: # ignore fail in bash < 4.4
+set -eE -o pipefail
+trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?. PIPESTATUS: ${PIPESTATUS[*]}" >&2' ERR
+
+[[ $EUID == 0 ]] || exec sudo -E "${BASH_SOURCE[0]}" "$@"
+
+conf=$1
+
+# We block dns lookups from going outside the vpn network namespace,
+# there might be some other workaround, but just resolving to static ips
+# is a simple fix.
+
+sed --follow-symlinks -i '/^ *remote /d' $conf
+ret=1
+while read -r host port; do
+  while read -r ip; do
+    printf "remote %s %s\n" "$ip" "$port" >>$conf
+    ret=0
+  done < <(dig +short $host ||:)
+done < <(sed -rn 's/^ *# *remote //p' $conf)
+if ((ret)); then
+  echo "vpn-static-ip: error: failed to set any ips" >&2
+  exit 1
+fi