From 3f6c5b1f2c72614ee8cb4d0e4325e7beddda9c04 Mon Sep 17 00:00:00 2001 From: Ian Kelling Date: Sun, 15 Oct 2023 20:09:38 -0400 Subject: [PATCH] mostly fixes --- brc | 2 +- brc2 | 34 +++++++++++++---- distro-end | 24 +++++++++--- .../etc/systemd/system/bitcoind.service | 4 ++ .../etc/systemd/system/profanity.service | 12 ------ filesystem/usr/local/bin/myupgrade | 28 ++++++++++++-- i3-sway/common.conf | 5 ++- laptop-xrandr | 11 ++++++ mail-setup | 26 ++++++++++++- prof | 3 +- prof-backup | 2 +- prof-notify | 10 +++++ prof-remote | 5 ++- prof-tail | 38 +++++++++++++++++++ script-files | 2 + sound-alert | 4 ++ subdir_files/.config/dunst/dunstrc | 8 ++++ .../.config/systemd/user/profanity.service | 18 +++++++++ 18 files changed, 200 insertions(+), 36 deletions(-) delete mode 100644 filesystem/etc/systemd/system/profanity.service create mode 100755 laptop-xrandr mode change 100755 => 100644 prof create mode 100644 prof-notify mode change 100755 => 100644 prof-remote create mode 100644 prof-tail create mode 100755 sound-alert create mode 100644 subdir_files/.config/dunst/dunstrc create mode 100644 subdir_files/.config/systemd/user/profanity.service diff --git a/brc b/brc index b2df5c2..b2bac5b 100644 --- a/brc +++ b/brc @@ -2141,7 +2141,7 @@ sk() { local quotes others quotes=2048,2068,2086,2206,2254 - others=2029,2033,2054,2164 + others=2029,2032,2033,2054,2164, shellcheck -W 999 -x -e $quotes,$others "$@" || return $? } # sk with quotes. For checking scripts that we expect to take untrusted diff --git a/brc2 b/brc2 index bad1194..93581a7 100644 --- a/brc2 +++ b/brc2 @@ -1189,7 +1189,7 @@ beet2nav() { # pull in beets library locally beetpull() { - local sshfs_host + local sshfs_host sshfs_cmd sshfs_host=b8.nz if [[ $HOSTNAME == kd ]]; then return 0 @@ -1198,8 +1198,9 @@ beetpull() { s mkdir /i s chown iank:iank /i fi - if ! mountpoint /i &>/dev/null; then - m sshfs $sshfs_host:/i /i + sshfs_cmd="sshfs -o ServerAliveInterval=15,reconnect $sshfs_host:/i /i" + if ! pgrep -f "^$sshfs_cmd$" >/dev/null; then + m $sshfs_cmd fi } @@ -2817,7 +2818,12 @@ myprof() { else i=0 fi - min_date=$(date -d 'monday 2 weeks ago' +%s) + # usually do this on monday, sometimes later + if [[ $(date +%A) == Monday ]]; then + min_date=$(date -d 'monday 2 weeks ago' +%s) + else + min_date=$(date -d 'monday 3 weeks ago' +%s) + fi for (( ; i < logcount; i++ )); do log=${logs[$i]} d=$(date -d "$(head -n1 $log|awk '{print $1}')" +%s) @@ -2831,12 +2837,24 @@ myprof() { popd } -# tail pms in the last day, for the case where we restart profanity and -# didn't check for pms beforehand. -profrecent() { +# Tail pms in the last day, for the case where we restart profanity and +# didn't check for pms beforehand. Assume the most recent logs are on kd. +# If that isn't the case, use prof-recent-local +prof-recent() { + case $HOSTNAME in + kd) + prof-recent-local + ;; + *) + ssh b8.nz prof-recent-local + ;; + esac +} + +prof-recent-local() { local d dates date files f # consider making the day count passed by parameter. note: this works: $(date -d '2 day ago' +%Y_%m_%d) - dates=("$(date -d +%Y_%m_%d)" "$(date -d '1 day ago' +%Y_%m_%d)" ) + dates=("$(date +%Y_%m_%d)" "$(date -d '1 day ago' +%Y_%m_%d)" ) for d in /d/p/profanity/chatlogs/iank_at_fsf.org/!(rooms); do files=() for date in ${dates[@]}; do diff --git a/distro-end b/distro-end index ed90a3f..4389b84 100755 --- a/distro-end +++ b/distro-end @@ -569,15 +569,27 @@ esac ##### begin automatic upgrades (after checkrestart has been installed) #### # if apt-config-auto-update is installed, # it also has similar config, in a file 10something, -# but i think his overrides it since its higher number. +# but i think this overrides it since its higher number. # This file was part of the automatic-updates package, -# and it has a configu option to not get new package lists, +# and it has a config option to not get new package lists, # which seems pretty stupid to me, you cant actually upgrade # anything if you dont have the new package list. sd /etc/apt/apt.conf.d/20auto-upgrades <<'EOF' +# note: man apt.conf says +# /usr/share/doc/apt/examples/configure-index.gz is a configuration file showing +# example values for all possible options. +# but that is a incorrect. +# Periodic and other options are only documented in +# /usr/lib/apt/apt.systemd.daily +# That filename can be found through poking around in apt daily cronjob. APT::Periodic::Update-Package-Lists "1"; APT::Periodic::Download-Upgradeable-Packages "1"; -APT::Periodic::AutocleanInterval "7"; +# 0 means disabled. I used to set this to 7, however, trisquel doesn't +# have an archive of old package versions, so I want to +# keep around old versions so I can easily downgrade. +APT::Periodic::AutocleanInterval "0"; +# daily expire old files /var/cache/apt if it gets above this MB +APT::Periodic::MaxSize "50000"; APT::Periodic::Unattended-Upgrade "1"; EOF @@ -1277,13 +1289,15 @@ fi ####### begin misc packages ########### +# old location, 2023. +sudo rm -fv /etc/systemd/system/profanity.service case $HOSTNAME in kd) ln -sfT /d/p/profanity ~/.local/share/profanity ln -sfT /d/p/profanity-config ~/.config/profanity source /a/bin/bash_unpublished/source-state - if [[ $HOSTNAME == "$HOST2" ]]; then - systemctl --now enable profanity + if [[ $HOSTNAME == "$HOST2" || ! -e /p/profanity-here ]]; then + systemctl --user --now enable profanity fi ;; *) diff --git a/filesystem/etc/systemd/system/bitcoind.service b/filesystem/etc/systemd/system/bitcoind.service index 6697933..5d3206d 100644 --- a/filesystem/etc/systemd/system/bitcoind.service +++ b/filesystem/etc/systemd/system/bitcoind.service @@ -21,6 +21,10 @@ After=network-online.target Wants=network-online.target [Service] +# iank: on a laptop, when it is doing its catchup, it tends to jump +# between 100% and 180% cpu and makes the fan spin annoyingly. Randomly +# trying out 50% to see if it will make the fan quieter. +CPUQuota=50% ExecStart=/usr/bin/bitcoind -daemonwait \ -pid=/run/bitcoind/bitcoind.pid \ -conf=/etc/bitcoin/bitcoin.conf \ diff --git a/filesystem/etc/systemd/system/profanity.service b/filesystem/etc/systemd/system/profanity.service deleted file mode 100644 index b9ecb1b..0000000 --- a/filesystem/etc/systemd/system/profanity.service +++ /dev/null @@ -1,12 +0,0 @@ -[Unit] -Description=profanity -After=network-online.target - -[Service] -# bash is required to get colors working -ExecStart=/usr/bin/screen -S profanity -Dm /bin/bash -c profanity -User=iank -Group=iank - -[Install] -WantedBy=multi-user.target diff --git a/filesystem/usr/local/bin/myupgrade b/filesystem/usr/local/bin/myupgrade index b86e418..939bb6e 100755 --- a/filesystem/usr/local/bin/myupgrade +++ b/filesystem/usr/local/bin/myupgrade @@ -48,7 +48,7 @@ myreboot() { } -case $HOSTNAME in +case $hn in kd) /c/roles/prom/files/simple/usr/local/bin/fsf-install-prometheus /c/roles/prom_export/files/simple/usr/local/bin/fsf-install-node-exporter -l 127.0.0.1 @@ -66,8 +66,30 @@ esac # because rebooting from the script stops the ability to send email. # We should figure some workaround. -if ! out=$(/sbin/needrestart -p 2>&1); then - if [[ $HOSTNAME == "$MAIL_HOST" ]]; then +# I originally had the idea that for MAIL_HOST, I'd just send an email +# if something needs restarting. But atm, I have a bad habit of ignoring +# those emails. + +if ! needrestart -p -k &>/dev/null; then + myreboot +fi + +needrestart -b -l -r a |& logger -t myupgrade +sleep 1 + +# Restart based on library doesnt always work. If we still +# detect outdated libraries after trying to automatically restart, +# then do a reboot unless we are on systems we care a bit more about +# uptime, then send us an email. +# +# Note: I've noticed restart based on library has tended to screw up +# desktop related daemons because they have bugs when restarted in +# isolation instead of as part of bring up and down the whole desktop. +# But, I'd rather something gets messed up than things not get +# restarted. +if ! /sbin/needrestart -p -l &>/dev/null; then + if [[ $hn == "$MAIL_HOST" || $hn == kd ]]; then + # send us an email so we can decide what to do needrestart -r l else myreboot diff --git a/i3-sway/common.conf b/i3-sway/common.conf index 8cfceb7..d7b7745 100644 --- a/i3-sway/common.conf +++ b/i3-sway/common.conf @@ -16,8 +16,9 @@ bindsym $mod+3 exec "abrowser" #bindsym $mod+3 exec "abrowser 2>&1 >/tmp/l" #bindsym $mod+3 exec "abrowser -no-remote -P sfw" bindsym $mod+4 exec "abrowser -no-remote -P firefox-main-profile" -bindsym $mod+5 exec "/usr/local/bin/start-tor-browser" -bindsym $mod+6 exec "/a/bin/redshift.sh" +bindsym $mod+5 exec "/a/bin/ds/laptop-xrandr" +bindsym $mod+6 exec "/usr/local/bin/start-tor-browser" +#bindsym $mod+6 exec "/a/bin/redshift.sh" # bindsym $mod+equal exec "t s w; t in" # bindsym $mod+Home exec "t out" # #bindsym $mod+End exec "t s x; t in" diff --git a/laptop-xrandr b/laptop-xrandr new file mode 100755 index 0000000..8182e44 --- /dev/null +++ b/laptop-xrandr @@ -0,0 +1,11 @@ +#!/bin/bash +set -e; . /usr/local/lib/err; set +e + +# xrandr --auto + +# xrandr --output HDMI2 --right-of eDP1 --mode 3840x2160 + +for i in 1 2 4 5 6 7 8 9 10; do + # if the workspace is already there, this will fail + i3-msg '[workspace="'$i'"]' move workspace to output HDMI2 ||: +done diff --git a/mail-setup b/mail-setup index baca1fc..499bbac 100755 --- a/mail-setup +++ b/mail-setup @@ -3,6 +3,28 @@ # Copyright (C) 2019 Ian Kelling # SPDX-License-Identifier: AGPL-3.0-or-later +# todo: +# on bk (and fsf servers that run multiple exim4 daemons, eg eximfsf2 and eximfsf3), +# make it so that when exim is restarted due to package upgrades, +# we also restart those daemons, which can be done like so, based on looking +# at the prerm and postinst scripts of exim4-daemon-heavy. +# +# if [[ ! -e /usr/sbin/invoke-rc.d-diverted ]]; then +# mv /usr/sbin/invoke-rc.d /usr/sbin/invoke-rc.d-diverted +# dpkg --divert /usr/sbin/invoke-rc.d-diverted --no-rename /usr/sbin/invoke-rc.d +# fi +# /usr/sbin/invoke-rc.d: +# #!/bin/bash +# if [[ DPKG_MAINTSCRIPT_PACKAGE == exim4* && $1 == exim4 ]]; then +# shift +# ret=0 +# for daemon in exim4 eximfsf2 eximfsf3; do +# /usr/sbin/invoke-rc.d-diverted $daemon "$@" || ret=$? +# done +# else +# /usr/sbin/invoke-rc.d-diverted "$@" +# fi + # Things I tend to forget. on MAIL_HOST, daemon runs with /etc/exim4/my.conf, # due to /etc/default/exim4 containing: # COMMONOPTIONS='-C /etc/exim4/my.conf' @@ -218,8 +240,8 @@ fi ####### -# * perstent password instructions -# Note: for cert cron, we need to manually run first to accept known_hosts +# * perstent password instructions Note: for cert cron, we need to +# manually run first to accept known_hosts # # exim passwords: # # for hosts which have all private files I just use the same user diff --git a/prof b/prof old mode 100755 new mode 100644 index cb951d2..35549f5 --- a/prof +++ b/prof @@ -8,7 +8,7 @@ if (( $# >= 1 )); then remote=$1 else remote=b8.nz - if systemctl --quiet is-active profanity || [[ $HOSTNAME == kd ]]; then + if systemctl --user --quiet is-active profanity || [[ $HOSTNAME == kd ]]; then dossh=false fi fi @@ -19,5 +19,6 @@ if $dossh; then export IANK_BASHRC_RUN="prof-remote $remote" konsole --profile profanity else + prof-tail | prof-notify & konsole --profile profanity -e screen -RD -S profanity fi diff --git a/prof-backup b/prof-backup index f5b99bf..7aefc21 100755 --- a/prof-backup +++ b/prof-backup @@ -31,7 +31,7 @@ case $HOSTNAME in fi ;; *) - if ssh b8.nz systemctl --quiet is-active profanity; then + if ssh iank@b8.nz systemctl --user --quiet is-active profanity; then rsync -a b8.nz:/d/p/profanity{,-config} /p fi ;; diff --git a/prof-notify b/prof-notify new file mode 100644 index 0000000..7c550b1 --- /dev/null +++ b/prof-notify @@ -0,0 +1,10 @@ +#!/bin/bash +set -e; . /usr/local/lib/err; set +e + +while read -r line; do + # check that the profanity window is not focused + if ! i3-msg -t get_tree | jq -e '.nodes[].nodes[].nodes[].nodes[] | select(.focused==true and .name=="profanity — Konsole") |.name' &>/dev/null; then + # the profanity tag makes it so new notification replaces old. + dunstify -h string:x-dunst-stack-tag:profanity $line + fi +done diff --git a/prof-remote b/prof-remote old mode 100755 new mode 100644 index d848894..422bb6e --- a/prof-remote +++ b/prof-remote @@ -7,7 +7,10 @@ remote=$1 fastcon=0 while true; do start=$EPOCHSECONDS - ssh -t $remote screen -Dr -S profanity + # -n or else it competes with the other ssh for reading stdin. + ssh -n $remote prof-tail | prof-notify & + ssh -t $remote screen -Dr -S profanity ||: + builtin kill %% &> /dev/null ||: if (( EPOCHSECONDS > start + 600 )); then fastcon=0 fi diff --git a/prof-tail b/prof-tail new file mode 100644 index 0000000..7028ae7 --- /dev/null +++ b/prof-tail @@ -0,0 +1,38 @@ +#!/bin/bash +set -e; . /usr/local/lib/err; set +e + + +xmpp_users=( + anoukr + craigt + dawnbp + devinu + gregf + johnh + jrasata + ksiewicz + michael + miriam + ruben + zoe + jtuttle +) + + +while true; do + midnight=$(date -d '00:00:00 tomorrow' +%s) + secs_till_midnight=$(( midnight - EPOCHSECONDS )) + log_today=$(date '+%Y_%m_%d').log + logdir=/home/iank/.local/share/profanity/chatlogs/iank_at_fsf.org + + timeout --foreground $secs_till_midnight tail -n0 -qF \ + $(for u in ${xmpp_users[@]}; do echo $logdir/${u}_at_fsf.org/$log_today; done) 2>/dev/null \ + | awk '$3 != "me:" {print $3; fflush()}' | sed -u 's/^/pm /;s/@.*//' || [[ $? == 124 ]] & + + timeout --foreground $secs_till_midnight tail -n0 -qF \ + $logdir/rooms/*/$log_today 2>/dev/null \ + | awk '$3 != "iank:"' | grep -i '\biank\b' | awk '{print $3; fflush()}' | sed 's/^/room /;s/@.*//' || [[ $? == 124 ]] + + sleep 1 + +done diff --git a/script-files b/script-files index ce27dcd..89a4277 100644 --- a/script-files +++ b/script-files @@ -20,6 +20,8 @@ my_bin_files=( prof prof-remote prof-backup + prof-tail + prof-notify ) for f in /b/log-quiet/*; do diff --git a/sound-alert b/sound-alert new file mode 100755 index 0000000..ea027f7 --- /dev/null +++ b/sound-alert @@ -0,0 +1,4 @@ +#!/bin/bash +set -e; . /usr/local/lib/err; set +e + +mpv --speed=1 --no-terminal --vo=null --volume=90 /a/bin/data/d20.wav diff --git a/subdir_files/.config/dunst/dunstrc b/subdir_files/.config/dunst/dunstrc new file mode 100644 index 0000000..3463bb0 --- /dev/null +++ b/subdir_files/.config/dunst/dunstrc @@ -0,0 +1,8 @@ +[play_sound] + summary = "*" + script = /b/ds/sound-alert + + +# default light blue is too light +[urgency_normal] + background = "#335EA8" diff --git a/subdir_files/.config/systemd/user/profanity.service b/subdir_files/.config/systemd/user/profanity.service new file mode 100644 index 0000000..ed713cd --- /dev/null +++ b/subdir_files/.config/systemd/user/profanity.service @@ -0,0 +1,18 @@ +[Unit] +Description=profanity +# background: i originally started profanity as a system service after +# networking-online.target but strangely, it had a hidden lock on /p +# preventing it from unmounting, and the only thing in /p i can see it +# using is gpg. I could try to get this to run after the last target, +# which is default.target, but all I can find documented on how to do +# this is to do this strange unexplained thing of making a new target, +# aliasing it to the default target and also make it +# After=default.target. I figured this probably works and is simpler. +After=gpg-agent.service + +[Service] +# bash is required to get colors working +ExecStart=/usr/bin/screen -S profanity -Dm /bin/bash -c profanity + +[Install] +WantedBy=default.target -- 2.30.2