X-Git-Url: https://iankelling.org/git/?p=distro-setup;a=blobdiff_plain;f=system-status;h=b3c22e4ea8126f1a24330b039aceef3803ed1d03;hp=e01b15b6346af812f68779b88dcb4d2864f274de;hb=79b274fcd8bfa556133ab13270e84b40aebe8468;hpb=2f7b266e782347022b68c5c8e8fbe9292492c343 diff --git a/system-status b/system-status index e01b15b..b3c22e4 100755 --- a/system-status +++ b/system-status @@ -13,6 +13,15 @@ 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() { @@ -36,41 +45,83 @@ write-status() { chars+=("MAILPING!") fi - qlen=$(/usr/sbin/exim -bpc) + if ! qlen=$(/usr/sbin/exiqgrep -o 60 -c -b | awk '{print $1}'); then + # early in install process, we dont have permission yet for exiqgrep + qlen=$(sudo /usr/sbin/exiqgrep -o 60 -c -b | awk '{print $1}') + fi if ((qlen)); then chars+=("q $qlen") fi + begin=false + cd /b/ds if ! make -q ~/.local/distro-begin || [[ $(<~/.local/distro-begin) != 0 ]]; then - chars+=("DISTRO-BEGIN!") + begin=true fi + end=false if ! make -q ~/.local/distro-end || [[ $(<~/.local/distro-end) != 0 ]]; then + end=true + fi + + if $begin && $end; then + chars+=("DISTRO!") + elif $begin; then + chars+=("DISTRO-BEGIN!") + elif $end; then chars+=("DISTRO-END!") 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 + if [[ ! -e .git ]]; then + # some hosts i dont push all of /p/c + continue + fi + 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 @@ -82,7 +133,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 @@ -123,7 +174,7 @@ write-status() { fi done if (( maxtime < now - 60*60 )); then - chars+=("OLD-SNAPSHOT!") + chars+=("OLD-SNAP!") snapshotmsg="/o snapshot older than 1 hour" fi lo -1 old-snapshot $snapshotmsg @@ -136,6 +187,7 @@ write-status() { fi } +# use this if we want to do something just once per minute first_chars=() power=true @@ -143,22 +195,6 @@ if [[ -e /sys/class/power_supply/AC/online && $(/dev/null) && [[ $c && $c != 0 ]]; then - msg=q:$h=$c - first_chars+=($msg) - fi - if [[ $1 ]]; then - echo q: $h $c - fi - lo -1 remote-mailq $msg - done -fi write-status if [[ $1 ]]; then cat $status_file