From a1ebefe19ab910d20fad0c2fd88637fee23dee7c Mon Sep 17 00:00:00 2001 From: Ian Kelling Date: Fri, 22 Nov 2019 18:57:17 -0500 Subject: [PATCH] various fixes and updates --- brc | 8 +++-- brc2 | 58 +++++++++++++++++++++--------- btrbk-run | 22 ++++++++---- check-subvol-stale | 1 + distro-begin | 11 ++++-- distro-end | 21 +++++++---- fsf-dnsmasq-servers.conf | 8 ----- i3-sway/common.conf | 4 +-- mount-latest-subvol | 2 +- pkgs | 2 ++ subdir_files/.config/i3/config | 4 +-- subdir_files/.config/sway/config | 4 +-- subdir_files/sieve/lists.sieve | 13 +++++++ subdir_files/sieve/liststest.sieve | 13 +++++++ switch-mail-host | 36 +++++++++++-------- 15 files changed, 142 insertions(+), 65 deletions(-) delete mode 100644 fsf-dnsmasq-servers.conf diff --git a/brc b/brc index 51a04dc..118ce01 100644 --- a/brc +++ b/brc @@ -888,7 +888,9 @@ q() { # start / launch a program in the backround and redir output to null # shellcheck disable=SC2120 r() { - history -a # save history + if [[ $HISTFILE ]]; then + history -a # save history + fi trap ERR # this avoids a segfault exit ${1:0} # i had this redir, not sure why @@ -1268,7 +1270,9 @@ if [[ $- == *i* ]]; then local ps_char ps_color unset IFS - history -a # save history + if [[ $HISTFILE ]]; then + history -a # save history + fi case $return in 0) ps_color="$term_purple" diff --git a/brc2 b/brc2 index 56f4db6..50d51ba 100644 --- a/brc2 +++ b/brc2 @@ -140,6 +140,20 @@ bigclock() { xclock -digital -update 1 -face 'arial black-80:bold' } +inttrap() { + pid=$1 + # just passing on -INT doesnt work. + kill -TERM $pid + sleep .05 + if [[ ! -e /proc/$pid ]]; then + if [[ $old_int_trap ]]; then + $old_int_trap + else + trap INT + fi + fi +} + _jrun() { # journal run. run args, log to journal, tail and grep the journal. # Redirect all commands which might have stderr to stdout because of # wrapping. @@ -154,19 +168,25 @@ _jrun() { # journal run. run args, log to journal, tail and grep the journal. cmd_name=${1##*/} systemd-cat -t "$cmd_name" "$@" 2>&1 & pid=$! - sedscript="/$pattern$cmd_name/p;/^.{16}[^ ]+ $cmd_name\[$pid]: $cmd_name: exiting with status [0-9]+\$/q" + old_int_trap="$(trap -p INT)" + # Note, just passing along INT wont actually stop it. + # Oddly, the log says ERROR: /script.sh returned 130 + # but it continues on. + trap "inttrap $pid" INT + sedscript="/$pattern$cmd_name/p;/^.{16}[^ ]+ $cmd_name\[$pid]: ([^ ]*\/)?$cmd_name: exiting with status [0-9]+\$/q" + # debug: + #echo "sedscript: sed -nr '$sedscript'" journalctl -S "4 seconds ago" -f |& sed -nr "$sedscript" 2>&1 & jr_pid=$! wait $pid 2>&1 || ret=$? if (( $ret )); then echo "$0: ERROR: $* returned $ret" fi - jobs %'journalctl -S "4 seconds ago" -f' &>/dev/null ended=false - # give it about 5 seconds to find the end of the log - for (( i=0; i<20; i++ )); do - if jobs %'journalctl -S "4 seconds ago" -f' &>/dev/null; then - sleep .3 2>&1 + # give it 4 seconds to find the end of the log + for (( i=0; i<80; i++ )); do + if [[ -e /proc/$jr_pid ]]; then + sleep .05 2>&1 else ended=true break @@ -175,6 +195,12 @@ _jrun() { # journal run. run args, log to journal, tail and grep the journal. if ! $ended; then kill $jr_pid 2>&1 fi + if [[ $old_int_trap ]]; then + $old_int_trap + else + trap INT + fi + return 0 } jrun() { # ditching stderr avoids the jobs status change output. @@ -182,19 +208,10 @@ jrun() { } sm() { - (( $# == 2 )) || return 1 - action=$1 - shift - host=$1 - shift - case $action in - pull|push) : ;; - *) return 1 ;; - esac c / # run latest install-my-scripts - jrun -p btrbk switch-mail-host $action $host + jrun -p btrbk switch-mail-host "$@" return $ret } @@ -808,7 +825,8 @@ resolvcat() { m s nscd -i hosts f=/etc/resolv.conf echo $f:; ccat $f - hr; m ser status dnsmasq | cat + # this will fail is dnsmasq is failed + hr; m ser status dnsmasq | cat || : hr; s ss -lpn 'sport = 53' #hr; echo dnsmasq is $(systemctl is-active dnsmasq) f=/var/run/dnsmasq/resolv.conf @@ -820,6 +838,10 @@ resolvcat() { rcat() { resolvcat | less } +reresolv() { + sudo nscd -i hosts + sudo systemctl restart dnsmasq +} # only run on MAIL_HOST. simpler to keep this on one system. r2eadd() { # usage: name url @@ -1220,6 +1242,8 @@ wtr() { curl wttr.in/boston; } xevkb() { xev -event keyboard; } +ziva() { e "toot! i love dancing. fart"; } + # * misc stuff # from curl cheat.sh/:bash_completion diff --git a/btrbk-run b/btrbk-run index 3a2d2a4..04a71a8 100644 --- a/btrbk-run +++ b/btrbk-run @@ -66,6 +66,7 @@ dry_run=false # mostly for testing rate_limit=no verbose=true; verbose_arg=-v progress_arg="--progress" +incremental_strict=true pull_reexec=false default_args_file=/etc/btrbk-run.conf @@ -79,7 +80,7 @@ fi cron=false orig_args=("$@") -temp=$(getopt -l cron,pull-reexec,help cl:m:npqs:t:vh "$@") || usage 1 +temp=$(getopt -l cron,pull-reexec,help cil:m:npqs:t:vh "$@") || usage 1 eval set -- "$temp" while true; do case $1 in @@ -90,6 +91,7 @@ while true; do ;; # only creates the config file, does not run btrbk -c) conf_only=true; shift ;; + -i) incremental_strict=false; shift ;; # bytes per second, suffix k m g -l) rate_limit=$2; shift 2 ;; # Comma separated mountpoints to backup. This has defaults set below. @@ -131,6 +133,10 @@ if $verbose; then fi ### end options parsing +if ! btrbk --version |& grep 0.29.0 >/dev/null; then + cd /a/opt/btrbk + m sudo make install +fi # TODO: i wonder if there should be an option to send to the default # targets, plus any given on the command line. @@ -150,8 +156,8 @@ if [[ ! -v targets && ! $source ]]; then ;;& x2|x3) if ping -q -c1 -w1 hal.office.fsf.org \ - && ip n show 192.168.0.26 | grep . &>/dev/null; then - at_work=true + && ip n show 192.168.0.26 | grep . &>/dev/null; then + at_work=true fi ;;& kw|x2|x3) @@ -162,7 +168,7 @@ if [[ ! -v targets && ! $source ]]; then fi ;;& kw) - targets=($home x2) + targets=($home x3) ;; x2|x3) targets=($home kw) @@ -370,9 +376,11 @@ target_preserve_min 4h rate_limit $rate_limit EOF - - - +if $incremental_strict; then + cat >>/etc/btrbk.conf < /etc/hostname hostname -F /etc/hostname fi +# office vpn dhcp adds to /etc/resolv.conf search office.fsf.org which +# makes that be #1 priority, which makes dnsmasq resolve that for +# unqualified hosts first, which means we skip the hosts file. Ya, its +# kinda dumb, but it is what it is. There is a dnsmasq config option to +# override it too, but this seems simpler. sudo sed -i --follow-symlinks -f - /etc/hosts </dev/null <" + ) { + fileinto :create "l/sr.ht-discuss"; + stop; + } + + if anyof ( header :contains "list-id" "", header :contains "list-id" "", @@ -103,6 +113,8 @@ if anyof ( header :contains "list-id" "", header :contains "list-id" "", header :contains "list-id" "", + header :contains "list-id" "", + header :contains "list-id" "", header :contains "from" "", header :contains "list-id" "" ) { @@ -110,6 +122,7 @@ if anyof ( stop; } + if allof ( address :is "from" "mailman-owner@zope.org", header :is "subject" "zope.org mailing list memberships reminder" diff --git a/subdir_files/sieve/liststest.sieve b/subdir_files/sieve/liststest.sieve index 54f617f..00b9443 100644 --- a/subdir_files/sieve/liststest.sieve +++ b/subdir_files/sieve/liststest.sieve @@ -90,6 +90,16 @@ if anyof ( } } + + +if anyof ( + header :contains "list-id" "<~sircmpwn/sr.ht-discuss.lists.sr.ht>" + ) { + fileinto :create "l/sr.ht-discuss"; + stop; + } + + if anyof ( header :contains "list-id" "", header :contains "list-id" "", @@ -103,6 +113,8 @@ if anyof ( header :contains "list-id" "", header :contains "list-id" "", header :contains "list-id" "", + header :contains "list-id" "", + header :contains "list-id" "", header :contains "from" "", header :contains "list-id" "" ) { @@ -110,6 +122,7 @@ if anyof ( stop; } + if allof ( address :is "from" "mailman-owner@zope.org", header :is "subject" "zope.org mailing list memberships reminder" diff --git a/switch-mail-host b/switch-mail-host index eafe104..df0b836 100644 --- a/switch-mail-host +++ b/switch-mail-host @@ -38,16 +38,18 @@ err-cleanup() { pre="${0##*/}:" m() { printf "$pre %s\n" "$*"; "$@"; } e() { printf "$pre %s\n" "$*"; } -err() { echo "$pre: ERROR: $*" >&2; } -mexit() { echo "$pre: exiting with status $1"; exit $1; } +err() { echo "$pre ERROR: $*" >&2; } +mexit() { echo "$pre exiting with status $1"; exit $1; } ##### begin command line parsing ######## -temp=$(getopt -l help owh "$@") || usage 1 +force=false mp_args="-m /o,/q,/a" +temp=$(getopt -l force,help owh "$@") || usage 1 eval set -- "$temp" while true; do case $1 in + --force) force=true ;; -o) mp_args="-m /o"; shift ;; -h|--help) usage ;; --) shift; break ;; @@ -66,8 +68,9 @@ fi case $1 in push) old_host=$HOSTNAME + old_hostname=$HOSTNAME new_host=$2 - bbk_args="-s $old_host" + bbk_args="-t $new_host" new_shell="ssh $new_host" new_hostname=$($new_shell hostname) ;; @@ -75,11 +78,10 @@ case $1 in old_host=$2 new_host=$HOSTNAME new_hostname=$HOSTNAME - bbk_args="-t $new_host" bbk_args="-s $old_host" old_shell="ssh $old_host" - # test ssh connection - $old_shell : + # tests ssh connection + old_hostname=$($old_shell hostname) ;; *) err invalid first argument @@ -89,9 +91,9 @@ esac source /a/bin/bash_unpublished/source-state -if [[ $old_host != "$MAIL_HOST" ]]; then - e "WARNING: \$old_host != \$MAIL_HOST. Sleeping for 5 seconds in case you want to reconsider" - sleep 5 +if [[ $old_hostname != "$MAIL_HOST" ]] && ! $force; then + err "\$old_hostname($old_hostname) != \$MAIL_HOST($MAIL_HOST). Rerun with --force if you really want this." + mexit 1 fi if [[ ! $new_host || ! $old_host ]]; then @@ -112,20 +114,24 @@ if $old_shell systemctl is-active btrbk.timer; then fi btrbk_test="systemctl is-active btrbk.service" -while true; do +active=true +while $active; do + active=false for shell in "$new_shell" "$old_shell"; do e $shell $btrbk_test status=$($shell $btrbk_test) ||: case $status in inactive|failed) : ;; *) + # This covers conditions like "activating", which still return 3 from + # systemctl is-active. + active=true e "btrbk active on shell:$shell, status:$status, sleeping 8 seconds" sleep 8 - continue + break ;; esac done - break done # ensure these are unused before doing anything @@ -162,8 +168,8 @@ fi m $old_shell /a/exe/primary-setup $new_hostname e Running main btrbk -if ! m btrbk-run -v $bbk_args -m /o; then - ret=$? +m btrbk-run -v $bbk_args -m /o || ret=$? +if (( ret )); then bang="$(printf "$(tput setaf 5)█$(tput sgr0)%.0s" 1 2 3 4 5 6 7)" e $bang failed btrbk of /o. restoring old host as primary m $old_shell /a/exe/primary-setup localhost -- 2.30.2