X-Git-Url: https://iankelling.org/git/?a=blobdiff_plain;f=system-status;h=c58d9cea7f6eb3efceae04e08d85c1ce386bfa22;hb=b3e6791bc8673b042e7772516be4de0fc10c0e92;hp=b8e854dbff25b158575aaa99eaadbb21eb734690;hpb=12e7a0f3de4f4f1b1f8e56e7cbe2e972027e0a42;p=distro-setup diff --git a/system-status b/system-status index b8e854d..c58d9ce 100755 --- a/system-status +++ b/system-status @@ -2,7 +2,8 @@ # Copyright (C) 2019 Ian Kelling # SPDX-License-Identifier: AGPL-3.0-or-later -# usage: runs 4 times every 15 seconds unless any args are passed, then just runs once +# usage: runs 4 times every 15 seconds unless any args are passed, or we +# are on battery power, then just runs once. if [ -z "$BASH_VERSION" ]; then echo "error: shell is not bash" >&2; exit 1; fi @@ -12,10 +13,19 @@ status_file=/dev/shm/iank-status shopt -s nullglob shopt -s dotglob +verbose=false +if [[ $1 ]]; then + verbose=true +fi +v() { + if $verbose; then + printf "%s\n" "$*" + fi +} lo() { /usr/local/bin/log-once "$@"; } write-status() { - chars=() + chars=("${first_chars[@]}") glob=(/nocow/btrfs-stale/*) if [[ -e ${glob[0]} ]]; then @@ -35,11 +45,12 @@ write-status() { chars+=("MAILPING!") fi - qlen=$(/usr/sbin/exim -bpc) + qlen=$(/usr/sbin/exiqgrep -o 60 -c -b | awk '{print $1}') if ((qlen)); then chars+=("q $qlen") fi + cd /b/ds if ! make -q ~/.local/distro-begin || [[ $(<~/.local/distro-begin) != 0 ]]; then chars+=("DISTRO-BEGIN!") fi @@ -49,27 +60,51 @@ write-status() { fi f=~/.local/conflink - if [[ -e $f ]]; then - cd /b/ds - now=$(date +%s) - fsec=$(stat -c%Y $f) - fmin=$(( (fsec - now ) / 60 + 1 )) - fminplus=$(( fmin + 60*24 )) - # Filesystem files get copied, so find any newer than the last run. - # The rest are hueristics: - # Given the last time we added a file in git, is that newer than the last conflink run. - # Given new files not added to git, were they modified more recently than the last conflink? but, - # push their modification time back by a day so we can develop them before needing to add them to git. - if (( $(date -d "$(git log --diff-filter=ACR --format=%aD -1)" +%s) > fsec )) || \ - [[ $(find {/a/bin/ds,/p/c}{/filesystem,/machine_specific/$HOSTNAME/filesystem} -mmin $fmin -type f -print -quit 2>/dev/null) ]] \ - || [[ $(find $(git ls-files -o --exclude-standard) -mmin $fminplus -type f -print -quit) ]]; then + for _ in 1; do + if [[ -e $f ]]; then + now=$(date +%s) + fsec=$(stat -c%Y $f) + # the / 60 makes it 0-59 seconds less strict, +1 makes sure we + # dont have any false positives. + fmin=$(( (fsec - now ) / 60 + 1 )) + fminplus=$(( fmin + 60*24 )) + # Filesystem files get copied, so find any newer than the last run. + # The rest are hueristics: + # Given the last time we added a file in git, is that newer than the last conflink run. + # Given new files not added to git, were they modified more recently than the last conflink? but, + # push their modification time back by a day so we can develop them before needing to add them to git. + + all_dirs=({/a/bin/ds,/p/c}{/filesystem,/machine_specific/$HOSTNAME/filesystem}) + # This part is copied from conflink + for x in /p/c/machine_specific/*.hosts /a/bin/ds/machine_specific/*.hosts; do + if grep -qxF $HOSTNAME $x; then all_dirs+=( ${x%.hosts} ); fi + done + + # just because i forget a lot, -mmin -NUM means files modified <= NUM minutes ago + if (( $(date -d "$(git log --diff-filter=ACR --format=%aD -1)" +%s) > fsec )) || \ + [[ $(find ${all_dirs[@]} -mmin $fmin -type f -print -quit 2>/dev/null) ]]; then + v conflink newer git or newer filesystem files + chars+=("CONFLINK!") + break + fi + + for d in /a/bin/distro-setup /p/c; do + cd $d + untracked=$(git ls-files -o --exclude-standard) + if [[ $untracked && $(find $untracked -mmin $fminplus -type f -print -quit) ]]; then + v conflink: untracked in $d + chars+=("CONFLINK!") + break + fi + done + + fi + if [[ ! -e $f || $(<$f) != 0 ]]; then + v conflink: last run not found or failed chars+=("CONFLINK!") + break fi - fi - - if [[ ! -e $f || $(<$f) != 0 ]]; then - chars+=("CONFLINK!") - fi + done ## Clean the paniclog, but only up to 4 times per day, or else we @@ -81,7 +116,7 @@ write-status() { spamcount=0 fi if (( spamcount <= 4 )); then - if grep -q 'spam acl condition' /var/log/exim4/paniclog; then + if grep -q 'spam acl condition' /var/log/exim4/paniclog &>/dev/null; then printf . >>$loglog fi /a/bin/distro-setup/epanic-clean @@ -96,6 +131,7 @@ write-status() { source /a/bin/bash_unpublished/source-state if [[ $MAIL_HOST == "$HOSTNAME" ]]; then + bbkmsg= if [[ $(systemctl is-active btrbk.timer) != active ]]; then chars+=("BTRBK.TIMER!") bbkmsg="btrbk.timer not enabled" @@ -134,11 +170,23 @@ write-status() { fi } +# use this if we want to do something just once per minute +first_chars=() + +power=true +if [[ -e /sys/class/power_supply/AC/online && $(