bwm() {
s bwm-ng -T avg -d
- }
+}
b() {
local topb
}
nmt() {
- s nmtui-connect "$@"
+ # cant use s because sudo -i doesnt work for passwordless sudo command
+ case $EUID in
+ 0)
+ sudo nmtui-connect "$@"
+ ;;
+ *)
+ nmtui-connect "$@"
+ ;;
+ esac
}
nopanic() {
local quotes others
quotes=2048,2068,2086,2206
- others=2029,2033,2164
+ others=2029,2033,2054,2164
shellcheck -W 999 -x -e $quotes,$others "$@" || return $?
}
journalctl -qn2 -f -u "$cmd_name" &
# Guess of time needed to avoid missing initial lines.
# .5 was not reliable. 1 was not reliable. 2 was not reliable
- sleep 3
+ sleep 4
# We kill this in prompt-command for the case that we ctrl-c the
# systemd-cat. i dont know any way to trap ctrl-c and still run the
# normal action for it. There might be a way, unsure.
mo() { xset dpms force off; } # monitor off
+mpvgpu() {
+ # seems to be the best gpu decoding on my nvidia 670.
+ # vlc gets similar or better framerate, but is much darker output on my test movie at least.
+
+
+ case $HOSTNAME in
+ kd)
+ echo 0f | sudo tee -a /sys/kernel/debug/dri/0/pstate
+ ;;
+ esac
+ # going back to the default slow clock, and slower fan:
+ # echo 07 | sudo tee -a /sys/kernel/debug/dri/0/pstate
+ if [[ $DISPLAY ]]; then
+ mpv --vo=vdpau --hwdec=auto "$@"
+ else
+ # waylandvk seems to work the same
+ mpv --gpu-context=wayland --hwdec=auto
+ fi
+}
+
mpvd() {
mpv --profile=d "$@";
}
sdnbash() { # systemd namespace bash
local unit pid
- if (( $# != 0 )); then
+ if (( $# != 1 )); then
echo $0: error wrong number of args >&2
return 1
fi
sdncmd() { # systemd namespace cmd
local unit pid
- if (( $# != 0 )); then
+ if (( $# <= 2 )); then
echo $0: error wrong number of args >&2
return 1
fi
}
fixu() {
+ local stats
ls -lad /run/user/1000
- s chmod 700 /run/user/1000; s chown iank.iank /run/user/1000
+ stats=$(stat -c%a-%g-%u /run/user/1000)
+ if [[ $stats != 700-1000-1000 ]]; then
+ m s chmod 700 /run/user/1000; m s chown iank.iank /run/user/1000
+ fi
}
# systemctl is-enabled / status / cat says nothing, instead theres
dry_run=false # mostly for testing
rate_limit=no
verbose=true; verbose_arg=-v
-progress_arg="--progress"
+if [[ $INVOCATION_ID ]]; then
+ # INVOCATION_ID means running as a systemd service. we cant show progress in this case,
+ # but if we pass the arg, it will insert mbuffer into the command.
+ progress_arg=
+else
+ progress_arg="--progress"
+fi
incremental_strict=false
pull_reexec=false
# Comma separated mountpoints to backup. This has defaults set below.
-m) IFS=, mountpoints=($2); unset IFS; shift 2 ;;
-n) dry_run=true; dry_run_arg=-n; shift ;;
- # show progress
- -p) progress_arg="--progress"; shift ;;
+ # hide progress
+ -p) progress_arg=; shift ;;
# internal option for rerunning under newer SOURCE_HOST version.
--pull-reexec) pull_reexec=true; shift ;;
# quiet
at_work=false
- targets=(frodo.b8.nz)
+ # todo, fix this up once frodo is back
+ # targets=(frodo.b8.nz)
case $HOSTNAME in
x2|kw)
at_work=true
home=b8.nz
fi
;;&
+ x2)
+ targets+=($home)
+ ;;
kw)
targets+=($home x2.office.fsf.org)
;;
- x2|x3|sy|bo)
+ x3|sy|bo)
targets+=($home)
if $at_work; then
targets+=(x2.office.fsf.org x2.b8.nz)
fi
;;
kd)
- targets+=(x2wg.b8.nz x3.b8.nz)
+ if ping -q -c1 -w1 x2.office.fsf.org &>/dev/null; then
+ targets+=(x2.office.fsf.org)
+ else
+ targets+=(x2wg.b8.nz)
+ fi
if ping -q -c1 -w1 sy.b8.nz &>/dev/null; then
targets+=(sy.b8.nz)
else
targets+=(syw.b8.nz)
fi
+ if ping -q -c1 -w1 x3.b8.nz &>/dev/null; then
+ targets+=(x3.b8.nz)
+ else
+ targets+=(x3w.b8.nz)
+ fi
;;
frodo)
# no targets
if [[ $source_host == "$MAIL_HOST" ]]; then
prospective_mps+=(/o)
fi
+ if [[ $source_host == "$HOST2" ]]; then
+ prospective_mps+=(/a /ar /qr /q)
+ fi
else
if [[ $HOSTNAME == "$MAIL_HOST" ]]; then
- # HOST2 is really the mail host if it exists
- if [[ $HOST2 && $HOST2 != "$HOSTNAME" ]]; then
- echo "skipping /o because HOST2 is not us"
- else
- prospective_mps+=(/o)
- fi
+ prospective_mps+=(/o)
+ fi
+ if [[ $HOSTNAME == "$HOST2" ]]; then
+ prospective_mps+=(/a /ar /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.
- prospective_mps+=(/a /ar /qr /q)
;;
esac
fi
Usage: ${0##*/} [ARGS]
Do btrfs maintence or stop if xprintidle shows a user
-force Run regardless of user idle status on all disks.
+force Run regardless of user idle status on all disks and do scrub
+ regardless of when it was last run.
check Only check if an existing maintence should be cancelled due to
nonidle user. Also, runs in a loop every 20 seconds for 10
minutes.
To: alerts@iankelling.org
Subject: btrfsmaintstop: btrfs dev stats -c $mnt
-$(diff -u $stats_path $tmp)
+$(diff -u $stats_path $tmp ||:)
EOF
mv $stats_path $stats_path.1
cat $tmp >$stats_path
sed -rn 's/^\s*scrub started at (.*) and finished.*/\1/p'
)
fi
- if [[ $date ]]; then
+ if ! $force && [[ $date ]]; then
if $dryrun; then
echo "$0: last scrub finish for $mnt: $date"
fi
continue
fi
fi
- # -c 2 -n 4 is from btrfsmaintenance, does ionice
- e btrfs scrub start -Bd -c 2 -n 4 $mnt
+ # btrfsmaintenance does -c 2 -n 4, but I want lowest pri.
+ e btrfs scrub start -Bd -c 3 $mnt
# We normally only do one disk since this is meant to be run while I sleep
# and if we try to do all disks, we invariably end up doing a scrub still
stale=true
# fresh if $svp has $last_snap as a snapshot,
if btrfs sub show $svp 2>/dev/null | sed '0,/^\s*Snapshot(s):/d;s/^\s*//' | \
- grep -xF ${last_snap#$root_dir/} ; then
+ grep -xF ${last_snap#$root_dir/} >/dev/null; then
stale=false
else # or else $svp is a snapshot of $last_snap. we use a uuid
# comparison, which if I remember from the docs, is a bit more
sudo sed -ri "/^127\./n;/[[:space:]]$HOSTNAME\$/d" /etc/hosts
fi
-if isdeb && [[ $(debian-codename) == nabia ]]; then
+if isdeb && [[ $(debian-codename) == aramo ]]; then
sudo dd of=/etc/apt/preferences.d/aramo-jammy-missing <<'EOF'
Package: linux-libc-dev libmysqlclient21
Pin: release n=jammy,o=Ubuntu
### system76 things ###
case $HOSTNAME in
- sy|bo)
+ bo) # sy| sy doesnt seem to really need this.
# note, i stored the initial popos packages at /a/bin/data/popos-pkgs
if [[ ! -e /etc/apt/sources.list.d/system76.list ]]; then
# https://blog.zackad.dev/en/2017/08/17/add-ppa-simple-way.html
fi
;;
esac
+### end system76 things ###
case $distro in
trisquel|ubuntu)
;;
jammy)
# not yet bothering with mate
- pi lightdm-gtk-greeter
+ pi lightdm-gtk-greeter lightdm
;;
esac
########### misc stuff
+rm -fv /home/iank/.mpv/watch_later
+rm -rf /home/iank/.mpv
+
+
if [[ $HOSTNAME != frodo ]]; then
# remove. i moved this into dns
echo | s cedit hole /etc/hosts ||:
# but not override existing things because theres stuff like PWD. This
# doesn't set SSH_AGENT_PID, but apparently its not needed anymore.
# Note: what a huge pita to write this in posix shell.
-if test "$EUID" && [ "$EUID" != 0 ]; then
- _sysenv=$(mktemp)
- _sysenvnames=$(mktemp)
- _unsetnames=$(mktemp)
- if systemctl --user show-environment >$_sysenv 2>/dev/null; then
- grep -o '^[^=]*' $_sysenv | sort > $_sysenvnames
- env -0 | grep -zo '^[^=]*' | xargs -0 printf "%s\n" | sort | \
- comm --nocheck-order -13 - $_sysenvnames >$_unsetnames
- while read -r unsetname; do
- while read -r sysenv; do
- case "$sysenv" in
- "$unsetname"*) eval export "$sysenv" ;;
- esac
- done < $_sysenv
- done < $_unsetnames
- rm -f $_tmpf
- fi
-fi
+# update: disabled this hackery since I'm not using it in t11
+# if test "$EUID" && [ "$EUID" != 0 ]; then
+# _sysenv=$(mktemp)
+# _sysenvnames=$(mktemp)
+# _unsetnames=$(mktemp)
+# if systemctl --user show-environment >$_sysenv 2>/dev/null; then
+# grep -o '^[^=]*' $_sysenv | sort > $_sysenvnames
+# env -0 | grep -zo '^[^=]*' | xargs -0 printf "%s\n" | sort | \
+# comm --nocheck-order -13 - $_sysenvnames >$_unsetnames
+# while read -r unsetname; do
+# while read -r sysenv; do
+# case "$sysenv" in
+# "$unsetname"*) eval export "$sysenv" ;;
+# esac
+# done < $_sysenv
+# done < $_unsetnames
+# rm -f $_tmpf
+# fi
+# fi
+
# and it seems that if we log into mate, it screws up the systemd env var anyways.
for _file in $(pgrep -a '^ssh-agent$' | sed -r 's/.*-a *([^ ]+).*/\1/'); do
if test -O "$_file"; then
# start it all the time for the user. If the var isn't set by the above,
# just set them to the values I know are in the service.
if ! test "$SSH_AUTH_SOCK"; then
- if [ "$EUID" == 0 ]; then
+ if [ "$EUID" = 0 ]; then
export SSH_AUTH_SOCK=/run/openssh_agent
else
export SSH_AUTH_SOCK=/run/user/1000/openssh_agent
+++ /dev/null
-# See logind.conf(5) for details.
-
-# A version of this file is duplicated in fai in order to get the bootstrap
-# distro to stop suspending when the lid is closed.
-[Login]
-HandleLidSwitch=ignore
-# seems like a good idea.
-# https://wiki.archlinux.org/index.php/profile-sync-daemon#I_need_more_memory_to_accommodate_my_profile/profiles_in_/run/user/xxxx._How_can_I_allocate_more?
-RuntimeDirectorySize=50%
# * Update mail cert
-if [[ -e /p/c/filesystem ]]; then
- # note, man openvpn implies we could just call mail-route on vpn startup/shutdown with
- # systemd, buuut it can remake the tun device unexpectedly, i got this in the log
- # after my internet was down for a bit:
- # NOTE: Pulled options changed on restart, will need to close and reopen TUN/TAP device.
- m /a/exe/vpn-mk-client-cert -b mailclient -n mail li.iankelling.org
-fi
+
+
+## needed only for openvpn mail vpn.
+# if [[ -e /p/c/filesystem ]]; then
+# # note, man openvpn implies we could just call mail-route on vpn startup/shutdown with
+# # systemd, buuut it can remake the tun device unexpectedly, i got this in the log
+# # after my internet was down for a bit:
+# # NOTE: Pulled options changed on restart, will need to close and reopen TUN/TAP device.
+# m /a/exe/vpn-mk-client-cert -b mailclient -n mail li.iankelling.org
+# fi
# With openvpn, I didn't get around to persisting the openvpn
# cert/configs into /p/c/machine_specific/bk, so I had this case to
remote_smtp_vpn:
debug_print = "T: remote_smtp_vpn for $local_part@$domain"
driver = smtp
-.ifndef IGNORE_SMTP_LINE_LENGTH_LIMIT
- message_size_limit = ${if > {$max_received_linelength}{998} {1}{0}}
-.endif
.ifdef REMOTE_SMTP_HOSTS_AVOID_TLS
hosts_avoid_tls = REMOTE_SMTP_HOSTS_AVOID_TLS
.endif
debug_print = "T: remote_smtp_smarthost for $local_part@$domain"
driver = smtp
multi_domain
-.ifndef IGNORE_SMTP_LINE_LENGTH_LIMIT
- message_size_limit = ${if > {$max_received_linelength}{998} {1}{0}}
-.endif
hosts_try_auth = <; ${if exists{CONFDIR/passwd.client} \
{\
${lookup{$host}nwildlsearch{CONFDIR/passwd.client}{$host_address}}\
backup_remote:
driver = smtp
multi_domain
-.ifndef IGNORE_SMTP_LINE_LENGTH_LIMIT
- message_size_limit = ${if > {$max_received_linelength}{998} {1}{0}}
+.ifdef IGNORE_SMTP_LINE_LENGTH_LIMIT
+ message_linelength_limit = 1000000
.endif
hosts_require_auth = *
hosts_try_auth = *
$script_dir/install-my-scripts
cd /usr/local
+ecode=0
+failed_hosts=()
+
+# exit code run
+er() {
+ local ret=0
+ "$@" || ret=$?
+ if (( ret )); then
+ echo "$0: failed command: $*"
+ failed_hosts+=($tg)
+ fi
+ if (( ret > ecode )); then
+ ecode=$ret
+ fi
+}
for tg; do
rsynctg=$tg
if [[ $tg == *:* ]]; then
rsynctg="[$tg]"
fi
# R = relative, t = times, O = omit-dir-times, p = perms
- rsync -RtOp bin/{mount-latest-subvol,check-subvol-stale} lib/err "root@$rsynctg:/usr/local"
+ er rsync -RtOp bin/{mount-latest-subvol,check-subvol-stale} lib/err "root@$rsynctg:/usr/local" || continue
# this can hang if we have an old nfs mount
- ssh root@$tg timeout -s 9 600 /usr/local/bin/mount-latest-subvol
+ ssh root@$tg timeout -s 9 600 /usr/local/bin/mount-latest-subvol ||:
done
+
+if (( $# == ${#failed_hosts[@]} )); then
+ echo "$0: error: all hosts failed: $*" >&2
+elif (( ${#failed_hosts[@]} )); then
+ echo "$0: error: some hosts failed: ${failed_hosts[@]}" >&2
+fi
+exit $ecode
-v|--verbose Be more verbose
-Note, at source location, intentionally not executable, run and read
-install-my-scripts.
+Note: In git this is not not executable because it's meant to be installed
+using ./install-my-scripts
Note: Uses util-linux getopt option parsing: spaces between args and
options, short options can be combined, options before args.
EOF
fi
+f=(/mnt/root/btrbk/qr.*); f=${f[0]}
+if [[ -e $f ]]; then
+ fstab <<EOF
+$crypt_dev /qr btrfs noatime,subvol=qr$mopts 0 0
+EOF
+fi
+
+f=(/mnt/root/btrbk/ar.*); f=${f[0]}
+if [[ -e $f ]]; then
+ fstab <<EOF
+$crypt_dev /ar btrfs noatime,subvol=ar,uid=1000,gid=1000$mopts 0 0
+EOF
+fi
+
+
f=(/mnt/o/btrbk/o.*); f=${f[0]}
if [[ -e $f ]]; then
fstab <<EOF
header :contains "list-id" "<emacs-erc.gnu.org>",
header :contains "list-id" "<linux-raid.vger.kernel.org>",
header :contains "list-id" "<mailop.mailop.org>",
+ header :contains "list-id" "<lilypond-devel.gnu.org>",
header :contains "list-id" "<xmonad.haskell.org>") {
if header :regex "list-id" "<([a-z_0-9-]+)[.@]" {
set :lower "listname" "${1}";
stop;
}
+if anyof (
+ header :contains "list-id" "<site-comments.w3.org>"
+ ) {
+ fileinto :create "l/w3c-site-comments";
+ stop;
+}
+
+
+
if anyof (
header :contains "list-id" "<~sircmpwn/sr.ht-discuss.lists.sr.ht>"
) {
header :contains "list-id" "<Spdx-legal.lists.spdx.org>",
header :contains "list-id" "<info-gnu.gnu.org>",
header :contains "list-id" "<gnu-system-discuss.gnu.org>",
+ header :contains "list-id" "<discuss.lists.blu.org>",
header :contains "list-id" "<spdx.lists.spdx.org>"
) {
fileinto :create "community";
header :contains "list-id" "<emacs-erc.gnu.org>",
header :contains "list-id" "<linux-raid.vger.kernel.org>",
header :contains "list-id" "<mailop.mailop.org>",
+ header :contains "list-id" "<lilypond-devel.gnu.org>",
header :contains "list-id" "<xmonad.haskell.org>") {
if header :regex "list-id" "<([a-z_0-9-]+)[.@]" {
set :lower "listname" "${1}";
stop;
}
+if anyof (
+ header :contains "list-id" "<site-comments.w3.org>"
+ ) {
+ fileinto :create "l/w3c-site-comments";
+ stop;
+}
+
+
+
if anyof (
header :contains "list-id" "<~sircmpwn/sr.ht-discuss.lists.sr.ht>"
) {
header :contains "list-id" "<Spdx-legal.lists.spdx.org>",
header :contains "list-id" "<info-gnu.gnu.org>",
header :contains "list-id" "<gnu-system-discuss.gnu.org>",
+ header :contains "list-id" "<discuss.lists.blu.org>",
+ header :contains "list-id" "<announce.lists.blu.org>",
header :contains "list-id" "<spdx.lists.spdx.org>"
) {
fileinto :create "community";
-i Disallow incremental backup.
-o Only btrbk /o, instead of all filesystems.
+--force Run even though our local state does not say that MAIL_HOST is
+ us when pushing or HOST when pulling.
-h|--help Print help and exit.
I used to adjust home network dns so NEW_HOST resolves locally if it is
exit $1
}
+script_name="${BASH_SOURCE[0]}"
+script_name="${script_name##*/}"
restore_new_btrbk=false
restore_old_btrbk=false
fi
}
-pre="${0##*/}:"
+pre="$script_name:"
m() { printf "$pre %s\n" "$*"; "$@"; }
e() { printf "$pre %s\n" "$*"; }
err() { echo "$pre ERROR: $*" >&2; }
##### begin command line parsing ########
+mail_only=false
+host2_only=false
force=false
mp_args="-m /o,/q,/a"
temp=$(getopt -l force,help ioh "$@") || usage 1
case $1 in
--force) force=true ;;
-i) incremental_arg="-i" ;;
- -o) mp_args="-m /o" ;;
+ -o)
+ mail_only=true ;;
-h|--help) usage ;;
--) shift; break ;;
*) echo "$0: Internal error! unexpected args: $*" ; exit 1 ;;
exit 1
fi
-case $1 in
+source /a/bin/bash_unpublished/source-state
+
+direction=$1
+host=$2
+case $direction in
push)
old_host=$HOSTNAME
old_hostname=$HOSTNAME
- new_host=$2
+ new_host=$host
bbk_args="-t $new_host"
new_shell="ssh -F $HOME/.ssh/confighome root@$new_host"
$new_shell -v hostname
new_hostname=$($new_shell hostname)
;;
pull)
- old_host=$2
+ old_host=$host
new_host=$HOSTNAME
new_hostname=$HOSTNAME
bbk_args="-s $old_host"
old_shell="ssh -F $HOME/.ssh/confighome root@$old_host"
- # tests ssh connection
- if ! old_hostname=$($old_shell hostname); then
- echo "retrying failed $old_shell with -v"
+ # tests ssh connection. crafted this to not need to do escape chars
+ f=/a/bin/bash_unpublished/source-state
+ if ! old_info=($($old_shell "hostname; sed -n s,.*MAIL_HOST=,,p $f; sed -n s,.*HOST2=,,p $f")); then
+ echo "$pre: error: failed ssh. retrying failed $old_shell with -v for more info:"
$old_shell -v hostname
exit 1
fi
+ old_hostname=${old_info[0]}
+ MAIL_HOST=${old_info[1]}
+ HOST2=${old_info[2]}
;;
*)
err invalid first argument
;;
esac
-source /a/bin/bash_unpublished/source-state
+case $script_name in
+ switch-mail-host)
+ if [[ $MAIL_HOST != "$HOST2" ]]; then
+ mail_only=true
+ fi
+ ;;
+ switch-host2)
+ host2_only=true
+ ;;
+ *)
+ err unexpected script name
+ ;;
+esac
+
+
+if $mail_only; then
+ mp_args="-m /o"
+elif $host2_only; then
+ mp_args="-m /a,/ar,/q,/qr"
+fi
+
+
if [[ $old_hostname != "$MAIL_HOST" ]] && ! $force; then
err "\$old_hostname($old_hostname) != \$MAIL_HOST($MAIL_HOST). Rerun with --force if you really want this."
# ensure these are unused before doing anything
e "On $new_host: umounting /m and /o, checking emacs"
-$new_shell bash -s <<'EOF'
+{
+ cat <<'EOF'
set -eE
if pgrep -G iank -u iank -f 'emacs --daemon' &>/dev/null; then
export XDG_RUNTIME_DIR=/run/user/1000
exit 1
fi
fi
+EOF
+ if ! $host2_only; then
+ cat <<'EOF'
for dir in m o; do
if mountpoint -q /$dir; then
echo On $new_host: umount /$dir
fi
done
EOF
+ fi
+} | $new_shell bash -s
$old_shell bash -s <<'EOF'
if pgrep -G iank -u iank -f 'emacs --daemon' &>/dev/null; then
exit $ret
fi
+if ! $mail_only; then
+ m $old_shell sed -ri "s/HOST2=.*/HOST2=$new_hostname/" /a/bin/bash_unpublished/source-state
+ m $new_shell sed -ri "s/HOST2=.*/HOST2=$new_hostname/" /a/bin/bash_unpublished/source-state
+fi
+
+if $host2_only; then
+ exit 0
+fi
+
if ! m $old_shell /a/exe/primary-setup $new_hostname; then
ret=$?
- err "failed \$old_shell primary-setup \$new_hostname. fix and rerun switch-mail-host"
+ err "failed \$old_shell primary-setup \$new_hostname. fix and rerun $script_name"
exit $ret
fi
esac
+ # this section copied from servicepid()
+ unit=exim4
+ pid=$(systemctl show --property MainPID --value $unit ||:)
+ case $pid in
+ [1-9]*) : ;;
+ *)
+ dir=/sys/fs/cgroup/system.slice
+ if [[ ! -d $dir ]]; then
+ dir=/sys/fs/cgroup/systemd/system.slice
+ fi;
+ pid=$(head -n1 $dir/${unit%.service}.service/cgroup.procs ||:)
+ ;;
+ esac
+ if [[ ! $pid ]]; then
+ chars+=(EXIM)
+ fi
+
+
if [[ -e /a/bin/bash_unpublished/source-state ]]; then
# /a gets remounted due to btrbk, ignore error code for file doesnt exist
source /a/bin/bash_unpublished/source-state || [[ $? == 1 ]]
# allow failure in case there are no snapshots yet.
# shellcheck disable=SC2012
shopt -u nullglob
- files=(/mnt/root/btrbk/$vol.20*)
+ files=(/mnt/o/btrbk/$vol.20*)
shopt -s nullglob
snaps=()
if (( ${#files[@]} )); then
main() {
while read -r host port; do
while read -r ip; do
+ echo $ip | egrep '[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*' &>/dev/null || continue
printf "remote %s %s\n" "$ip" "$port" >>$conf
ret=0
- done < <(dig +short $host ||:)
+ done < <(timeout -s 9 1 dig +short $host ||:)
done < <(sed -rn 's/^ *# *remote //p' $conf)
}