X-Git-Url: https://iankelling.org/git/?p=distro-setup;a=blobdiff_plain;f=brc2;h=50d51baab5ff3b3b03c98932a5bc0068a4c8235a;hp=56f4db6c860d4ff83bb91a254ab3a0eb683e33cf;hb=a1ebefe19ab910d20fad0c2fd88637fee23dee7c;hpb=7f759d320592e791a62cd0a966350e8c53ee0976 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