From 0f9a999aa601cd77343a3e08cf0c6c4f9f943813 Mon Sep 17 00:00:00 2001 From: Ian Kelling Date: Tue, 26 Dec 2023 20:39:30 -0500 Subject: [PATCH] bash-bear rename and a few improvements --- brc | 50 ++++++++++++++++--- brc2 | 8 +++ btrbk-run | 2 +- check-subvol-stale | 2 +- distro-end | 2 +- filesystem/usr/local/bin/irc | 2 +- filesystem/usr/local/bin/myupgrade | 3 +- filesystem/usr/local/bin/myupgrade-iank | 3 +- mail-setup | 49 +++++++++++------- mount-latest-remote | 2 +- mount-latest-subvol | 2 +- nextcloud-setup | 8 +-- primary-setup | 2 +- prof-backup | 3 ++ save-sent | 3 ++ script-files | 1 + .../.local/share/konsole/profileian.profile | 2 +- switch-mail-host | 42 +++++++--------- system-status | 3 +- unsaved-buffers | 13 +++++ zboot | 2 +- ziva-screen | 3 +- 22 files changed, 136 insertions(+), 71 deletions(-) create mode 100755 save-sent create mode 100644 unsaved-buffers diff --git a/brc b/brc index 5aff8e0..a47a6fa 100644 --- a/brc +++ b/brc @@ -14,9 +14,9 @@ if [[ -s /a/bin/bash-bear-trap/bash-bear ]]; then else # bleh shellcheck can't handle disabling in an elif, so nesting this if. # shellcheck disable=SC2154 # set in .bashrc - if [[ -s $bashrc_dir/err ]]; then + if [[ -s $bashrc_dir/bash-bear ]]; then # shellcheck source=/a/bin/bash-bear-trap/bash-bear - source $bashrc_dir/err + source $bashrc_dir/bash-bear fi fi @@ -725,6 +725,7 @@ khcopy() { ssh-copy-id $1 } +# copy path into clipboard a() { local x x=$(readlink -nf "${1:-$PWD}") @@ -1455,13 +1456,22 @@ g() { gp() { cat &>/a/tmp/gtmp g "$@" /a/tmp/gtmp - } - -# like cmd &> tempfile; emacs tempfile -gc() { +} +# g log +#like cmd &> tempfile; emacs tempfile +# +# note: a useful workflow for doing mass replace on my files: +# gc rem REGEX +## remove any false positives, or manually edit them. rename files if needed. +# sedi 's/REGEX/REPLACEMENT/' $(gr '^/' /a/tmp/gtmp) +gl() { "$@" &> /a/tmp/gtmp g /a/tmp/gtmp - } +} +# g command substitution +gc() { + g $("$@") +} # force terminal version gn() { @@ -2801,6 +2811,8 @@ leap-year() { # on-battery on-bat() { if [[ -e /sys/class/power_supply/AC/online && $(&2; exit 1; fi +set -e; . /usr/local/lib/bash-bear; set +e -source /usr/local/lib/bash-bear pre="${0##*/}:" PATH="/sbin:$PATH" m() { printf "$pre %s\n" "$*"; "$@"; } diff --git a/filesystem/usr/local/bin/myupgrade-iank b/filesystem/usr/local/bin/myupgrade-iank index b4cd1a4..c3d6429 100755 --- a/filesystem/usr/local/bin/myupgrade-iank +++ b/filesystem/usr/local/bin/myupgrade-iank @@ -2,9 +2,8 @@ # 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 -e; . /usr/local/lib/bash-bear; set +e -source /usr/local/lib/bash-bear pre="${0##*/}:" m() { printf "$pre %s\n" "$*"; "$@"; } e() { printf "$pre %s\n" "$*"; } diff --git a/mail-setup b/mail-setup index e2f7b21..776f3e6 100755 --- a/mail-setup +++ b/mail-setup @@ -3229,16 +3229,27 @@ MAILDIR_HOME_MAILDIR_LOCATION = /m/md/Sent EOF + # ian: save a copy of sent mail. i thought of other ways to do this, + # for example, to only save sent mail that is not sent from my mail + # client which saves a copy by default, but in the end, it seems + # simplest to turn that off. We want to save external mail sent by + # smarthosts. However, there is one complication: encrypted + # mail. Saving it here just gets us an encrypted copy that we can't + # read. Soo, we could bcc ourselves: then we still have the + # annoyance that it is encrypted so we can't grep it. Or, we could + # hack emacs so that it sends us an unencrypted copy. Turns out that + # the emacs function which saves sent email can also send us a + # copy. But, then we have 3 copies: the encrypted copy exim saves, + # the unencrypted copy exim saves, and the copy emacs saves. Soo, + # we can emacs send a copy directly to the sent alias but only when + # it is not mail_host, and have the exim condition for redirecting a + # copy to the sent alias avoid doing it if it has an emacs user + # agent header. u /etc/exim4/conf.d/router/186_sentarchive_nn <<'EOF' -# ian: save a copy of sent mail. i thought of other ways to -# do this, for example, to only save sent mail that is not sent -# from my mail client which saves a copy by default, but in the -# end, it seems simplest to turn that off. We want to save -# external mail sent by smarthosts. sentarchive_nn: driver = redirect domains = ! +local_domains - condition = ${if !bool{${lookup{$local_part@$domain}lsearch{/etc/exim4/ignore-sent}{true}}}} + condition = ${if and {{!bool{${lookup{$local_part@$domain}lsearch{/etc/exim4/ignore-sent}{true}}}} {!match {$h_user-agent:}{emacs}}}} data = vojdedIdNejyebni@b8.nz unseen EOF @@ -3605,25 +3616,25 @@ sentarchive: driver = redirect domains = ! +local_domains senders = <; *@fsf.org ; *@posteo.net - condition = ${if !bool{${lookup{$local_part@$domain}lsearch{/etc/exim4/ignore-sent}{true}}}} + condition = ${if and {{!bool{${lookup{$local_part@$domain}lsearch{/etc/exim4/ignore-sent}{true}}}} {!match {$h_user-agent:}{emacs}}}} data = vojdedIdNejyebni@b8.nz unseen EOF u /etc/myexim4/conf.d/router/160_backup_redir <<'EOF' backup_redir: -driver = redirect -# i dont email myself from my own machine much, so lets ignore that. -domains = ! +local_domains -senders = <; *@fsf.org ; *@posteo.net -condition = ${if !bool{${lookup{$local_part@$domain}lsearch{/etc/exim4/ignore-sent}{true}}}} -# b is just an arbirary short string -data = b@eximbackup.b8.nz -# note, to test this, i could temporarily allow testignore. -# alerts avoids potential mail loop. -local_parts = ! root : ! testignore : ! alerts : ! daylert -unseen = true -errors_to = alerts@iankelling.org + driver = redirect + # i dont email myself from my own machine much, so lets ignore that. + domains = ! +local_domains + senders = <; *@fsf.org ; *@posteo.net + condition = ${if and {{!bool{${lookup{$local_part@$domain}lsearch{/etc/exim4/ignore-sent}{true}}}} {!match {$h_user-agent:}{emacs}}}} + # b is just an arbirary short string + data = b@eximbackup.b8.nz + # note, to test this, i could temporarily allow testignore. + # alerts avoids potential mail loop. + local_parts = ! root : ! testignore : ! alerts : ! daylert + unseen = true + errors_to = alerts@iankelling.org EOF # for bk, we have a exim4in.service that will do this for us. diff --git a/mount-latest-remote b/mount-latest-remote index c80c003..04ac198 100755 --- a/mount-latest-remote +++ b/mount-latest-remote @@ -16,7 +16,7 @@ # usage: HOST [mount-latest-subvol args] -source /usr/local/lib/bash-bear +set -e; . /usr/local/lib/bash-bear; set +e script_dir=$(dirname $(readlink -f "$BASH_SOURCE")) diff --git a/mount-latest-subvol b/mount-latest-subvol index 13cfc3d..bb93939 100644 --- a/mount-latest-subvol +++ b/mount-latest-subvol @@ -18,7 +18,7 @@ readonly this_file cd / [[ $EUID == 0 ]] || exec sudo -E "$this_file" "$@" -source /usr/local/lib/bash-bear +set -e; . /usr/local/lib/bash-bear; set +e usage() { cat <&2; exit 1; fi source /a/bin/bash-bear-trap/bash-bear source /a/bin/bash_unpublished/source-state +if [[ ! $HOSTNAME ]]; then + HOSTNAME=$(cat /etc/hostname) +fi if [[ $HOSTNAME != "$HOST2" ]]; then exit 0 fi diff --git a/save-sent b/save-sent new file mode 100755 index 0000000..8578e46 --- /dev/null +++ b/save-sent @@ -0,0 +1,3 @@ +#!/bin/bash + +exim -f '<>' vojdedIdNejyebni@b8.nz <"$1" diff --git a/script-files b/script-files index 6ed94b5..b4f8b61 100644 --- a/script-files +++ b/script-files @@ -9,6 +9,7 @@ my_bin_files=( myi3status mailbindwatchdog check-mailq + unsaved-buffers unsaved-buffers.el mail-backup-clean iptables-exim diff --git a/subdir_files/.local/share/konsole/profileian.profile b/subdir_files/.local/share/konsole/profileian.profile index 6e3eb3d..33baf40 100644 --- a/subdir_files/.local/share/konsole/profileian.profile +++ b/subdir_files/.local/share/konsole/profileian.profile @@ -1,6 +1,6 @@ [Appearance] ColorScheme=ianktheme -Font=DejaVu Sans Mono,12,-1,5,50,0,0,0,0,0 +Font=Noto Mono,12,-1,5,50,0,0,0,0,0 [General] LocalTabTitleFormat=%w diff --git a/switch-mail-host b/switch-mail-host index b31ab79..f1cb212 100644 --- a/switch-mail-host +++ b/switch-mail-host @@ -1,6 +1,6 @@ #!/bin/bash -source /usr/local/lib/bash-bear +set -e; . /usr/local/lib/bash-bear; set +e usage() { cat </dev/null; then - bufs="$(sudo -u iank env XDG_RUNTIME_DIR=/run/user/1000 emacsclient --eval "$(cat /a/bin/ds/unsaved-buffers.el)"| sed '/^"nil"$/d;s/^"(/E: /;s/)"$//')" - if [[ $bufs ]]; then - echo "error: on $HOSTNAME, unsaved emacs files: $bufs" >&2 - exit 1 - fi -fi -EOF + cat /usr/local/bin/unsaved-buffers if ! $host2_only; then cat </dev/null; then - bufs="$(sudo -u iank env XDG_RUNTIME_DIR=/run/user/1000 emacsclient --eval "$(cat /a/bin/ds/unsaved-buffers.el)"| sed '/^"nil"$/d;s/^"(/E: /;s/)"$//')" - if [[ $bufs ]]; then - echo "error: on $HOSTNAME, unsaved emacs files: $bufs" >&2 - exit 1 - fi -fi + cat /usr/local/bin/unsaved-buffers - <<'EOF' | $old_shell bash -s # Try to prevent emacs from saving stale data it has in memory to disk. eg: files, recentf list, etc. # But if emacs ignores the signal, let it live. diff --git a/system-status b/system-status index 47d0a67..7a87e6b 100755 --- a/system-status +++ b/system-status @@ -461,7 +461,8 @@ main-loop() { fi case $bat in 100|9?) - bitcoinon & + : + #bitcoinon & ;; esac fi diff --git a/unsaved-buffers b/unsaved-buffers new file mode 100644 index 0000000..095f3ad --- /dev/null +++ b/unsaved-buffers @@ -0,0 +1,13 @@ +#!/bin/bash +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 $?" >&2' ERR +if pgrep -G iank -u iank -f '^emacs --daemon$' &>/dev/null; then + elisp=$(cat /usr/local/bin/unsaved-buffers.el) + emacsout=$(sudo -u iank env XDG_RUNTIME_DIR=/run/user/1000 emacsclient --eval "$elisp") + bufs=$(printf "%s\n" "$emacsout"|sed '/^"nil"$/d;s/^"(/E: /;s/)"$//') + if [[ $bufs ]]; then + echo "error: on $HOSTNAME, unsaved emacs files: $bufs" >&2 + exit 1 + fi +fi diff --git a/zboot b/zboot index e0fcc61..bf9c7c2 100755 --- a/zboot +++ b/zboot @@ -3,7 +3,7 @@ script=$(readlink -f -- "$BASH_SOURCE") [[ $EUID == 0 ]] || exec sudo -E "$script" "$@" -source /usr/local/lib/bash-bear +set -e; . /usr/local/lib/bash-bear; set +e # Explaining this whole thing. The host amy is used by someone else, diff --git a/ziva-screen b/ziva-screen index 5578835..c512673 100755 --- a/ziva-screen +++ b/ziva-screen @@ -2,9 +2,10 @@ # Get screenshots from bow, discard them if they dont change much. -source /usr/local/lib/bash-bear [[ $EUID == 0 ]] || exec sudo -E "${BASH_SOURCE[0]}" "$@" +set -e; . /usr/local/lib/bash-bear; set +e + dest_dir=/d/ziva-log case $HOSTNAME in sy) -- 2.30.2