From 103a2e153f844343c359882079936b2521c82f15 Mon Sep 17 00:00:00 2001 From: Ian Kelling Date: Thu, 1 Sep 2022 12:26:37 -0400 Subject: [PATCH] various updates --- brc | 14 +++- brc2 | 32 +++++++- btrbk-run | 45 ++++++++---- btrfsmaint | 11 +-- check-subvol-stale | 2 +- distro-begin | 2 +- distro-end | 9 ++- filesystem/etc/profile.d/environment.sh | 40 +++++----- .../etc/systemd/logind.conf.d/iank.conf | 9 --- mail-setup | 27 +++---- mount-latest-remote | 26 ++++++- mount-latest-subvol | 19 ++++- subdir_files/sieve/lists.sieve | 11 +++ subdir_files/sieve/liststest.sieve | 12 +++ switch-mail-host | 73 ++++++++++++++++--- system-status | 20 ++++- vpn-static-ip | 3 +- 17 files changed, 266 insertions(+), 89 deletions(-) delete mode 100644 filesystem/etc/systemd/logind.conf.d/iank.conf diff --git a/brc b/brc index c3747cf..138fd89 100644 --- a/brc +++ b/brc @@ -468,7 +468,7 @@ ccomp cd c bwm() { s bwm-ng -T avg -d - } +} b() { local topb @@ -1407,7 +1407,15 @@ nags() { } 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() { @@ -1732,7 +1740,7 @@ sk() { 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 $? } diff --git a/brc2 b/brc2 index 3a5ab9d..4877c3f 100644 --- a/brc2 +++ b/brc2 @@ -472,7 +472,7 @@ jrun() { # journal run. run args, log to journal, tail and grep the journal. 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. @@ -1316,6 +1316,26 @@ mdt() { 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 "$@"; } @@ -1873,7 +1893,7 @@ servicepid() { sdnbash() { # systemd namespace bash local unit pid - if (( $# != 0 )); then + if (( $# != 1 )); then echo $0: error wrong number of args >&2 return 1 fi @@ -1884,7 +1904,7 @@ sdnbash() { # systemd namespace bash sdncmd() { # systemd namespace cmd local unit pid - if (( $# != 0 )); then + if (( $# <= 2 )); then echo $0: error wrong number of args >&2 return 1 fi @@ -1986,8 +2006,12 @@ vpn() { } 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 diff --git a/btrbk-run b/btrbk-run index 5d020d7..2e1bc63 100644 --- a/btrbk-run +++ b/btrbk-run @@ -63,7 +63,13 @@ conf_only=false 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 @@ -102,8 +108,8 @@ while true; do # 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 @@ -196,7 +202,8 @@ if [[ ! -v targets && ! $source ]]; then 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 @@ -218,10 +225,13 @@ if [[ ! -v targets && ! $source ]]; then 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) @@ -230,12 +240,21 @@ if [[ ! -v targets && ! $source ]]; then 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 @@ -279,19 +298,19 @@ else 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 diff --git a/btrfsmaint b/btrfsmaint index 6423e26..d226325 100755 --- a/btrfsmaint +++ b/btrfsmaint @@ -46,7 +46,8 @@ usage() { 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. @@ -124,7 +125,7 @@ From: root@$HOSTNAME.b8.nz 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 @@ -175,7 +176,7 @@ EOF 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 @@ -190,8 +191,8 @@ EOF 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 diff --git a/check-subvol-stale b/check-subvol-stale index f012c4f..286f3ba 100644 --- a/check-subvol-stale +++ b/check-subvol-stale @@ -215,7 +215,7 @@ for d; do 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 diff --git a/distro-begin b/distro-begin index d0b03f6..ac86b2d 100755 --- a/distro-begin +++ b/distro-begin @@ -394,7 +394,7 @@ if bitfolk; then 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 diff --git a/distro-end b/distro-end index 09ad1de..a8f5eed 100755 --- a/distro-end +++ b/distro-end @@ -896,7 +896,7 @@ esac ### 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 @@ -929,6 +929,7 @@ EOF fi ;; esac +### end system76 things ### case $distro in trisquel|ubuntu) @@ -997,7 +998,7 @@ EOF ;; jammy) # not yet bothering with mate - pi lightdm-gtk-greeter + pi lightdm-gtk-greeter lightdm ;; esac @@ -1814,6 +1815,10 @@ DEVICESCAN -a -o on -S on -n standby,q $sched \ ########### 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 ||: diff --git a/filesystem/etc/profile.d/environment.sh b/filesystem/etc/profile.d/environment.sh index 9e4feef..f441752 100644 --- a/filesystem/etc/profile.d/environment.sh +++ b/filesystem/etc/profile.d/environment.sh @@ -90,24 +90,26 @@ export GPG_AGENT_INFO=$XDG_RUNTIME_DIR/gnupg/S.gpg-agent:0:1 # 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 @@ -121,7 +123,7 @@ done # 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 diff --git a/filesystem/etc/systemd/logind.conf.d/iank.conf b/filesystem/etc/systemd/logind.conf.d/iank.conf deleted file mode 100644 index 77ced7d..0000000 --- a/filesystem/etc/systemd/logind.conf.d/iank.conf +++ /dev/null @@ -1,9 +0,0 @@ -# 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% diff --git a/mail-setup b/mail-setup index b3cb092..4d69087 100755 --- a/mail-setup +++ b/mail-setup @@ -849,13 +849,16 @@ EOF # * 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 @@ -1369,9 +1372,6 @@ i /etc/exim4/conf.d/transport/30_remote_smtp_vpn <<'EOF' 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 @@ -1427,9 +1427,6 @@ smarthost_dkim: 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}}\ @@ -2747,8 +2744,8 @@ EOF 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 = * diff --git a/mount-latest-remote b/mount-latest-remote index 76c1bef..978b211 100755 --- a/mount-latest-remote +++ b/mount-latest-remote @@ -25,13 +25,35 @@ fi $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 diff --git a/mount-latest-subvol b/mount-latest-subvol index d2e41f3..93a085a 100644 --- a/mount-latest-subvol +++ b/mount-latest-subvol @@ -28,8 +28,8 @@ Usage: ${0##*/} [OPTIONS] -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. @@ -243,6 +243,21 @@ $crypt_dev /q btrfs noatime,subvol=q,gid=1000$mopts 0 0 EOF fi +f=(/mnt/root/btrbk/qr.*); f=${f[0]} +if [[ -e $f ]]; then + fstab <", header :contains "list-id" "", header :contains "list-id" "", + header :contains "list-id" "", header :contains "list-id" "") { if header :regex "list-id" "<([a-z_0-9-]+)[.@]" { set :lower "listname" "${1}"; @@ -119,6 +120,15 @@ if anyof ( stop; } +if anyof ( + header :contains "list-id" "" + ) { + fileinto :create "l/w3c-site-comments"; + stop; +} + + + if anyof ( header :contains "list-id" "<~sircmpwn/sr.ht-discuss.lists.sr.ht>" ) { @@ -145,6 +155,7 @@ if anyof ( header :contains "list-id" "", header :contains "list-id" "", header :contains "list-id" "", + header :contains "list-id" "", header :contains "list-id" "" ) { fileinto :create "community"; diff --git a/subdir_files/sieve/liststest.sieve b/subdir_files/sieve/liststest.sieve index aa7354c..bd31574 100644 --- a/subdir_files/sieve/liststest.sieve +++ b/subdir_files/sieve/liststest.sieve @@ -93,6 +93,7 @@ if anyof ( header :contains "list-id" "", header :contains "list-id" "", header :contains "list-id" "", + header :contains "list-id" "", header :contains "list-id" "") { if header :regex "list-id" "<([a-z_0-9-]+)[.@]" { set :lower "listname" "${1}"; @@ -119,6 +120,15 @@ if anyof ( stop; } +if anyof ( + header :contains "list-id" "" + ) { + fileinto :create "l/w3c-site-comments"; + stop; +} + + + if anyof ( header :contains "list-id" "<~sircmpwn/sr.ht-discuss.lists.sr.ht>" ) { @@ -145,6 +155,8 @@ if anyof ( header :contains "list-id" "", header :contains "list-id" "", header :contains "list-id" "", + header :contains "list-id" "", + header :contains "list-id" "", header :contains "list-id" "" ) { fileinto :create "community"; diff --git a/switch-mail-host b/switch-mail-host index 65ca08d..fd3d032 100644 --- a/switch-mail-host +++ b/switch-mail-host @@ -12,6 +12,8 @@ filesystems unless passing -o. -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 @@ -23,6 +25,8 @@ EOF exit $1 } +script_name="${BASH_SOURCE[0]}" +script_name="${script_name##*/}" restore_new_btrbk=false restore_old_btrbk=false @@ -37,7 +41,7 @@ err-cleanup() { fi } -pre="${0##*/}:" +pre="$script_name:" m() { printf "$pre %s\n" "$*"; "$@"; } e() { printf "$pre %s\n" "$*"; } err() { echo "$pre ERROR: $*" >&2; } @@ -50,6 +54,8 @@ fi ##### 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 @@ -58,7 +64,8 @@ while true; do 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 ;; @@ -74,28 +81,36 @@ if [[ ! $HOSTNAME ]]; then 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 @@ -103,7 +118,28 @@ case $1 in ;; 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." @@ -150,7 +186,8 @@ done # 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 @@ -160,6 +197,9 @@ if pgrep -G iank -u iank -f 'emacs --daemon' &>/dev/null; then 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 @@ -167,6 +207,8 @@ for dir in m o; do 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 @@ -201,9 +243,18 @@ if ! m btrbk-run -v $bbk_args $incremental_arg $mp_args; 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 diff --git a/system-status b/system-status index fc04445..d6874e1 100755 --- a/system-status +++ b/system-status @@ -100,6 +100,24 @@ write-status() { 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 ]] @@ -143,7 +161,7 @@ write-status() { # 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 diff --git a/vpn-static-ip b/vpn-static-ip index 8d04891..bef7933 100755 --- a/vpn-static-ip +++ b/vpn-static-ip @@ -15,9 +15,10 @@ conf=$1 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) } -- 2.30.2