various fixes
authorIan Kelling <ian@iankelling.org>
Tue, 29 Dec 2020 23:12:43 +0000 (18:12 -0500)
committerIan Kelling <ian@iankelling.org>
Tue, 29 Dec 2020 23:12:43 +0000 (18:12 -0500)
brc
check-subvol-stale
distro-begin
mail-setup
mailtest-check
mount-latest-subvol
primary-setup
system-status

diff --git a/brc b/brc
index b2eac3f3100dbe27098559c9545ccf08e9af0d93..5579fc48b5104713593d077de1745840af396adb 100644 (file)
--- a/brc
+++ b/brc
@@ -636,10 +636,11 @@ eless() {
 ccomp less eless
 eqcat() {
   exiqgrep -i | while read -r i; do
-    m exim -Mvh $i
-    m exim -Mvb $i
-    hr
-    m exigrep $i /var/log/exim4/mainlog | cat ||:
+    hlm exim -Mvh $i
+    echo
+    hlm exim -Mvb $i
+    echo
+    hlm exigrep $i /var/log/exim4/mainlog | cat ||:
   done
 }
 
@@ -840,6 +841,20 @@ hr() { # horizontal row. used to break up output
   printf "$(tput setaf 5 2>/dev/null ||:)█$(tput sgr0 2>/dev/null||:)%.0s" $(eval echo "{1..${COLUMNS:-60}}")
   echo
 }
+# highlight
+hl() {
+  local col input_len=0
+  for arg; do
+    input_len=$((input_len + 1 + ${#arg}))
+  done
+  col=$((60 - input_len))
+  printf "\e[1;97;41m%s" "$*"
+  if (( col > 0 )); then
+    printf "\e[1;97;41m \e[0m%.0s" $(eval echo "{1..${col}}")
+  fi
+  echo
+}
+hlm() { hl "$*";  "$@"; }
 
 hrcat() { local f; for f; do [[ -f $f ]] || continue; hr; echo "$f"; cat "$f"; done }
 
@@ -1275,10 +1290,14 @@ sgo() { # service go
     ser enable $service
   fi
 }
-soff() { # service go
-  service=$1
-  ser stop $service
-  ser disable $service
+soff () {
+  for service; do
+    # ignore services that dont exist
+    if systemctl cat $service &>/dev/null; then
+      ser stop $service;
+      ser disable $service
+    fi
+  done
 }
 
 sgu() {
@@ -1478,7 +1497,7 @@ sl() {
 
   if $haveinfo && [[ $type == b ]]; then
     info_sec=${tmp::10}
-    read files_sec _ < <(find -L $SL_FILES_DIR -printf "%T@ %p\n" | sort -nr || [[ $? == 141 ]])
+    read files_sec _ < <(find -L $SL_FILES_DIR -printf "%T@ %p\n" | sort -nr || [[ $? == 141 || ${PIPESTATUS[0]} == 32 ]]  )
     files_sec=${files_sec%%.*}
     if (( files_sec > info_sec )); then
       dorsync=true
index 4f489e7c9f0d6100ddd6341029da049c7c063dc0..84530269901dbcf2dc2216cb3bf6d3b27502623e 100644 (file)
@@ -137,7 +137,7 @@ for d; do
       unix_time=$(date -d $(sed -r  's/(.{4})(..)(.{5})(..)(.*)/\1-\2-\3:\4:\5/' <<<${f#$vol.}) +%s)
       printf "%s %s\n" $unix_time $s
       # sort will fail
-    done | sort -r | head -n 1 | awk '{print $2}' || [[ ${PIPESTATUS[1]} == 141 ]]
+    done | sort -r | head -n 1 | awk '{print $2}' || [[ ${PIPESTATUS[1]} == 141 || ${PIPESTATUS[0]} == 32 ]]
            )
   if [[ ! $last_snap ]]; then
     # should not happen.
index 09507192c02fa3ba08753ff71e72aa4aab6ec628..1f1d7bc0d2d1a3067fd173eddadeb2dca5f936cf 100755 (executable)
@@ -334,6 +334,9 @@ if dpkg -s -- nscd &>/dev/null; then
   sudo systemctl stop nscd ||: # fails if already stopped
 fi
 
+# http://strugglers.net/~andy/blog/2020/12/03/starting-services-only-when-the-network-is-ready-on-debiansystemd/
+systemctl enable ifupdown-wait-online.service
+
 if bitfolk; then
   # remove line like this: 85.119.82.128   je.iankelling.org       je
   # it messes with hostname -f.
index 57cc43e9d01ef033b57cd71f1e240e0d2ba2d46b..8dc41f0e57329796e3a102fc5c370742da9d873a 100755 (executable)
@@ -3,6 +3,11 @@
 # Copyright (C) 2019 Ian Kelling
 # SPDX-License-Identifier: AGPL-3.0-or-later
 
+# todo: run mailping test after running, or otherwise
+# clear out terminal alert
+
+# todo: in err can we print out variables?
+
 # todo setup better backup/sync of MAIL_HOST emails
 
 # todo: reinstall bk with bigger filesystem
@@ -262,7 +267,7 @@ fi
 pre="${0##*/}:"
 m() { printf "$pre %s\n"  "$*"; "$@"; }
 e() { printf "$pre %s\n"  "$*"; }
-err() { echo "[$(date +'%Y-%m-%d %H:%M:%S%z')]: $0: $*" >&2; exit 1; }
+err() { printf "$pre %s\n"  "$*" >&2; exit 1; }
 reload=false
 i() { # install file
   local tmp tmpdir dest="$1"
@@ -506,7 +511,7 @@ StartLimitIntervalSec=0
 
 
 [Service]
-Type=oneshot
+Type=simple
 RemainAfterExit=true
 PrivateNetwork=true
 ExecStart=/usr/bin/flock -w 20 /tmp/newns.flock /a/bin/newns/newns -n 10.173.8 start mail
@@ -529,9 +534,7 @@ Wants=network-online.target
 [Service]
 Type=simple
 PrivateNetwork=true
-ExecStartPre=/usr/bin/flock -w 20 /tmp/newns.flock /a/bin/newns/newns -n 10.173.8 start mail
 ExecStart=/bin/sleep infinity
-ExecStopPost=/usr/bin/flock -w 20 /tmp/newns.flock /a/bin/newns/newns stop mail
 
 [Install]
 WantedBy=multi-user.target
@@ -594,6 +597,7 @@ case $HOSTNAME in
   $MAIL_HOST)
     i /etc/systemd/system/unbound.service.d/nn.conf <<EOF
 [Unit]
+After=mailnn.service
 JoinsNamespaceOf=mailnn.service
 BindsTo=mailnn.service
 StartLimitIntervalSec=0
@@ -613,9 +617,8 @@ EOF
     for unit in ${nn_progs[@]}; do
       i /etc/systemd/system/$unit.service.d/nn.conf <<EOF
 [Unit]
-After=network.target
 Requires=mailvpn.service
-After=mailvpn.service
+After=network.target mailnn.service mailvpn.service
 JoinsNamespaceOf=mailnn.service
 BindsTo=mailnn.service
 StartLimitIntervalSec=0
@@ -1028,9 +1031,9 @@ if mailhost; then
 [Unit]
 # this unit is configured to start and stop whenever
 # openvpn-client-mail@mail does
-After=network.target
+After=network.target network-online.target mailnn.service mailvpn.service
+Wants=network-online.target
 BindsTo=mailvpn.service
-After=mailvpn.service
 JoinsNamespaceOf=mailnn.service
 StartLimitIntervalSec=0
 
@@ -1563,7 +1566,7 @@ RewriteRule ^/\.well-known/caldav /nextcloud/remote.php/dav/ [R=301,L]
 ### end nextcloud settings
 EOF
     if [[ ! -e $rcdir/config/secret ]]; then
-      base64 </dev/urandom | head -c24 >$rcdir/config/secret || [[ $? == 141 ]]
+      base64 </dev/urandom | head -c24 >$rcdir/config/secret || [[ $? == 141 || ${PIPESTATUS[0]} == 32 ]]
     fi
     secret=$(cat $rcdir/config/secret)
 
@@ -1816,7 +1819,7 @@ EOF
 \$CONFIG['htaccess.RewriteBase'] = '/nextcloud';
 \$CONFIG['trusted_domains'] = array (
         0 => '$domain',
-    );
+    );s
 #\$CONFIG[''] = '';
 fwrite(STDOUT, "<?php\n\\\$CONFIG = ");
 var_export(\$CONFIG);
@@ -2151,7 +2154,7 @@ dc_eximconfig_configtype='smarthost'
 dc_smarthost='$smarthost'
 EOF
 
-    hostname -A|awk '{print $1}' |i /etc/mailname
+    hostname -f |i /etc/mailname
 
     cat >>/etc/exim4/update-exim4.conf.conf <<EOF
 # The manpage incorrectly states this will do header rewriting, but
@@ -2209,10 +2212,9 @@ if [[ -e /nocow ]]; then
   fi
   i /etc/systemd/system/exim4.service.d/override.conf <<'EOF'
 [Unit]
-# without this on exim, we get these kind of errors in paniclog on shutdown:
+# without local-fs on exim, we get these kind of errors in paniclog on shutdown:
 # Failed to create spool file /var/spool/exim4//input//1jCLxz-0008V4-V9-D: Permission denied
 After=local-fs.target
-After=network.target
 EOF
   if ! mountpoint -q $sdir; then
     stopifactive exim4 exim4in
index 5a58e0774ce5c65b13036b2a6881151827ae0ef5..f2d564da8f434f9b1ea058a45aa5a7bd30407864 100755 (executable)
@@ -29,6 +29,8 @@ fi
 # add any argument to say we are running interactively
 if [[ $SUDO_USER && ! $1 ]]; then
   int=true
+elif [[ $1 ]]; then
+  int=false
 else
   int=false
   sleep 60
index 048c9522e5f73e7d68605d2fca314de33d21924e..c1e5726c43f77943cd5156db0374d6cfa4194173 100644 (file)
@@ -308,8 +308,10 @@ for vol in q a o i; do
       done
       if [[ $bsub ]]; then
         tmp=$(mktemp)
-        # in testing, same subvol is 136 bytes. allow some overhead
-        btrfs send --no-data -p $bsub $leaf | head -c 1000 > $tmp || [[ $? == 141 ]]
+        # in testing, same subvol is 136 bytes. allow some overhead. 32 happens sometimes under systemd.
+        # $ errno 32
+        # EPIPE 32 Broken pipe
+        btrfs send --no-data -p $bsub $leaf | head -c 1000 > $tmp || [[ $? == 141 || ${PIPESTATUS[0]} == 32 ]]
         if (( $(stat -c%s $tmp) < 1000)); then
           # example output for an empty diff:
           # Found a valid Btrfs stream header, version 1
index 9894f3f64cf434bfa0dfbdb92d13992d9066345e..6b294abf2875e677d48ad428b862ea844da57c1a 100755 (executable)
@@ -68,9 +68,13 @@ fi
 # fi
 
 if [[ $HOSTNAME == "$MAIL_HOST" ]]; then
+  m sudo systemctl --user start psd
+  m sudo systemctl --user enable psd
   m sudo systemctl start openvpn-client@hole
   m sudo systemctl enable openvpn-client@hole
 else
+  m sudo systemctl --user stop psd
+  m sudo systemctl --user disable psd
   m sudo systemctl stop openvpn-client@hole
   m sudo systemctl disable openvpn-client@hole
 fi
index eaf35999a3c816fe34cbfe6fd0dc471969bb19af..1167bfd90d642e17196904f245abc92b0a513117 100644 (file)
@@ -215,8 +215,12 @@ write-status() {
     # allow failure in case there are no snapshots yet.
     # shellcheck disable=SC2012
     shopt -u nullglob
-    snaps=($(ls -1avdr /mnt/root/btrbk/$vol.20* 2>/dev/null |head -n1 || : ))
+    files=(/mnt/root/btrbk/$vol.20*)
     shopt -s nullglob
+    snaps=()
+    if (( ${#files[@]} )); then
+      snaps=($(ls -1avdr "${files[@]}" 2>/dev/null |head -n1 || : ))
+    fi
     now=$(date +%s)
     maxtime=0
     for s in ${snaps[@]}; do