printf "%s\n" "note: this log file contains logs before those of previous command" | ts "%F %T" | tee -a "$log_path"
fi
}
+# This is an awk script which adds timestamps to those lines that are missing it.
+# It was a very specific/odd situation which drove me to make this. Actually ran
+# it from a file, gawk -F ts.awk (ts.awk had the following string).
+# {
+# if ($0 !~ /^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}/) {
+# print strftime("%Y-%m-%d %H:%M:%S") " - " $0
+# } else {
+# print $0
+# }
+# }
+
# Gets all the essential disk info on a machine. In case it gets ill, this
# a1 = awk {print $1}
for _field in {1..20}; do
- eval a$_field"() { awk '{print \$$_field}'; }"
+ eval a$_field"() { awk '{print \$$_field}' \"\$@\"; }"
done
unset _field
# h1 = head -n1
done
unset _num
+# awk print final field.
+af() {
+ awk '{print $NF}' "$@"
+}
hexipv4() {
# shellcheck disable=SC2046 disable=SC2001 disable=SC2183 # hacks, expected
# wait for PID $1 to die
pidw() {
-local x=$(mktemp); e $pid >$x; pidwait -e -F $x; rm $x
+ local pid="$1"
+ local x=$(mktemp); e $pid >$x; pidwait -e -F $x; rm $x
}
# printf string + newline
#path_add --ifexists --end /a/opt/scancode-toolkit-3.10.
path_add --ifexists --end /p/bin
-### stuff recommended by CPAN. However it is quite annoying that these things blindly
+
+### Commented because I tried a cpan module, but didn't want to keep it, so I removed cpan too,
+### then I found that this was causing problems with my perl.
+###
+### Stuff recommended by CPAN. However it is quite annoying that these things blindly
# add on to existing vars, so if you source this file multiple times, you get crazy long vars.
-# So, I fix.
-path_add --end /home/iank/perl5/bin
-if [[ ! $PERL5LIB ]]; then
- PERL5LIB=/home/iank/perl5/lib/perl5
- PERL_LOCAL_LIB_ROOT=/home/iank/perl5
- PERL_MB_OPT="--install_base /home/iank/perl5"
- PERL_MM_OPT=INSTALL_BASE=/home/iank/perl5
- export PERL5LIB PERL_LOCAL_LIB_ROOT PERL_MB_OPT PERL_MM_OPT
-fi
+# So, I fixed.
+# path_add --end /home/iank/perl5/bin
+# if [[ ! $PERL5LIB ]]; then
+# PERL5LIB=/home/iank/perl5/lib/perl5
+# PERL_LOCAL_LIB_ROOT=/home/iank/perl5
+# PERL_MB_OPT="--install_base /home/iank/perl5"
+# PERL_MM_OPT=INSTALL_BASE=/home/iank/perl5
+# export PERL5LIB PERL_LOCAL_LIB_ROOT PERL_MB_OPT PERL_MM_OPT
+# fi
case $HOSTNAME in
sy|bo)
# When we are setting up a mount namespace, we use this to avoid
# redundant calls of mns-setup
mns-no-setup() {
+ if (( $# < 2 )); then err "need at least 2 arguments"; return 1; fi
local ns
ns=$1
shift
}
mns() { # mount namespace
+ if (( $# < 2 )); then err "need at least 2 arguments"; return 1; fi
local ns
ns=$1
shift
;;
esac
done
+ if (( $# < 2 )); then err "need at least 2 arguments"; return 1; fi
ns=$1
shift
m sudm nsenter --mount=/root/mount_namespaces/$ns sudo -u $user -i "${final_args[@]}"
}
-# Run cmd or shell in named mount namespace + systemd network namespace
+# Run a command in named mount namespace + systemd network namespace
+# Usage: mnsd [OPTIONS] MOUNT_NAMESPACE_NAME SYSTEMD_SERVICE_NAME CMD...
+#
+# See below for options.
+#
mnsd() {
local ns unit user tmpf pre_check pid alt_user=false
local -a final_args
;;
esac
done
+ if (( $# < 3 )); then err "need at least 3 arguments"; return 1; fi
ns=$1
unit=$2
shift 2
EOF
s sysctl -p$t
- }
+}
# just fyi: default rpc port is 9091
tr-config-daemon() {
+ settings_copy=$(mktemp)
+ sudo cat $tconf_dir/settings.json >$settings_copy
d_host_suffix=$(awk '$2 == "'$d_host'" {print $1}' /p/c/host-info)
u ~/.config/transmission-daemon-iank.rb <<EOF
#!/usr/bin/ruby
require 'json'
-p = '$tconf_dir/settings.json'
+p = '$settings_copy'
s = {
'rpc-whitelist' => '',
'rpc-whitelist-enabled' => false,
tmpf=$(mktemp)
# shellcheck disable=SC2024 # false positive
- chmod +x ~/.config/transmission-daemon-iank.rb
- if ! sudo ~/.config/transmission-daemon-iank.rb >$tmpf; then
- echo "iank ruby transmission error" >&2
- return 1
- fi
+ ruby ~/.config/transmission-daemon-iank.rb >$tmpf
# shellcheck disable=SC2154 # false positive
- if ! sudo diff -q $tmpf $tconf_dir/settings.json &>/dev/null; then
+ if ! diff -q $tmpf $settings_copy &>/dev/null; then
restart_ser=false
ser=transmission-daemon-nn
if ser is-active $ser &>/dev/null; then
m ser stop $ser
restart_ser=true
fi
- sudo dd of=$tconf_dir/settings.json <$tmpf 2>/dev/null
+ sudo dd if=$tmpf of=$tconf_dir/settings.json 2>/dev/null
if $restart_ser; then
sudo cat $tconf_dir/settings.json #debug
m ser start $ser
##### postgres #####
ver=18
-if [[ $HOSTNAME == frodo ]]; then
- ver=17
-fi
# based on https://www.postgresql.org/download/linux/ubuntu/
if [[ ! -e /etc/apt/sources.list.d/pgdg.sources ]]; then
pi postgresql-common
sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh -y noble
- pi-nostart postgresql-$ver
+ pi-nostart postgresql-$ver postgresql-doc-$ver
# when we run it, do:
#sudo -u postgres createuser -d iank
sudo usermod -a -G postgres iank
--- /dev/null
+[Unit]
+Description=profanity
+After=local-fs.target
+# on desktop, we need /d to mount, and generally having it start later
+# is find and good and this is the last target.
+After=multi-user.target
+
+[Service]
+# tmux requirement
+Type=forking
+# new-session is a tmux command which allows launching profanity.
+ExecStart=/usr/bin/tmux -L profanity new-session -d profanity
+
+Restart=always
+RestartSec=30
+TimeoutStartSec=300
+
+User=iank
+Group=iank
+
+# note: when running it as a system service instead of a user service, it
+# complains about not being able to connect to gpg on startup. but it
+# seems to work fine.
+
+[Install]
+WantedBy=multi-user.target
shift
fi
-if pgrep -fA '^/bin/bash /usr/local/bin/prof-tail'; then
+if pgrep -fA '^/bin/bash /usr/local/bin/prof-tail' >/dev/null; then
if [[ -t 1 ]]; then
echo "prof-tail already running. exiting"
fi
while true; do
start=$EPOCHSECONDS
if ! ssh-add -l | grep SHA256:YEhwH5u+wkqkSl/dCq8rFebi2qz7Os3RmIWPxMg13eA &>/dev/null; then
- ssh -n prof
+ ssh -l iank -n prof
fi
ssh -l iank -t prof tmux -L profanity a ||:
if (( EPOCHSECONDS > start + 600 )); then
e finished restoring old host as primary, now exiting $ret due to earlier failed btrbk of /o.
exit $ret
fi
-
+_s=$(stty size); c=${_s#* }; while ((c-- >0)); do printf $; done; echo
# new system is usable at this point
-blocks=██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████
-printf "%s\n" "${blocks:0:${COLUMNS:-100}}"
# once I accidentally accepted incoming mail on old host. I used this script to copy over that mail:
#
else
cmd="$BASH_COMMAND"
fi
+ [[ $COLUMNS ]] || { _s=$(stty size); COLUMNS=${_s#* }; }
if [[ $COLUMNS == *[0-9]* ]]; then
# generally fill up 2 rows
col=$(( COLUMNS * 2 - 20 ))
ARRAY /dev/md/pg1 level=raid0 num-devices=4 metadata=1.2 UUID=3bab0b4d:ad7a3136:c75fde32:f4373de1
- devices=/dev/dm-16,/dev/dm-22,/dev/dm-5,/dev/dm-7
ARRAY /dev/md/ndi level=raid0 num-devices=4 metadata=1.2 UUID=693bf056:3875b2bb:7794738b:98914a2c
- #devices=/dev/mapper/int-vgnvme-WD_BLACK_SN850P_for_PS5_8000GB_24517P800200-ndi,/dev/mapper/int-vgnvme-WD_BLACK_SN850X_8000GB_245244802091-ndi,/dev/mapper/int-vgnvme-WD_BLACK_SN850X_8000GB_245244802317-ndi,/dev/mapper/int-vgnvme-WD_BLACK_SN850X_8000GB_25026Y802189-ndi
[Unit]
AssertPathExists=/d/p/profanity
+After=d.mount
--- /dev/null
+[Unit]
+AssertPathExists=/d/tor/.config/transmission-daemon/settings.json
+After=d.mount
+Requires=d.mount
dir=/var/lib/prometheus/node-exporter
path=$dir/mailtest-check.prom.$$
- if $doprom && [[ -e $dir ]]; then
+ if $doprom && [[ -d $dir ]]; then
+ find $dir -type f -mmin +1080 -name 'mailtest-check.prom.*' -delete
for l in "${p_unexpected_spamd_results[@]}"; do
printf "%s\n" "$l" >>$path
done
for l in "${p_last_usec[@]}"; do
printf "%s\n" "$l" >>$path
done
- mv $path $dir/mailtest-check.prom
+ if [[ -s $path ]]; then
+ mv $path $dir/mailtest-check.prom
+ fi
# note: node_textfile_mtime_seconds will tell us when this last happened. useful for debugging.
fi
}
2 screens: Width=1916
2 screens: XPosition=2
2 screens: YPosition=2
-3840x2160 screen: Height=2156
-3840x2160 screen: Width=956
-3840x2160 screen: XPosition=1922
-3840x2160 screen: YPosition=2
+3840x2160 screen: Height=1718
+3840x2160 screen: Width=1276
+3840x2160 screen: XPosition=2562
+3840x2160 screen: YPosition=440
DP-0=DP-0
DP-1 eDP-1=DP-1
DP-1-1 eDP-1=DP-1-1
+++ /dev/null
-[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
-After=local-fs.target
-# on desktop, we need /d to mount, and based on logs, this is the next target after it mounts.
-# However, this does nothing since a user service is blind to system targets.
-After=multi-user.target
-
-Restart=always
-RestartSec=30
-TimeoutStartSec=300
-
-[Service]
-# tmux requirement
-Type=forking
-# new-session is a tmux command which allows launching profanity.
-ExecStart=/usr/bin/tmux -L profanity new-session -d profanity
-
-
-# if we have to move this to a system service:
-#User=iank
-#Group=iank
-
-[Install]
-WantedBy=default.target