minor improvements
authorIan Kelling <ian@iankelling.org>
Mon, 29 Jul 2019 20:51:51 +0000 (16:51 -0400)
committerIan Kelling <ian@iankelling.org>
Mon, 29 Jul 2019 20:51:51 +0000 (16:51 -0400)
brc
filesystem/etc/cron.d/ian
mail-setup
system-status [new file with mode: 0755]

diff --git a/brc b/brc
index ee6ca1995c27321775cbd88f2a4144b45a926875..5fb46ac450959aa36d96908568d25e7fa5c7b104 100644 (file)
--- a/brc
+++ b/brc
@@ -628,6 +628,12 @@ dus() { # du, sorted, default arg of
 
 e() { echo "$@"; }
 
+# echo var. print var including escapes, etc
+ev() {
+  printf "%qEOL\n" "${!1}"
+  printf "%s" "${!1}" |& hexdump -C
+}
+
 
 ediff() {
   [[ ${#@} == 2 ]] || { echo "error: ediff requires 2 arguments"; return 1; }
@@ -1435,7 +1441,10 @@ q() { # start / launch a program in the backround and redir output to null
 }
 
 r() {
-  exit "$@" 2>/dev/null
+  histappend -a
+  exit "$@"
+  # i had this redir, not sure why
+#  exit "$@" 2>/dev/null
 }
 
 rbpipe() { rbt post -o --diff-filename=- "$@"; }
@@ -1942,7 +1951,6 @@ psnetns() {
 
 m() { printf "%s\n" "$*";  "$@"; }
 
-
 vpncmd() {
   #m s nsenter -t $(pgrep -f "/usr/sbin/openvpn .* --config /etc/openvpn/.*pia.conf") -n -m "$@"
   m s nsenter -t $(pgrep -f "/usr/sbin/openvpn .* --config /etc/openvpn/.*client.conf") -n -m "$@"
@@ -2081,44 +2089,16 @@ match_lhs=""
 
 if ${use_color} && [[ $- == *i* ]]; then
 
-  if [[ $XTERM_VERSION == Cygwin* ]]; then
-    get_term_color() {
-      for x in "$@"; do
-        case $x in
-         underl) echo -n $'\E[4m' ;;
-         bold) echo -n $'\E[1m' ;;
-         red) echo -n $'\E[31m' ;;
-         green) echo -n $'\E[32m' ;;
-         blue) echo -n $'\E[34m' ;;
-         cyan) echo -n $'\E[36m' ;;
-         yellow) echo -n $'\E[33m' ;;
-         purple) echo -n $'\E[35m' ;;
-         nocolor) echo -n $'\E(B\E[m' ;;
-        esac
-      done
-    }
+  term_underl="$(tput smul)"
+              term_bold="$(tput bold)"
+              term_red="$(tput setaf 1)"
+              term_green="$(tput setaf 2)"
+              term_blue="$(tput setaf 4)"
+              term_cyan="$(tput setaf 6)"
+              term_yellow="$(tput setaf 3)"
+              term_purple="$(tput setaf 5)"
+              term_nocolor="$(tput sgr0)" # no font attributes
 
-  else
-    get_term_color() {
-      for x in "$@"; do
-        case $x in
-         underl) echo -n $(tput smul) ;;
-         bold) echo -n $(tput bold) ;;
-         red) echo -n $(tput setaf 1) ;;
-         green) echo -n $(tput setaf 2) ;;
-         blue) echo -n $(tput setaf 4) ;;
-         cyan) echo -n $(tput setaf 6) ;;
-         yellow) echo -n $(tput setaf 3) ;;
-         purple) echo -n $(tput setaf 5) ;;
-         nocolor) echo -n $(tput sgr0) ;; # no font attributes
-        esac
-      done
-    }
-  fi
-else
-  get_term_color() {
-    :
-  }
 fi
 # Try to keep environment pollution down, EPA loves us.
 unset safe_term match_lhs use_color
@@ -2161,50 +2141,39 @@ if [[ $- == *i* ]]; then
     PS1="\h $PS1"
   fi
 
+  # emacs terminal has problems if this runs slowly,
+  # so I've thrown a bunch of things at the wall to speed it up.
   prompt-command() {
     local return=$? # this MUST COME FIRST
     local psc pst ps_char ps_color stale_subvol
     unset IFS
     history -a # save history
 
-
-
     case $return in
-      0) ps_color="$(get_term_color purple)"
+      0) ps_color="$term_purple"
          ps_char='\$'
          ;;
-      1) ps_color="$(get_term_color green)"
+      1) ps_color="$term_green"
          ps_char="$return \\$"
          ;;
-      *) ps_color="$(get_term_color yellow)"
+      *) ps_color="$term_yellow"
          ps_char="$return \\$"
          ;;
     esac
     if [[ ! -O . ]]; then # not owner
       if [[ -w . ]]; then # writable
-       ps_color="$(get_term_color bold red)"
+       ps_color="$term_bold$term_red"
       else
-       ps_color="$(get_term_color bold green)"
+       ps_color="$term_bold$term_green"
       fi
     fi
-    # I would set nullglob, but bash has had bugs where that
-    # doesnt work if not in top level.
-    if [[ -e /nocow/btrfs-stale ]] && ((`command ls -AUq /nocow/btrfs-stale|wc -l`)); then
-      ps_char="! $ps_char"
-    fi
-    if test -e /m/md/bounces/new/*; then
-      ps_char='!BOUNCE! '"$ps_char"
-    fi
-    if [[ -e /nocow/user/mailtest-failure ]]; then
-      ps_char='!MAILPING! '"$ps_char"
-    fi
-    source /a/bin/bash_unpublished/source-state
+
+    # faster than sourceing the file im guessing
+    eval $(< /dev/shm/iank-status)
     if [[ ! $SSH_CLIENT && $MAIL_HOST != $HOSTNAME ]]; then
       ps_char="@ $ps_char"
     fi
-    PS1="${PS1%"${PS1#*[wW]}"} \[$ps_color\]$ps_char\[$(get_term_color nocolor)\] "
-    # emacs completion doesnt like the git prompt atm, so disabling it.
-    #PS1="${PS1%"${PS1#*[wW]}"}$(__git_ps1 ' (%s)') \[$ps_color\]$ps_char\[$(get_term_color nocolor)\] "
+    PS1="${PS1%"${PS1#*[wW]}"} \[$ps_color\]$ps_char\[$term_nocolor\] "
   }
   PROMPT_COMMAND=prompt-command
 
index 87b2bc6ef9f8cbb3aa8f82a96a5e236868995eec..2874944e9a7a3dfcf65eaf940ee423ebef702e65 100644 (file)
@@ -1,2 +1,4 @@
 SHELL=/bin/bash
 */10 * * * *   iank /a/exe/rootsshsync 2>&1 | /usr/local/bin/log-once -15 rootsshsync
+# this goes into bash prompt, does in cron for more efficient shell
+* * * * *   iank /a/exe/system-status 2>&1 | /usr/local/bin/log-once system-status
index 9bc36dc3d2344ded9374fc29b0d7bf766a828999..690d17daa941028f46bbf8564f7a18fdcbe81fa5 100755 (executable)
@@ -840,6 +840,8 @@ for d in /Maildir /root/Maildir; do
   ln -sf -T /m/md/bounces $d
 done
 
+sudo -u $u ln -sf -T /m/.mu /home/$u/.mu
+
 # put spool dir in directory that spans multiple distros.
 # based on http://www.postfix.org/qmgr.8.html and my notes in gnus
 #
@@ -890,9 +892,9 @@ EOF
   cat >/etc/cron.d/mailtest <<EOF
 SHELL=/bin/bash
 # running as user just because no need to run as root
-*/10 * * * *   $u $f
-*/10 * * * *   $u /usr/local/bin/mailtest-check
-*/10 * * * *   root chmod -R g+rw /m/md/bounces
+*/10 * * * *   $u $f 2>&1 | log-once send-test-forward
+*/10 * * * *   $u /usr/local/bin/mailtest-check 2>&1 | log-once -1 send-test-forward
+*/10 * * * *   root chmod -R g+rw /m/md/bounces 2>&1 | log-once -1 bounces-chmod
 EOF
   cp /a/bin/distro-setup/filesystem/usr/local/bin/mailtest-check /usr/local/bin
 else
diff --git a/system-status b/system-status
new file mode 100755 (executable)
index 0000000..231e610
--- /dev/null
@@ -0,0 +1,41 @@
+#!/bin/bash
+# Copyright (C) 2019 Ian Kelling
+# SPDX-License-Identifier: AGPL-3.0-or-later
+
+if [ -z "$BASH_VERSION" ]; then echo "error: shell is not bash" >&2; exit 1; fi
+
+set -eE -o pipefail
+trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
+
+f=/dev/shm/iank-status
+
+write-status() {
+  chars=()
+
+  if test -e /nocow/btrfs-stale/*; then
+    chars+=("STALE!")
+  fi
+  if test -e /m/md/bounces/new/*; then
+    chars+=("BOUNCE!")
+  fi
+  if [[ -e /nocow/user/mailtest-failure ]]; then
+    chars+=("MAILPING!")
+  fi
+  if [[ -s /var/log/exim4/paniclog ]]; then
+    chars+=("PANIC!")
+  fi
+
+  cat /a/bin/bash_unpublished/source-state >$f
+
+  if [[ $chars ]]; then
+    echo "ps_char=\"${chars[*]} \$ps_char\"" >>$f
+  fi
+}
+write-status
+if [[ $@ ]]; then
+  exit 0
+fi
+for ((i=1; i<=3; i++)); do
+  sleep 15
+  write-status
+done