various fixes and mail improvements
authorIan Kelling <ian@iankelling.org>
Mon, 22 Jul 2019 19:59:59 +0000 (15:59 -0400)
committerIan Kelling <ian@iankelling.org>
Mon, 22 Jul 2019 19:59:59 +0000 (15:59 -0400)
.bashrc
brc
btrbk-run
filesystem/usr/local/bin/mailtest-check [new file with mode: 0755]
install-my-scripts
mail-setup
mount-latest-subvol
primary-setup
radicale-setup
switch-mail-host

diff --git a/.bashrc b/.bashrc
index 097dd9859413d0f9c5640e12908726d579bfdd29..53e4138d07b1ae1ba1e2fdacee445da6360a7491 100644 (file)
--- a/.bashrc
+++ b/.bashrc
 # which we could test for, but I can't think of a way to make that
 # inherently limited to a single ssh command.  I choose to set SendEnv
 # and AcceptEnv ssh config vars to allow the environment variable
-# BASH_LOGIN_SHELL to propagate across ssh.
+# BASH_LOGIN_SHELL to propagate across ssh. This also requires that we
+# wrap ssh in interactive shells, because, once we export the var, it
+# will go into scripts and theres no way to automatically set it.
 
-# assume we want ssh commands to source this file if we are sourcing it,
-# and we haven't specified otherwise already
-[[ ! $BASH_LOGIN_SHELL ]] && export BASH_LOGIN_SHELL=true
-#BASH_LOGIN_SHELL=false # temporary override
 
 # first conditions show that we are an ssh command without an interactive shell
 if [[ $SSH_CONNECTION ]] \
        && [[ $- == *c* ]] \
        && [[ ! $SSH_TTY ]] \
        && [[ $- != *i* ]] \
-       && [[ ! $BASH_LOGIN_SHELL == true ]]; then
+       && [[ $BASH_LOGIN_SHELL != true ]]; then
     return 0
 else
     if [[ -r /etc/profile ]]; then
diff --git a/brc b/brc
index cdfac012cb45c2c94a79d0999a14e2929cb8bcf2..bf8548f11dee9c65259cbca9395dd6eea1c311eb 100644 (file)
--- a/brc
+++ b/brc
@@ -157,7 +157,7 @@ HISTCONTROL=ignoredups
 # works in addition to HISTCONTROL to do more flexible things
 # it could also do the same things as HISTCONTROL and thus replace it,
 # but meh. dunno why, but just " *" does glob expansion, so use [ ] to avoid it.
-HISTIGNORE='pass *:[ ]*:lom*:gram*'
+HISTIGNORE='pass *:[ ]*:otp *:oathtool *'
 
 export BC_LINE_LENGTH=0
 
@@ -1713,6 +1713,9 @@ srun() {
   ssh $1 /tmp/${2##*/} "${@:2}"
 }
 
+ssh() {
+  BASH_LOGIN_SHELL=true command ssh "$@"
+}
 sss() { # ssh solo
   ssh -oControlMaster=no -oControlPath=/ "$@"
 }
@@ -1821,11 +1824,11 @@ _dosieve() {
 
 # always run this first, edit the test files, then run the following
 testsieve() {
-  _dosieve ~/sieve/maintest.sieve INBOX delete
+  _dosieve ~/sieve/maintest.sieve ${1:-INBOX} delete
 }
 runsieve() {
   c ~/sieve; cp personal{test,}.sieve; cp lists{test,}.sieve
-  _dosieve ~/sieve/main.sieve -eW INBOX delete
+  _dosieve ~/sieve/main.sieve -eW ${1:-INBOX} delete
 }
 
 # mail related
@@ -2176,6 +2179,10 @@ if [[ $- == *i* ]]; then
     if [[ -e /nocow/btrfs-stale ]] && ((`command ls -AUq /nocow/btrfs-stale|wc -l`)); then
       ps_char="! $ps_char"
     fi
+    if [[ -e /nocow/mailtest-failure ]]; then
+      ps_char="@#$@#$ $ps_char"
+    fi
+    source /a/bin/bash_unpublished/source-state
     if [[ ! $SSH_CLIENT && $MAIL_HOST != $HOSTNAME ]]; then
       ps_char="@ $ps_char"
     fi
index f3589700b35729fa4cbb691e265a83e64c11658a..e30c9c3dd3667d259a46e560773890e3919dd9a9 100644 (file)
--- a/btrbk-run
+++ b/btrbk-run
 
 # todo: if we cancel in the middle of a btrfs send, then run again immediately, the received subvolume doesn't get a Received UUID: field, and we won't mount it. Need to figure out a solution that will fix this.
 
-set -eE -o pipefail
-trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
+err-bash-trace() {
+  local -i argc_index=0 frame i start=${1:-0} max_indent=8 indent
+  local source
+  local extdebug=false
+  if [[ $(shopt -p extdebug) == *-s* ]]; then
+    extdebug=true
+  fi
+  for ((frame=0; frame < ${#FUNCNAME[@]}-1; frame++)); do
+    argc=${BASH_ARGC[frame]}
+    argc_index+=$argc
+    ((frame < start)) && continue
+    if (( ${#BASH_SOURCE[@]} > 1 )); then
+      source="${BASH_SOURCE[frame+1]}:${BASH_LINENO[frame]}:"
+    fi
+    indent=$((frame-start + 1))
+    indent=$((indent < max_indent ? indent : max_indent))
+    printf "%${indent}s↳%sin \`%s" '' "$source" "${FUNCNAME[frame]}"
+    if $extdebug; then
+      for ((i=argc_index-1; i >= argc_index-argc; i--)); do
+        printf " %s" "${BASH_ARGV[i]}"
+      done
+    fi
+    echo \'
+  done
+  return 0
+}
+err-catch() {
+  set -E; shopt -s extdebug
+  _err-trap() {
+    err=$?
+    exec >&2
+    set +x
+    echo "${BASH_SOURCE[1]}:${BASH_LINENO[0]}: \`$BASH_COMMAND' returned $err"
+    err-bash-trace 2
+    set -e # err trap does not work within an error trap
+    "${_errcatch_cleanup[@]:-:}" # note :-: is to be compatible with set -u
+    echo "$0: exiting with code $err"
+    exit $err
+  }
+  trap _err-trap ERR
+  set -o pipefail
+}
+err-catch
+
 
 [[ $EUID == 0 ]] || exec sudo -E "$BASH_SOURCE" "$@"
 
@@ -47,8 +89,8 @@ m() { if $verbose; then printf "$pre %s\n"  "$*"; fi;  "$@"; }
 die() { printf "$pre %s\n" "$*" >&2;  exit 1; }
 
 # latest $MAIL_HOST
-if [[ -e /b/bash_unpublished/source-semi-priv ]]; then
-  source /b/bash_unpublished/source-semi-priv
+if [[ -e /b/bash_unpublished/source-state ]]; then
+  source /b/bash_unpublished/source-state
 fi
 
 # note q is owned by root:1000
@@ -134,7 +176,7 @@ if [[ ! -v targets && ! $source ]]; then
       if ping -q -c1 -w1 iank.vpn.office.fsf.org &>/dev/null; then
         home=iank.vpn.office.fsf.org
       else
-        home=$HOME_DOMAIN
+        home=b8.nz
       fi
       ;;&
     kw)
diff --git a/filesystem/usr/local/bin/mailtest-check b/filesystem/usr/local/bin/mailtest-check
new file mode 100755 (executable)
index 0000000..73f3b33
--- /dev/null
@@ -0,0 +1,29 @@
+#!/bin/bash
+set -eE -o pipefail
+trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
+
+cd /m/md/l/testignore/new
+shopt -s nullglob
+
+last_sec=0
+for file in *; do
+  if [[ $file -nt $latest ]]; then
+    latest=$file
+  fi
+done
+
+if [[ $latest ]]; then
+  last_sec=$(awk '/^Subject: / {print $3}' $latest)
+fi
+
+now=$(date +%s)
+limit=$(( now - 60 * 22 ))
+
+if (( last_sec < limit )); then
+  echo $HOSTNAME mailtest failure
+  touch /nocow/mailtest-failure
+else
+  rm -f /nocow/mailtest-failure
+fi
+
+find -type f -mtime +1 -delete
index 6c7aabf2bb0a57d6a04f09102002a2d76b1c62dd..f5347208d709726f7913f3a5e2e80e3b54e05ddb 100755 (executable)
@@ -28,7 +28,6 @@ trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
 x="$(readlink -f "$BASH_SOURCE")"; cd ${x%/*}
 
 
-e() { echo "$*"; "$@"; }
-
 # scripts that would interfere with unmounting /a, put them elsewhere
-e install /a/bin/log-quiet/log-once switch-mail-host btrbk-run mount-latest-subvol check-subvol-stale /usr/local/bin
+echo install /a/bin/log-quiet/log-once switch-mail-host btrbk-run mount-latest-subvol check-subvol-stale /usr/local/bin
+install /a/bin/log-quiet/log-once switch-mail-host btrbk-run mount-latest-subvol check-subvol-stale /usr/local/bin
index b8440fbfc7fc3684678f851273128102a238cfe4..058fb4f52d4d56e4894212a2a1d804d4b36f4a05 100755 (executable)
@@ -322,7 +322,7 @@ debconf-set-selections <<EOF
 exim4-config exim4/use_split_config boolean true
 EOF
 
-source /a/bin/bash_unpublished/source-semi-priv
+source /a/bin/bash_unpublished/source-state
 mkdir -p /etc/exim4/conf.d/{main,transport,auth,router}
 
 cat >/etc/exim4/rcpt_local_acl <<'EOF'
@@ -419,7 +419,7 @@ trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
 
 [[ $EUID == 0 ]] || exec sudo "$BASH_SOURCE" "$@"
 
-f=/a/bin/bash_unpublished/source-semi-priv
+f=/a/bin/bash_unpublished/source-state
 if [[ -e $f ]]; then
     source $f
 fi
@@ -543,8 +543,7 @@ exim4-config exim4/mailname string mail.iankelling.org
 # Other destinations for which mail is accepted:
 # iank.bid is for testing
 # mail.iankelling.org is for machines i own
-exim4-config exim4/dc_other_hostnames string *.iankelling.org;iankelling.org;*iank.bid;iank.bid;*zroe.org;zroe.org;*.b8.nz;b8.nz
-
+exim4-config exim4/dc_other_hostnames string *.iankelling.org;iankelling.org;*iank.bid;iank.bid;*zroe.org;zroe.org;*.b8.nz;b8.nz;*.fsf.org;fsf.org
 
 
 
@@ -973,6 +972,17 @@ fi
 systemctl restart exim4
 systemctl enable exim4
 
+
+if [[ $HOSTNAME == $MAIL_HOST ]]; then
+  cat >/etc/cron.d/mailtest <<'EOF'
+*/10 * * * *   iank echo body_test | mail -s "primary_test $(date +%s) $(date +%Y-%m-%dT%H:%M:%S%z)" iank@posteo.de
+2/10 * * * *   root /usr/local/bin/mailtest-check
+EOF
+  cp /a/bin/distro-setup/filesystem/usr/local/bin/mailtest-check /usr/local/bin
+else
+  rm -f /etc/cron.d/mailtest
+fi
+
 # MAIL_HOST also does radicale, and easier to start and stop it here
 # for when MAIL_HOST changes, so radicale gets the synced files and
 # does not stop us from remounting /o.
index ea1d1f89195cc26420e68aa462671d1288eef5c4..5cb226c5676b9539ea96ebab8241b5ccc6ebbec4 100644 (file)
@@ -35,28 +35,13 @@ EOF
 }
 
 
-errcatch() {
-  set -E; shopt -s extdebug
-  _err-trap() {
-    err=$?
-    exec >&2
-    set +x
-    echo "${BASH_SOURCE[1]}:${BASH_LINENO[0]}:in \`$BASH_COMMAND' returned $err"
-    bash-trace 2
-    echo "$0: exiting with code $err"
-    exit $err
-  }
-  trap _err-trap ERR
-  set -o pipefail
-}
-bash-trace() {
-  local -i argc_index=0 frame i start=${1:-1} max_indent=8 indent
+err-bash-trace() {
+  local -i argc_index=0 frame i start=${1:-0} max_indent=8 indent
   local source
   local extdebug=false
   if [[ $(shopt -p extdebug) == *-s* ]]; then
     extdebug=true
   fi
-
   for ((frame=0; frame < ${#FUNCNAME[@]}-1; frame++)); do
     argc=${BASH_ARGC[frame]}
     argc_index+=$argc
@@ -64,7 +49,7 @@ bash-trace() {
     if (( ${#BASH_SOURCE[@]} > 1 )); then
       source="${BASH_SOURCE[frame+1]}:${BASH_LINENO[frame]}:"
     fi
-    indent=$((frame-start+1))
+    indent=$((frame-start + 1))
     indent=$((indent < max_indent ? indent : max_indent))
     printf "%${indent}s↳%sin \`%s" '' "$source" "${FUNCNAME[frame]}"
     if $extdebug; then
@@ -74,8 +59,25 @@ bash-trace() {
     fi
     echo \'
   done
+  return 0
+}
+err-catch() {
+  set -E; shopt -s extdebug
+  _err-trap() {
+    err=$?
+    exec >&2
+    set +x
+    echo "${BASH_SOURCE[1]}:${BASH_LINENO[0]}: \`$BASH_COMMAND' returned $err"
+    err-bash-trace 2
+    set -e # err trap does not work within an error trap
+    "${_errcatch_cleanup[@]:-:}" # note :-: is to be compatible with set -u
+    echo "$0: exiting with code $err"
+    exit $err
+  }
+  trap _err-trap ERR
+  set -o pipefail
 }
-errcatch
+err-catch
 
 tu() {
   while read -r line; do
index 4ce132c3c94452274079ee66917c73b0f50051d7..22ec48eb9c1b8539895a3c36d9fd6cabb5d27c7c 100755 (executable)
@@ -9,8 +9,8 @@ trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
 
 if [[ $1 ]]; then
   new_host=$1
-  sed -ri "s/MAIL_HOST=.*/MAIL_HOST=$new_host/" /a/bin/bash_unpublished/source-semi-priv
-  source /a/bin/bash_unpublished/source-semi-priv
+  sed -ri "s/MAIL_HOST=.*/MAIL_HOST=$new_host/" /a/bin/bash_unpublished/source-state
+  source /a/bin/bash_unpublished/source-state
 fi
 
 if [[ $HOSTNAME == $MAIL_HOST ]]; then
index ba8fde2321caee3450edb466d0236f1d2e585075..3cfaa8225a2b424aed0d33d6f0f54845a401482b 100755 (executable)
@@ -1,8 +1,16 @@
-#!/bin/bash -l
-set -x
+#!/bin/bash
+
 [[ $EUID == 0 ]] || exec sudo -E "$BASH_SOURCE" "$@"
 
+if [[ -e /b/errhandle/err ]]; then
+  source /b/errhandle/err
+else
+  set -eE -o pipefail
+  trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
+fi
 
+source /a/bin/bash_unpublished/source-state
+source /a/bin/distro-functions/src/package-manager-abstractions
 # davdroid setup instructions at the bottom
 
 # main docs:
@@ -25,7 +33,7 @@ fi
 
 d=/etc/systemd/system/radicale.service.d
 mkdir -p $d
-sudo dd of=$d/override.conf <<EOF
+cat >$d/override.conf <<EOF
 [Unit]
 # this unit is configured to start and stop whenever openvpn-client@mail.service
 # does
@@ -36,7 +44,7 @@ After=$vpn_ser@mail.service
 [Install]
 RequiredBy=$vpn_ser@mail.service
 EOF
-ser daemon-reload # not sure this is needed
+systemctl daemon-reload # not sure this is needed
 
 pi-nostart radicale
 
@@ -56,7 +64,7 @@ find /o/radicale -xdev -exec chgrp -h 609 {} +
 # I moved /var/lib/radicale after it's initialization.
 # I did a sudo -u radicale git init in the collections subfolder
 # after it gets created, per the git docs.
-lnf -T /o/radicale /var/lib/radicale
+/a/exe/lnf -T /o/radicale /var/lib/radicale
 
 # from https://www.williamjbowman.com/blog/2015/07/24/setting-up-webdav-caldav-and-carddav-servers/
 
@@ -75,7 +83,8 @@ setini() {
 setini hosts 10.8.0.4:5232 server
 
 if [[ $HOSTNAME == $MAIL_HOST ]]; then
-    sgo radicale
+    systemctl start radicale
+    systemctl enable radicale
 fi
 
 # disable power management feature, set to 240 min sync interval,
index cbb7e69e3d421bbd7af7c26e5a8314a0ff3eeb29..d71d4a8ce4340ab3f57bb8b9f06a84ca89ae3683 100644 (file)
@@ -41,7 +41,7 @@ done
 
 old_host=$1
 new_host=$2
-source /a/bin/bash_unpublished/source-semi-priv
+source /a/bin/bash_unpublished/source-state
 
 if [[ $old_host != $MAIL_HOST ]]; then
   read -p "warning: \$old_host != \$MAIL_HOST: $old_host != $MAIL_HOST, proceed? y/N "
@@ -74,7 +74,7 @@ if timeout -s 9 5 ssh-keyscan -p 2220 -t rsa 10.0.0.1 2>/dev/null | grep -qFx '[
 fi
 echo "$0: at_home = $at_home"
 
-source /a/bin/bash_unpublished/source-semi-priv
+source /a/bin/bash_unpublished/source-state
 #### begin convert private hostnames to public hostnames ####
 #if ! $at_home; then
 #    for var in old_host new_host; do