# jdo = journal do. Run command as transient systemd service, tailing
# its output in the journal until it completes.
#
-# Usage: jdo COMMAND...
+# Usage: jdo [-n UNIT_NAME] COMMAND...
+#
+# UNIT_NAME instead of using COMMAND as unit name, use UNIT_NAME. This is needed
+# in case COMMAND is already a unit.
#
# Compared to pd: commands recognize this is a non-interactive shell.
# The service is unaffected if our ssh connection dies, no need to run
# systemctl daemon-reload, and I've had other approaches. I haven't yet
# really tried logging with script, sudo, or screen.
jdo() {
- local cmd cmd_name jr_pid ret sdrun_args sdrun_prefix
+ local cmd unit_name jr_pid ret sdrun_args sdrun_prefix
ret=0
+ if [[ $1 == -n ]]; then
+ unit_name="$2"
+ shift 2
+ fi
+
cmd="$1"
+ if [[ ! $unit_name ]]; then
+ unit_name=${cmd##*/}
+ fi
+
shift
- if [[ $EUID != 0 ]]; then
+ if [[ $EUID == 0 ]]; then
+ sdrun_args="-E HOME=/root -E SSH_AUTH_SOCK=/run/openssh_agent"
+ else
# note, I don't use system --user because if it does sudo ssh, that
# will leave a process around that we can't kill and it will leave
# the unit hanging around in a failed state needing manual killing
# of the process.
sdrun_prefix=sudo
sdrun_args="--uid "$(id -u)" --gid "$(id -g)" -E SSH_AUTH_SOCK=/run/openssh_agent"
- echo "jdo: error: rerun as root"
- return 1
fi
- cmd_name=${cmd##*/}
if [[ $cmd != /* ]]; then
+ # we need to pass a full path to systemd
cmd=$(type -P "$cmd")
fi
#note date format for since is date '+%F %T'
# -q = quiet
- journalctl --since=now -qn2 -f -u "$cmd_name" &
+ journalctl --since=now -qn2 -f -u "$unit_name" &
jr_pid=$!
- # todo: trial an error testing of the wait time here.
- sleep 1
- $sdrun_prefix systemd-run $sdrun_args --unit "$cmd_name" --wait --collect "$cmd" "$@" || ret=$?
+ # sleep 1 is too fast for x200
+ sleep 2
+ $sdrun_prefix systemd-run $sdrun_args --unit "$unit_name" --wait --collect "$cmd" "$@" || ret=$?
# The sleep lets the journal output its last line
# before the prompt comes up.
sleep .5
rspamta() {
ta "$@" /var/log/rspamd/rspamd.log
- }
+}
_rspamtag() {
tailf /var/log/rspamd/rspamd.log | grp "$@"
- }
+}
rspamtag() {
bn _rspamtag "$@"
}
# etail + grep.
_etailg() {
- ngset
- tailf /var/log/exim4/mainlog /var/log/exim4/*main /var/log/exim4/paniclog /var/log/exim4/*panic -n 200 | grp "$@"
- ngreset
- }
+ ngset
+ tailf /var/log/exim4/mainlog /var/log/exim4/*main /var/log/exim4/paniclog /var/log/exim4/*panic -n 200 | grp "$@"
+ ngreset
+}
etailg() {
bn _etailg "$@"
}
bn _jrfg "$@"
}
jru() {
- journalctl -nall -u "$@" ;
+ journalctl -u "$@" ;
}
jrug() {
_jrug() {
hssh-update() {
local -a failed_hosts hosts
case $HOSTNAME in
- sy|kd)
+ sy|so|kd)
hosts=(
kd.b8.nz x3.office.fsf.org syw x2.b8.nz
)
prospective_mps=(/a /o /qr /qd /q)
fi
fi
+ # If the above conditions didnt add any mountpoints, and host
+ # status is empty, then add all mointpoints. This is a case of
+ # doing something like kd_spread manually.
+ if [[ ! ${prospective_mps[0]} && $source_host != "$HOST2" && $source_host != "$MAIL_HOST" && $HOSTNAME != "$MAIL_HOST" && $HOSTNAME != "$HOST2" ]]; then
+ prospective_mps=(/a /o /qr /qd /q)
+ 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.
;;
tmpf=$(mktemp)
m rsync -ra $source:/usr/local/bin/{mount-latest-subvol,check-subvol-stale} /usr/local/bin
m rsync -ra $source:/usr/local/lib/bash-bear /usr/local/lib
- m scp $source:/a/bin/distro-setup/btrbk-run $tmpf
+ m rsync $source:/usr/local/bin/btrbk-run $tmpf
if ! diff -q $tmpf ${BASH_SOURCE[0]}; then
e "found different version on host $source. reexecing"
- install -T $tmpf /usr/local/bin/btrbk-run
+ rsync -aSAX --chmod=755 --chown=root:root $tmpf /usr/local/bin/btrbk-run
m /usr/local/bin/btrbk-run --pull-reexec "${orig_args[@]}"
mexit 0
fi
echo "$0: exit status $ret. see error above"
fi
exit $ret
-
-
old_hostname=$HOSTNAME
new_host=$host
bbk_args="-t $new_host"
- new_shell="ssh -F $HOME/.ssh/confighome root@$new_host"
+ new_shell="ssh -F /root/.ssh/confighome root@$new_host"
if ! new_hostname=$($new_shell hostname); then
echo "$pre: error: failed ssh. retrying failed $new_shell with -v for more info:"
$new_shell -v hostname
new_host=$HOSTNAME
new_hostname=$HOSTNAME
bbk_args="-s $old_host"
- old_shell="ssh -F $HOME/.ssh/confighome root@$old_host"
+ old_shell="ssh -F /root/.ssh/confighome root@$old_host"
# tests ssh connection. crafted this to not need to do escape chars
if ! $mail_only && ! $pull_reexec ; then
files=(
/usr/local/{bin/{unsaved-buffers{,.el},switch-mail-host},lib/bash-bear}
)
- m scp -F $HOME/.ssh/confighome \
+ m scp -F /root/.ssh/confighome \
${files[@]/#/root@$old_host:} $tmpd
diff=false
for f in ${files[@]}; do
#status_command i3status
#for faster testing
-#status_command /a/bin/ds/myi3status
+#status_command /a/bin/ds/filesystem/usr/local/bin/myi3status
status_command /usr/local/bin/myi3status
#mode hide
# hidden_state hide
bindsym $mod+Shift+d move container to workspace 3
bindsym $mod+d workspace 3
-bindsym $mod+Shift+f move container to workspace 2
+bindsym $mod+Shift+fq move container to workspace 2
bindsym $mod+f workspace 2
bindsym $mod+Shift+z move container to workspace 5
x="$(readlink -f -- "${BASH_SOURCE[0]}")"; cd ${x%/*} # directory of this file
+i3_cmd=reload
+if [[ $1 == -r ]]; then
+ i3_cmd=restart
+fi
+
## do sway config. untested and probably broken at this point
dir=/a/bin/distro-setup/subdir_files/.config/sway
mkdir -p $dir
fi
if [[ $I3SOCK ]]; then
- echo $0: i3-msg reload
- i3-msg reload
+ echo $0: i3-msg $i3_cmd
+ i3-msg $i3_cmd
fi
esac
if [[ ! $type ]]; then
- if xinput | grep -i keyboardio; then
+ if xinput | grep -i keyboardio &>/dev/null; then
type=keyboardio
else
type=laptop
# cp keyboardio-t12.xkb x2-t12.xkb
# diff xkbcomp-t9.xkb x2-t9.xkb
# g x2-t12.xkb
- m xkbcomp /a/c/keyboardio-t12.xkb $DISPLAY
+ m xkbcomp /a/c/keyboardio-t12.xkb $DISPLAY |& grep -v '^No symbols defined for'
;;
laptop)
- m xkbcomp /a/c/x2-t12.xkb $DISPLAY
+ m xkbcomp /a/c/x2-t12.xkb $DISPLAY |& grep -v '^No symbols defined for'
;;
esac
i3-msg "$@"
fi
}
+xmod() {
+ xrandr "$@"
+ gen_arg=-r
+}
date "+%A, %B %d, %r, %S seconds"
for mon_suffix in TOP-LEFT BOTTOM-LEFT LEFT RIGHT; do
if xrandr --listmonitors | awk '$2 == "MON-'$mon_suffix\" |grep . >/dev/null; then
- m xrandr --delmonitor MON-$mon_suffix
+ m xmod --delmonitor MON-$mon_suffix
fi
done
if [[ ! $secondary_out ]] || grep -A1 disconnected $xf | grep '^[[:space:]]'; then
# gets rid of leftover secondary
- m xrandr --auto
+ m xmod --auto
fi
if [[ $secondary_out ]] && $restart; then
- m xrandr --output $secondary_out --off
+ m xmod --output $secondary_out --off
m sleep 2
fi
if [[ $secondary_out || $primary_res != "$target_res" ]]; then
- m xrandr --output $target_out $left_right_arg --mode $target_res
+ m xmod --output $target_out $left_right_arg --mode $target_res
fi
if $tall; then
# 298 & 336 are millimeters. I took them from a monitor I was using. I
# don't know if they are important, I assume not important enough to
# change for different monitors.
- m xrandr --setmonitor MON-LEFT $half_x/298x$target_y/336+$x_offset+0 $target_out
- m xrandr --setmonitor MON-RIGHT $half_x/298x$target_y/336+$(( x_offset + half_x ))+0 none
+ m xmod --setmonitor MON-LEFT $half_x/298x$target_y/336+$x_offset+0 $target_out
+ m xmod --setmonitor MON-RIGHT $half_x/298x$target_y/336+$(( x_offset + half_x ))+0 none
elif $quarter; then
- m xrandr --setmonitor MON-LEFT $half_x/298x$half_y/336+$x_offset+0 $target_out
+ m xmod --setmonitor MON-LEFT $half_x/298x$half_y/336+$x_offset+0 $target_out
# note: this bottom left is buggy when it comes to context menus,
# including in web pages. In the tall configuration, I sometimes see
# them in another "monitor" area, but with this bottom left monitor,
# they aren't displayed at all, as if the window system is displaying
# them off screen. When that happens, I just switch to the tall
# configuration, use the dialog, and them maybe switch back.
- m xrandr --setmonitor MON-BOTTOM-LEFT $half_x/298x$half_y/336+$x_offset+$half_y none
- m xrandr --setmonitor MON-RIGHT $half_x/298x$target_y/336+$(( x_offset + half_x ))+0 none
+ m xmod --setmonitor MON-BOTTOM-LEFT $half_x/298x$half_y/336+$x_offset+$half_y none
+ m xmod --setmonitor MON-RIGHT $half_x/298x$target_y/336+$(( x_offset + half_x ))+0 none
fi
echo d1 ${ws_outputs[@]}
rm -f ~/i3-myx.conf
-total_ws_count=10
+total_ws_count=11
for (( i=0; i<total_ws_count; i++ )); do
ws=$(( i+1 ))
tmp=${ws_outputs[$i]}
cat /a/bin/ds/i3-sway/bar.conf >> ~/i3-myx.conf
fi
echo "bindsym \$mod+Shift+t move workspace to output ${move_outputs[*]}" >>~/i3-myx.conf
-m /a/bin/ds/i3-sway/gen
# give it some time to reload or adjust to new x settings.
+
+# i3-msg -t get_outputs | jq -C .
+# showed
+# {
+ # "name": "HDMI-2",
+ # "active": true,
+ # "primary": false,
+ # "rect": {
+ # "x": 1920,
+ # "y": 0,
+ # "width": 3840,
+ # "height": 2160
+ # },
+ # "current_workspace": "3"
+ # },
+ # {
+ # "name": "DP-1",
+ # "active": false,
+ # "primary": false,
+ # "rect": {
+ # "x": 1920,
+ # "y": 0,
+ # "width": 3840,
+ # "height": 2160
+ # },
+ # "current_workspace": null
+ # }
+ # This was incorrect. The correct thing is that DP-1 is active, HDMI-2 is not active.
+ # Restarting i3 did not help.
+
sleep 1
+m /a/bin/ds/i3-sway/gen $gen_arg
if (( ${#ws_outputs[@]} )); then
cat <<'EOF' >&2
ERROR: moving workspaces is not working as expected I've seen it happen
-that an output is not "active" and restarting i3 fixed it. If you see
-this, try reloading i3, and thinking about how to automatically handle
-the situation from within the script.
-
+that an output should not exist anymore. Restarting i3 fixed it, reloading did not.
+This script did a restart, but it might need a sleep before doing so.
EOF
exit 1
fi
tmps=$(jq -r '.[] | .num, .output' <<<"$tmps")
while read -r ws; do
read -r output || break
+ if [[ $ws != [0-9] && $ws != 10 ]]; then
+ echo "$0: error: unexpected workspace found: $ws. continuing"
+ continue
+ fi
if [[ ${ws_expected_out[$ws]} != "$output" ]]; then
m i3 '[workspace="'$ws'"]' move workspace to output ${ws_expected_out[$ws]}
refresh_workspaces=true
echo -n "myx end: "
date "+%A, %B %d, %r, %S seconds"
+
+
+# myx -f
+# Tuesday, July 23, 05:54:37 PM, 37 seconds
+# myx: xmod --delmonitor MON-LEFT
+# myx: xmod --delmonitor MON-RIGHT
+# myx: xmod --output DP-1 --right-of eDP-1 --mode 3840x2160
+# d1 eDP-1 DP-1
+# myx: /a/bin/ds/i3-sway/gen -r
+# /a/bin/ds/i3-sway/gen: i3-msg restart
+# [{"success":true}]
+# myx: i3 [workspace="2"] move workspace to output DP-1
+# ERROR: No output matched
+# [{"success":false,"error":"No output matched"}]
+# /a/exe/myx:63: `i3-msg "$@"' returned 2
+# from /a/exe/myx:63:in `i3 [workspace="2"] move workspace to output DP-1'
+# from /a/exe/myx:88:in `m i3 [workspace="2"] move workspace to output DP-1'
+# from /a/exe/myx:330:in `main -f'
+# /a/exe/myx: exiting with status 2
### FOR SOURCING ###
my_bin_files=(
- switch-mail-host
- switch-host2
- btrbk-run mount-latest-subvol
- check-subvol-stale
- myi3status
- mailbindwatchdog
- check-mailq
- unsaved-buffers
- unsaved-buffers.el
- mail-backup-clean
- iptables-exim
- ip6tables-exim
- exim-nn-iptables
- check-crypttab
+
/a/bin/cedit/cedit
- btrbk-spread-wrap
- prof
- prof-remote
- prof-backup
- prof-tail
- prof-notify
/a/bin/newns/newns
/a/bin/fai/fai/config/distro-install-common/ethusb-static
-
- i3-abrowser
- i3-auto-layout-toggle
- i3-chat
- i3-check-profanity
- i3-emacs
- i3-event-hook
- i3-focus-maybe
- i3-konsole
- i3-mouse-warp
- i3-set-layout
- i3-split-maybe
- i3-split-push
-
- copyq-restart
- toggle-mute
-
- check-stale-alerts
- check-radicale
- mailclean
- bk-backup
- eggdrop-upgrade
)
for f in /b/log-quiet/*; do
# DO NOT USE THIS ONE.
#keyserver hkp://pool.sks-keyservers.net
-#keyserver hkp://keys.openpgp.org
+keyserver hkp://keys.openpgp.org
#keyserver hkp://pgp.mit.edu
#keyserver hkp://keyserver.pgp.com
#keyserver hkp://ipv4.pool.sks-keyservers.net
#keyserver hkp://keys.gnupg.net
#keyserver hkp://keyserver.ubuntu.com
#keyserver hkp://keyring.debian.org
-keyserver keyserver.ubuntu.com
+#keyserver keyserver.ubuntu.com
# more secure hkps, but had problems with my gpg version
#keyserver hkps://hkps.pool.sks-keyservers.net
TextEditorCmd=6
TextEditorCmdCustom=/a/exe/g +LINE:COLUMN PATH
UnderlineFilesEnabled=true
-WordCharacters=@-./_~?&=%+#
+WordCharacters=@-./_~?&=%+#:
[Keyboard]
KeyBindings=default