From 9ac513d1086f22a8dede2ebe3ca0236443bdc429 Mon Sep 17 00:00:00 2001 From: Ian Kelling Date: Fri, 7 Apr 2023 23:37:27 -0400 Subject: [PATCH] mostly fixes, some improvements --- beet-data | 171 +++++++++++++++++---------------- brc | 18 ++-- brc2 | 133 ++++++++++++++++++++++--- btrbk-run | 16 ++- conflink | 2 +- distro-end | 3 +- filesystem/usr/local/bin/spend | 6 +- i3-sway/common.conf | 11 +++ mailtest-check | 21 ++-- pkgs | 3 + subdir_files/.gnupg/gpg.conf | 4 +- system-status | 80 +++++++++------ 12 files changed, 309 insertions(+), 159 deletions(-) diff --git a/beet-data b/beet-data index a990308..c030efd 100644 --- a/beet-data +++ b/beet-data @@ -100,58 +100,6 @@ tags=( sad ) - -for g in ${ignore_genres[@]}; do - ignore_genres_a[$g]=t -done -for g in ${slow_genres[@]}; do - slow_genres_a[$g]=t -done - -# genres that have a beat -beat_genres=() -genres=() - - -# relatively upbeat genres to listen, eg while biking -upbeat_genres=() -for g in ${all_genres[@]}; do - if [[ ${ignore_genres_a[$g]} ]]; then continue; fi - genres+=($g) - if [[ ${slow_genres_a[$g]} ]]; then continue; fi - beat_genres+=($g) - case $g in - chill) - continue - ;; - esac - upbeat_genres+=($g) -done - -# generate regex for beat playlist -beat_regex= -first=true -for g in ${beat_genres[@]}; do - if $first; then - first=false - beat_regex=$g - else - beat_regex+="|$g" - fi -done - -# generate regex for upbeat playlist -upbeat_regex= -first=true -for g in ${upbeat_genres[@]}; do - if $first; then - first=false - upbeat_regex=$g - else - upbeat_regex+="|$g" - fi -done - declare -A bpla # beet playlist associative array beetapl() { # beet add playlist local name @@ -160,39 +108,100 @@ beetapl() { # beet add playlist bpla[$name]="${@@Q}" } -for g in ${genres[@]}; do - for r in {3..5}; do + +# this function is just so we can have some local vars +# and not mess with the global var namespace. +_beet-gen-global-vars() { + + local first g t r + + for g in ${ignore_genres[@]}; do + ignore_genres_a[$g]=t + done + for g in ${slow_genres[@]}; do + slow_genres_a[$g]=t + done + + # genres that have a beat + beat_genres=() + genres=() + + + # relatively upbeat genres to listen, eg while biking + upbeat_genres=() + for g in ${all_genres[@]}; do + if [[ ${ignore_genres_a[$g]} ]]; then continue; fi + genres+=($g) + if [[ ${slow_genres_a[$g]} ]]; then continue; fi + beat_genres+=($g) case $g in - pop|rap) - beetapl ${g}-${r} rating:${r}..5 genre::^$g\$ ^expl:t ^gimicky:t ^lesser_version:t - beetapl ${g}-x-${r} rating:${r}..5 genre::^$g\$ ^gimicky:t ^lesser_version:t - ;; - *) - beetapl ${g}-${r} rating:${r}..5 genre:$g ^gimicky:t ^lesser_version:t + chill) + continue ;; esac + upbeat_genres+=($g) + done + + # generate regex for beat playlist + beat_regex= + first=true + for g in ${beat_genres[@]}; do + if $first; then + first=false + beat_regex=$g + else + beat_regex+="|$g" + fi + done + + # generate regex for upbeat playlist + upbeat_regex= + first=true + for g in ${upbeat_genres[@]}; do + if $first; then + first=false + upbeat_regex=$g + else + upbeat_regex+="|$g" + fi + done + + + for g in ${genres[@]}; do + for r in {3..5}; do + case $g in + pop|rap) + beetapl ${g}-${r} rating:${r}..5 genre::^$g\$ ^expl:t ^gimicky:t ^lesser_version:t + beetapl ${g}-x-${r} rating:${r}..5 genre::^$g\$ ^gimicky:t ^lesser_version:t + ;; + *) + beetapl ${g}-${r} rating:${r}..5 genre:$g ^gimicky:t ^lesser_version:t + ;; + esac + done + done + + for t in ${tags[@]}; do + for r in {3..5}; do + beetapl ${t}-${r} rating:${r}..5 $t:t ^lesser_version:t + done done -done -for t in ${tags[@]}; do for r in {3..5}; do - beetapl ${t}-${r} rating:${r}..5 $t:t ^lesser_version:t + beetapl beat-${r} rating:${r}..5 genre::$beat_regex ^expl:t ^gimicky:t ^lesser_version:t + beetapl beat-x-${r} rating:${r}..5 genre::$beat_regex ^gimicky:t ^lesser_version:t + beetapl upbeat-${r} rating:${r}..5 genre::$upbeat_regex ^expl:t ^gimicky:t ^lesser_version:t ^sad:t + beetapl upbeat-x-${r} rating:${r}..5 genre::$upbeat_regex ^gimicky:t ^lesser_version:t ^sad:t + beetapl gimicky-${r} rating:${r}..5 gimicky:t ^lesser_version:t done -done - -for r in {3..5}; do - beetapl beat-${r} rating:${r}..5 genre::$beat_regex ^expl:t ^gimicky:t ^lesser_version:t - beetapl beat-x-${r} rating:${r}..5 genre::$beat_regex ^gimicky:t ^lesser_version:t - beetapl upbeat-${r} rating:${r}..5 genre::$upbeat_regex ^expl:t ^gimicky:t ^lesser_version:t ^sad:t - beetapl upbeat-x-${r} rating:${r}..5 genre::$upbeat_regex ^gimicky:t ^lesser_version:t ^sad:t - beetapl gimicky-${r} rating:${r}..5 gimicky:t ^lesser_version:t -done - -for r in {3..5}; do - beetapl \ - sy$r rating:${r}..5 genre::$upbeat_regex ^gimicky:t ^lesser_version:t 'artist:sonic youth' -done - -for t in ${nav_tags[@]}; do - beetapl $t $t:t -done + + for r in {3..5}; do + beetapl \ + sy$r rating:${r}..5 genre::$upbeat_regex ^gimicky:t ^lesser_version:t 'artist:sonic youth' + done + + for t in ${nav_tags[@]}; do + beetapl $t $t:t + done +} +_beet-gen-global-vars diff --git a/brc b/brc index 82b635c..75a7393 100644 --- a/brc +++ b/brc @@ -2581,18 +2581,22 @@ if [[ $- == *i* ]]; then _title_escape="\033]0;" fi + # make the titlebar be the last command and the current directory. settitle () { - # this makes it so we show the current command if - # one is running, otherwise, show nothing - if [[ $1 == prompt-command ]]; then + + # These are some checks to help ensure we dont set the title at + # times that the debug trap is running other than the case we + # want. Some of them might not be needed. + if (( ${#FUNCNAME[@]} != 1 || ${#BASH_ARGC[@]} != 2 || $BASH_SUBSHELL != 0 )); then return 0 fi - if (( ${#BASH_ARGC[@]} == 1 && BASH_SUBSHELL == 0 )); then - echo -ne "$_title_escape ${PWD/#$HOME/~} " - printf "%s" "$*" - echo -ne "\007" + if [[ $1 == prompt-command ]]; then + return 0 fi + echo -ne "$_title_escape ${PWD/#$HOME/~} " + printf "%s" "$*" + echo -ne "\007" } # note, this wont work: diff --git a/brc2 b/brc2 index fa84ca3..73dc3da 100644 --- a/brc2 +++ b/brc2 @@ -290,7 +290,10 @@ tback() { # s sshfs bu@$host:/bu/home/md /bu/mnt -o reconnect,ServerAliveInterval=20,ServerAliveCountMax=30 -o allow_other eqgo() { - enn -M "$(exiqgrep -i -r.\*)" + local -a array tmpstr + tmpstr=$(exiqgrep -i -r.\*) + mapfile -t array <<<"$tmpstr" + enn -M "${array[@]}" } eqgo1() { enn -M "$(exipick -i -r.\*|h1)" @@ -663,13 +666,14 @@ beetag() { local last_genre_i fstring tag id char new_item char_i genre tag remove doplay i j random path local do_rare_genres read_wait help line lsout tmp ls_line skip_lookback local escape_char escaped_input expected_input skip_input_regex right_pad erasable_line seek_sec - local pl_state_path pl_state_dir pl_state_file - local new_random pl_seed_path seed_num seed_file fmt + local pl_state_path pl_state_dir pl_state_file tmpstr + local new_random pl_seed_path seed_num seed_file fmt first_play local -a pl_tags buttons button_map ids tags tmp_tags initial_ls ls_lines paths local -A button_i local -i i j volume scrolled id_count line_int skip_start pre_j_count head_count skip_lookback local -i overflow_lines overflow + first_play=true erasable_line=false escape_char=$(printf "\u1b") scrolled=999 # more than any $LINES @@ -743,7 +747,8 @@ beetag() { # PijokVipiotOzeph is just a random string for a delimiter fmt='%ifdef{rating,$rating }'"$fstring"'$genre | $title - $artist - $album $length $id PijokVipiotOzeph $path' # shellcheck disable=SC2016 # obvious reason - mapfile -t initial_ls < <(beet ls -f "$fmt" "$@" | { if $random; then sort -R --random-source=$pl_seed_path; else cat; fi; } ) + tmpstr=$(beet ls -f "$fmt" "$@" | { if $random; then sort -R --random-source=$pl_seed_path; else cat; fi; } ) + mapfile -t initial_ls <<<"$tmpstr" id_count=${#initial_ls[@]} for line in "${initial_ls[@]}"; do path="${line#*PijokVipiotOzeph }" @@ -786,11 +791,9 @@ beetag() { if $doplay; then #{ mpv --profile=a --volume=$volume --idle 2>&1 & } 2>/dev/null mpv --profile=a --volume=$volume --idle & - # if we dont sleep, we get error like this: + # if we dont sleep, can expect an error like this: # socat[1103381] E connect(5, AF=1 "/tmp/mpvsock", 14): Connection refused - # and strangely, it persists until mpv is restarted. - # .1 sleep was too little. - sleep .2 + sleep .1 fi while true; do @@ -816,7 +819,21 @@ beetag() { #{ mpv --profile=a --volume=$volume "$path" 2>&1 & } 2>/dev/null # old #{ beet play "--args=--volume=$volume" "id:$id" 2>&1 & } 2>/dev/null - mpvrpc '{ "command": ["loadfile", "'"$path"'"] }' + + # on slow systems, we may need to wait like .3 seconds before mpv + # is ready. so impatiently check until it is ready + if $first_play; then + first_play=false + for (( i=0; i<20; i++ )); do + if [[ $(mpvrpco '{ "command": ["get_property", "idle-active"] }' 2>/dev/null | jq .data) == true ]]; then + mpvrpc '{ "command": ["loadfile", "'"$path"'"] }' 2>/dev/null + break + fi + sleep .1 + done + else + mpvrpc '{ "command": ["loadfile", "'"$path"'"] }' + fi erasable_line=false fi while true; do @@ -828,7 +845,8 @@ beetag() { # Automatically skip to the next song if this one ends, unless # we turn off the autoplay. if (( ret == 142 )) || [[ ! $char ]]; then - if jobs -p | grep -q . &>/dev/null; then + if jobs -p | grep -q . &>/dev/null && \ + [[ $(mpvrpco '{ "command": ["get_property", "idle-active"] }' | jq .data) == false ]]; then continue else break @@ -942,7 +960,7 @@ beetag() { read -rsn2 escaped_input skip_input_regex="^[0-9]+$" case $escaped_input in - # up char + # up char: show all the songs, use less '[A') skip_start=0 skip_lookback=5 @@ -1267,7 +1285,7 @@ scr() { # tried to use ceb2txt but it failed because of schema # slightly different than what it expected. cheogram-get-logs() { - adb shell rm -r /storage/emulated/0/Download/Cheogram/Backup + #adb shell rm -r /storage/emulated/0/Download/Cheogram/Backup read -r -p "do cheogram backup on phone, do not enable extra cheogram data. press any key when done" cd /p/cheogram rm -rf Backup b @@ -1298,11 +1316,17 @@ order by timeSent;" mycheologs() { local days q days=${1:-16} - # timezone compared to utc. note: this will need adjustment for spring/fall. - zone_offset=$(( 60 * 60 * 5 )) + # timezone compared to utc. note: this takes the current offset, so if daylight savings change + # happened in the looking back period, this won't account for it. + zone_offset=$(( $( date +%z | sed 's/[^1-9-]*//g' ) * 60 * 60)) + case $zone_offset in + -*) : ;; + *) zone_offset="+ $zone_offset" + esac + echo zone_offset=$zone_offset q=" select - datetime(substr(timeSent,0,11) - $zone_offset, 'unixepoch'), + datetime(substr(timeSent,0,11) $zone_offset, 'unixepoch'), body from messages where timeSent > $(( (EPOCHSECONDS - days * 60 * 60 * 24) * 1000 )) @@ -1973,7 +1997,65 @@ tl() { t s w } -arbttlog() { arbtt-dump "$@" | grep -v '( )\|Current Desktop' | sed -rn '/^[^ ]/{N;s/^(.{21})([0-9]*)[0-9]{3}m.*\(\*/\1\2/;s/^(.{21})[0-9]*.*\(\*/\1/;s/\n//;p}' ; } +focus() { + /p/c/proc/focus/linux-amd64/focus & + watcharb5 + kill %% +} + + +watcharb5() { + local char ret + killall arbtt-capture ||: + rm -f ~/.arbtt/capture.log + arbtt-capture --sample-rate=10 & + clear + while true; do + arb5 + ret=0 + # i first thought to sleep and capture ctrl-c, but it seems we can't + # capture control-c, unless maybe we implement the commands in a + # separate script or maybe add err-cleanup to err. Anyways, this + # method is superior because any single char exits. + read -rsN1 -t 5 char || ret=$? + if (( ret == 142 )) || [[ ! $char ]]; then + # debug + #e ret=$ret char=$char + : + else + killall arbtt-capture ||: + return 0 + fi + clear + done + +} + +arb5() { + local i l sec + i=0 + if [[ ! -e ~/.arbtt/capture.log ]]; then + sleep 5 + fi + # https://stackoverflow.com/questions/56486272/how-to-concat-multiple-fields-to-same-line-with-jq + arbtt-dump -l 30 -t json | jq -r '.[] | [ ( .inactive / 1000 | floor ) , ( .windows[] | select (.active == true) |.title) ] | @tsv' \ + | tac | while read -r sec l; do + if (( i % 6 == 0 && i >= 2 )); then + echo == $(( i / 6 + 1 )) == + fi + if (( sec > 10 )); then + printf "%3d %s\n" $sec "$l" + else + printf " %s\n" "$l" + fi + i=$(( i + 1 )) + done +} + +arbttlog() { + # from the log, show only the currently active window, and the number of + # seconds of input inactivity. + arbtt-dump "$@" | grep -v '( )\|Current Desktop' | sed -rn '/^[^ ]/{N;s/^(.{21})([0-9]*)[0-9]{3}m.*\(\*/\1\2/;s/^(.{21})[0-9]*.*\(\*/\1/;s/\n//;p}' ; } idea() { /a/opt/idea-IC-163.7743.44/bin/idea.sh "$@" & r @@ -3170,6 +3252,25 @@ vspicy() { # usage: VIRSH_DOMAIN wian() { cat-new-files /m/4e/INBOX/new } +wakehours() { + local sec + if (( $# != 1 )) ; then + echo wakehours: error: expected 1 arg, got $# >&2 + return 1 + fi + sec=$(( EPOCHSECONDS - $( date +%s -d $1am ) )) + printf "%d:%02d\n" $(( sec / 60 / 60)) $(( (sec / 60) % 60 )) +} + +calvis() { # calendar visualize + install -m 600 /dev/null /tmp/calendar-bytes + while read l; do + for char in $l; do + printf "\x$(printf "%x" $char)" >>/tmp/calendar-bytes + done + done < <(grep -v '[#-]' /p/calendar-data) + /p/c/proc/calendar/linux-amd64/calendar +} wtr() { curl wttr.in/boston; } diff --git a/btrbk-run b/btrbk-run index 755e5cc..cf7cf83 100644 --- a/btrbk-run +++ b/btrbk-run @@ -261,23 +261,26 @@ if [[ ! -v targets && ! $source ]]; then ;;& *) if $at_home; then - if ! $kd_spread; then + if ! $kd_spread && [[ $HOSTNAME != x3 ]]; then # main work machine if ping -q -c1 -w1 x3.office.fsf.org &>/dev/null; then targets+=(x3.office.fsf.org) + elif ping -q -c1 -w1 $h.b8.nz &>/dev/null; then + # in case we took it home + targets+=(x3.b8.nz) else targets+=(x3wg.b8.nz) fi fi # temporarily disabled while doing recovery -# for h in frodo kd; do + # for h in frodo kd; do for h in kd; do if [[ $HOSTNAME == "$h" ]]; then continue fi targets+=($h.b8.nz) done - for h in x2 x3 sy; do + for h in x2 sy; do if [[ $HOSTNAME == "$h" ]]; then continue fi @@ -347,6 +350,9 @@ else if [[ $HOSTNAME == "$HOST2" ]]; then prospective_mps+=(/a /ar /qr /q) fi + if $kd_spread; then + prospective_mps=(/a /ar /o /qr /q) + fi fi # note: put q last just in case its specific retention options were to # affect other config sections. I havent tested if that is the case. @@ -364,6 +370,10 @@ else done fi +if (( ! ${#mountpoints[@]} )); then + die didnt get mountpoint arg and had no defaults +fi + echo "mountpoints: ${mountpoints[*]}" ##### end command line parsing ######## diff --git a/conflink b/conflink index e5cf3fb..56a251f 100755 --- a/conflink +++ b/conflink @@ -115,7 +115,7 @@ common-file-setup() { # we dont want t, instead c for checksum. # That way we dont set times on directories. # -a = -rlptgoD - cmd=( s rsync -rclpgoDiSAX --chown=root:root + cmd=( s rsync -rclpgoDiSAX --chmod=Dg-s --chown=root:root --exclude=/etc/dovecot/users --exclude='/etc/exim4/passwd*' --exclude='/etc/exim4/*.pem' diff --git a/distro-end b/distro-end index 6f7b871..bcfe627 100755 --- a/distro-end +++ b/distro-end @@ -1687,7 +1687,8 @@ sudo gpasswd -a $USER lpadmin # based on ubuntu wiki # general known for debian/ubuntu, not for fedora m /a/bin/buildscripts/go -m /a/bin/buildscripts/rust +# only needed for rg. cargo takes up 11 gigs, filled up the disk on je. +#m /a/bin/buildscripts/rust m /a/bin/buildscripts/misc m /a/bin/buildscripts/pithosfly #m /a/bin/buildscripts/alacritty diff --git a/filesystem/usr/local/bin/spend b/filesystem/usr/local/bin/spend index 9387339..f4b68b7 100755 --- a/filesystem/usr/local/bin/spend +++ b/filesystem/usr/local/bin/spend @@ -2,8 +2,8 @@ for (( i=0; i<3; i++ )); do systemctl suspend - wall -n spend: $$ suspending in 30 seconds - sleep 30 + echo $$ suspending in 180 seconds + sleep 180 done -wall -n spend: $$ shutdown in 30 seconds +wall -n spend: $$ shutdown in 180 seconds shutdown diff --git a/i3-sway/common.conf b/i3-sway/common.conf index d648272..a12b573 100644 --- a/i3-sway/common.conf +++ b/i3-sway/common.conf @@ -135,3 +135,14 @@ bindsym $mod+End exec /a/opt/clipster/clipster -sp # file:///usr/share/doc/i3-wm/userguide.html#_border_style_for_new_windows new_window none + +# I dont see a way to make processing windows act like normal windows, +# this does it. +# https://unix.stackexchange.com/questions/450700/opening-a-programme-in-a-floating-window-in-i3 +# +# This is the info for a processing window launched from the ide. +# I'm not sure I want it like this, so commenting it out for now. +#for_window [class="processing-core-PApplet" instance="processing-core-PApplet"] floating disable + +# this is the processing window for my app named focus. +for_window [class="focus" instance="focus"] floating disable diff --git a/mailtest-check b/mailtest-check index d5d30aa..4224511 100755 --- a/mailtest-check +++ b/mailtest-check @@ -195,6 +195,10 @@ EOF # it seems like some versions of spamassassin do BODY_SINGLE_WORD, others dont, we dun care. # bayes_00 is a new one indicating ham, we dont care if its missing. BAYES_00|BODY_SINGLE_WORD|FROM_FMBLA_NEWDOM*|autolearn) : ;; + + # These have somewhat randomly been added and removed, resulting in useless alerts, so ignore them. + RCVD_IN_DNSWL_MED|DKIMWL_WL_HIGH) : ;; + SPF_HELO_NEUTRAL) # some of my domains use neutral spf, treat them the same. results[SPF_HELO_PASS]=t @@ -211,12 +215,7 @@ EOF keys=(DKIM_SIGNED DKIM_VALID{,_AU,_EF} SPF_HELO_PASS SPF_PASS TVD_SPACE_RATIO) if [[ $to == *@gnu.org && $from == *@gnu.org ]]; then keys=(ALL_TRUSTED TVD_SPACE_RATIO) - elif [[ $to == *@gnu.org ]]; then - # eggs has RCVD_IN_DNSWL_MED - keys+=(RCVD_IN_DNSWL_MED) - elif [[ $from == *@gnu.org ]]; then - # eggs has this. it used to have DKIMWL_WL_HIGH sometime in 2022 - keys+=(RCVD_IN_DNSWL_MED) + # from eggs had DKIMWL_WL_HIGH sometime in 2022, then DKIMWL_WL_MED unti march 2023 fi for t in ${keys[@]}; do @@ -274,14 +273,10 @@ EOF esac done for miss in ${missing[@]}; do - # We expect dns failures from time to time, so - # we count them separately and alert differently. + # At some point we had annoying dns failures that we couldn't solve so we + # we counted dns fail related results separately and alert differently. + # DKIM_VALID|DKIM_VALID_AU|DKIM_VALID_EF|SPF_HELO_PASS|SPF_PASS| case $miss in - # iank: dns fail - # DKIM_VALID|DKIM_VALID_AU|DKIM_VALID_EF|SPF_HELO_PASS|SPF_PASS| - RCVD_IN_DNSWL_MED|DKIMWL_WL_HIGH) - missing_dnswl+=1 - ;; *) unexpected+=1 ;; diff --git a/pkgs b/pkgs index b5403ba..5b67690 100644 --- a/pkgs +++ b/pkgs @@ -69,6 +69,7 @@ p3=( apt-show-versions aptitude-doc-en arandr + arbtt # dictionary / thesaurus artha asciidoc @@ -223,6 +224,8 @@ p3=( readline-doc rename reportbug + # first exist in t11 afaik + ripgrep rfkill rng-tools rygel diff --git a/subdir_files/.gnupg/gpg.conf b/subdir_files/.gnupg/gpg.conf index 0dbd896..9868101 100644 --- a/subdir_files/.gnupg/gpg.conf +++ b/subdir_files/.gnupg/gpg.conf @@ -39,12 +39,12 @@ default-key B125F60B7B287FF6A2B7DF8F170AF0E2954295DF # DO NOT USE THIS ONE. #keyserver hkp://pool.sks-keyservers.net -keyserver hkp://keys.openpgp.org +#keyserver hkp://keys.openpgp.org #keyserver hkp://pgp.mit.edu #keyserver hkp://keyserver.pgp.com #keyserver hkp://ipv4.pool.sks-keyservers.net #keyserver hkp://keys.gnupg.net -#keyserver hkp://keyserver.ubuntu.com +keyserver hkp://keyserver.ubuntu.com #keyserver hkp://keyring.debian.org #keyserver keyserver.ubuntu.com # more secure hkps, but had problems with my gpg version diff --git a/system-status b/system-status index 09dd469..cd603ca 100755 --- a/system-status +++ b/system-status @@ -123,6 +123,54 @@ write-status() { # /a gets remounted due to btrbk, ignore error code for file doesnt exist source /a/bin/bash_unpublished/source-state || [[ $? == 1 ]] fi + + + ## check if last snapshot was recent + old_snap_limit=$(( 3 * 60 * 60 )) + for vol in a o q; do + case $vol in + o) btrbk_root=/mnt/o/btrbk ;; + *) btrbk_root=/mnt/root/btrbk ;; + esac + # this section generally copied from btrbk scripts, but + # this part modified to speed things up by about half a second. + # I'm not sure if its quite as reliable, but it looks pretty safe. + # Profiled it using time and also adding to the top of the file: + # set -x + # PS4='+ $(date "+%2N") ' + # allow failure in case there are no snapshots yet. + # shellcheck disable=SC2012 + shopt -u nullglob + files=($btrbk_root/$vol.20*) + shopt -s nullglob + snaps=() + if (( ${#files[@]} )); then + snaps=($(ls -1avdr "${files[@]}" 2>/dev/null |head -n1 || : )) + fi + now=$EPOCHSECONDS + maxtime=0 + for s in ${snaps[@]}; do + file=${s##*/} + t=$(date -d $(sed -r 's/(.{4})(..)(.{5})(..)(.*)/\1-\2-\3:\4:\5/' <<<${file#$vol.}) +%s) + if (( t > maxtime )); then + maxtime=$t + fi + done + snapshotmsg= + last_snap_age=$(( now - maxtime )) + last_snap_hours=$(( last_snap_age / 60 / 60 )) + if (( last_snap_age > old_snap_limit )); then + chars+=(OLD-SNAP-${last_snap_hours}h) + snapshotmsg="/$vol snapshot older than 4 hours" + if [[ $MAIL_HOST == "$HOSTNAME" ]]; then + p "$snapshotmsg" | lo -1 old-snapshot + fi + # not bothering to get info on all volumes if we find an old one. + break + fi + done + + if [[ $MAIL_HOST == "$HOSTNAME" ]]; then bouncemsg= @@ -151,38 +199,6 @@ write-status() { fi p "$bbkmsg" | lo -480 btrbk.timer - ## check if last snapshot was within an hour - vol=o - # this section generally copied from btrbk scripts, but - # this part modified to speed things up by about half a second. - # I'm not sure if its quite as reliable, but it looks pretty safe. - # Profiled it using time and also adding to the top of the file: - # set -x - # PS4='+ $(date "+%2N") ' - # allow failure in case there are no snapshots yet. - # shellcheck disable=SC2012 - shopt -u nullglob - files=(/mnt/o/btrbk/$vol.20*) - shopt -s nullglob - snaps=() - if (( ${#files[@]} )); then - snaps=($(ls -1avdr "${files[@]}" 2>/dev/null |head -n1 || : )) - fi - now=$EPOCHSECONDS - maxtime=0 - for s in ${snaps[@]}; do - file=${s##*/} - t=$(date -d $(sed -r 's/(.{4})(..)(.{5})(..)(.*)/\1-\2-\3:\4:\5/' <<<${file#$vol.}) +%s) - if (( t > maxtime )); then - maxtime=$t - fi - done - snapshotmsg= - if (( maxtime < now - 4*60*60 )); then - chars+=(OLD-SNAP) - snapshotmsg="/o snapshot older than 4 hours" - fi - p "$snapshotmsg" | lo -1 old-snapshot # commented out, only using timetrap retrospectively. -- 2.30.2