From: Ian Kelling Date: Mon, 29 Jul 2019 20:51:51 +0000 (-0400) Subject: minor improvements X-Git-Url: https://iankelling.org/git/?p=distro-setup;a=commitdiff_plain;h=f6501ed8450080e799b9293a2b38f3381e791db4 minor improvements --- diff --git a/brc b/brc index ee6ca19..5fb46ac 100644 --- 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 diff --git a/filesystem/etc/cron.d/ian b/filesystem/etc/cron.d/ian index 87b2bc6..2874944 100644 --- a/filesystem/etc/cron.d/ian +++ b/filesystem/etc/cron.d/ian @@ -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 diff --git a/mail-setup b/mail-setup index 9bc36dc..690d17d 100755 --- a/mail-setup +++ b/mail-setup @@ -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 <&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 index 0000000..231e610 --- /dev/null +++ b/system-status @@ -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