else
# bleh shellcheck can't handle disabling in an elif, so nesting this if.
# shellcheck disable=SC2154 # set in .bashrc
- if [[ -s $bashrc_dir/err ]]; then
+ if [[ -s $bashrc_dir/bash-bear ]]; then
# shellcheck source=/a/bin/bash-bear-trap/bash-bear
- source $bashrc_dir/err
+ source $bashrc_dir/bash-bear
fi
fi
ssh-copy-id $1
}
+# copy path into clipboard
a() {
local x
x=$(readlink -nf "${1:-$PWD}")
gp() {
cat &>/a/tmp/gtmp
g "$@" /a/tmp/gtmp
- }
-
-# like cmd &> tempfile; emacs tempfile
-gc() {
+}
+# g log
+#like cmd &> tempfile; emacs tempfile
+#
+# note: a useful workflow for doing mass replace on my files:
+# gc rem REGEX
+## remove any false positives, or manually edit them. rename files if needed.
+# sedi 's/REGEX/REPLACEMENT/' $(gr '^/' /a/tmp/gtmp)
+gl() {
"$@" &> /a/tmp/gtmp
g /a/tmp/gtmp
- }
+}
+# g command substitution
+gc() {
+ g $("$@")
+}
# force terminal version
gn() {
# on-battery
on-bat() {
if [[ -e /sys/class/power_supply/AC/online && $(</sys/class/power_supply/AC/online) == 0 ]]; then
+ return 0
+ else
return 1
fi
}
}
+disk-info() {
+ local cmds cmd
+ mapfile -t cmds <<'EOF'
+tail -n +1 /proc/mdstat /etc/mdadm/mdadm.conf /etc/fstab /etc/crypttab
+lsblk
+blkid
+ls -la /dev/disk/by-id
+EOF
+
+ for cmd in "${cmds[@]}"; do
+ cat <<EOF
+### $cmd
+
+\`\`\`
+EOF
+ $cmd
+ cat <<'EOF'
+
+```
+
+EOF
+ done
+}
+
# * misc stuff
source /a/bin/bash_unpublished/source-semi-priv
source /a/bin/bash_unpublished/source-state
+if [[ $HOSTNAME == "$MAIL_HOST" ]]; then
+ export MAIL_HOST_P=t
+else
+ export NOT_MAIL_HOST_P=t
+fi
+
+
source /a/bin/log-quiet/logq-function
# not used
otp() {
oathtool --totp -b "$*" | xclip -selection clipboard
}
+# run cmd and copy output
j() {
"$@" |& pee "xclip -r -selection clipboard" cat
}
[[ $EUID == 0 ]] || exec sudo -E "${BASH_SOURCE[0]}" "$@"
-source /usr/local/lib/bash-bear
+set -e; . /usr/local/lib/bash-bear; set +e
usage() {
cat <<'EOF'
[[ $EUID == 0 ]] || exec sudo -E "${BASH_SOURCE[0]}" "$@"
-source /usr/local/lib/bash-bear
+set -e; . /usr/local/lib/bash-bear; set +e
shopt -s nullglob
case $HOSTNAME in
sy|kd)
- sudo install -m 0755 -o root -g root -t /usr/bin /a/opt/bitcoin-24.0.1/bin/*
+ sudo install -m 0755 -o root -g root -t /usr/bin /a/opt/bitcoin-26.0/bin/*
sgo bitcoind
# note: the bitcoin user & group are setup in fai
sudo usermod -a -G bitcoin iank
#!/bin/bash
-exec emacs -f znc-all
+exec emacs -f znc-all "$@"
# Note: running this inside a cronjob, it wont mail any output if we end
# up rebooting from this script.
-if [ -z "$BASH_VERSION" ]; then echo "error: shell is not bash" >&2; exit 1; fi
+set -e; . /usr/local/lib/bash-bear; set +e
-source /usr/local/lib/bash-bear
pre="${0##*/}:"
PATH="/sbin:$PATH"
m() { printf "$pre %s\n" "$*"; "$@"; }
# Copyright (C) 2019 Ian Kelling
# SPDX-License-Identifier: AGPL-3.0-or-later
-if [ -z "$BASH_VERSION" ]; then echo "error: shell is not bash" >&2; exit 1; fi
+set -e; . /usr/local/lib/bash-bear; set +e
-source /usr/local/lib/bash-bear
pre="${0##*/}:"
m() { printf "$pre %s\n" "$*"; "$@"; }
e() { printf "$pre %s\n" "$*"; }
EOF
+ # ian: save a copy of sent mail. i thought of other ways to do this,
+ # for example, to only save sent mail that is not sent from my mail
+ # client which saves a copy by default, but in the end, it seems
+ # simplest to turn that off. We want to save external mail sent by
+ # smarthosts. However, there is one complication: encrypted
+ # mail. Saving it here just gets us an encrypted copy that we can't
+ # read. Soo, we could bcc ourselves: then we still have the
+ # annoyance that it is encrypted so we can't grep it. Or, we could
+ # hack emacs so that it sends us an unencrypted copy. Turns out that
+ # the emacs function which saves sent email can also send us a
+ # copy. But, then we have 3 copies: the encrypted copy exim saves,
+ # the unencrypted copy exim saves, and the copy emacs saves. Soo,
+ # we can emacs send a copy directly to the sent alias but only when
+ # it is not mail_host, and have the exim condition for redirecting a
+ # copy to the sent alias avoid doing it if it has an emacs user
+ # agent header.
u /etc/exim4/conf.d/router/186_sentarchive_nn <<'EOF'
-# ian: save a copy of sent mail. i thought of other ways to
-# do this, for example, to only save sent mail that is not sent
-# from my mail client which saves a copy by default, but in the
-# end, it seems simplest to turn that off. We want to save
-# external mail sent by smarthosts.
sentarchive_nn:
driver = redirect
domains = ! +local_domains
- condition = ${if !bool{${lookup{$local_part@$domain}lsearch{/etc/exim4/ignore-sent}{true}}}}
+ condition = ${if and {{!bool{${lookup{$local_part@$domain}lsearch{/etc/exim4/ignore-sent}{true}}}} {!match {$h_user-agent:}{emacs}}}}
data = vojdedIdNejyebni@b8.nz
unseen
EOF
driver = redirect
domains = ! +local_domains
senders = <; *@fsf.org ; *@posteo.net
- condition = ${if !bool{${lookup{$local_part@$domain}lsearch{/etc/exim4/ignore-sent}{true}}}}
+ condition = ${if and {{!bool{${lookup{$local_part@$domain}lsearch{/etc/exim4/ignore-sent}{true}}}} {!match {$h_user-agent:}{emacs}}}}
data = vojdedIdNejyebni@b8.nz
unseen
EOF
u /etc/myexim4/conf.d/router/160_backup_redir <<'EOF'
backup_redir:
-driver = redirect
-# i dont email myself from my own machine much, so lets ignore that.
-domains = ! +local_domains
-senders = <; *@fsf.org ; *@posteo.net
-condition = ${if !bool{${lookup{$local_part@$domain}lsearch{/etc/exim4/ignore-sent}{true}}}}
-# b is just an arbirary short string
-data = b@eximbackup.b8.nz
-# note, to test this, i could temporarily allow testignore.
-# alerts avoids potential mail loop.
-local_parts = ! root : ! testignore : ! alerts : ! daylert
-unseen = true
-errors_to = alerts@iankelling.org
+ driver = redirect
+ # i dont email myself from my own machine much, so lets ignore that.
+ domains = ! +local_domains
+ senders = <; *@fsf.org ; *@posteo.net
+ condition = ${if and {{!bool{${lookup{$local_part@$domain}lsearch{/etc/exim4/ignore-sent}{true}}}} {!match {$h_user-agent:}{emacs}}}}
+ # b is just an arbirary short string
+ data = b@eximbackup.b8.nz
+ # note, to test this, i could temporarily allow testignore.
+ # alerts avoids potential mail loop.
+ local_parts = ! root : ! testignore : ! alerts : ! daylert
+ unseen = true
+ errors_to = alerts@iankelling.org
EOF
# for bk, we have a exim4in.service that will do this for us.
# usage: HOST [mount-latest-subvol args]
-source /usr/local/lib/bash-bear
+set -e; . /usr/local/lib/bash-bear; set +e
script_dir=$(dirname $(readlink -f "$BASH_SOURCE"))
cd /
[[ $EUID == 0 ]] || exec sudo -E "$this_file" "$@"
-source /usr/local/lib/bash-bear
+set -e; . /usr/local/lib/bash-bear; set +e
usage() {
cat <<EOF
#!/bin/bash
-if [[ -s /usr/local/lib/bash-bear ]]; then
- source /usr/local/lib/bash-bear
-else
- exit 1
-fi
+set -e; . /usr/local/lib/bash-bear; set +e
pre="${0##*/}:"
i /usr/local/bin/ncup <<'EOFOUTER'
#!/bin/bash
-source /usr/local/lib/bash-bear
+set -e; . /usr/local/lib/bash-bear; set +e
m() { printf "%s\n" "$*"; "$@"; }
err-cleanup() {
# usage $0 [MAIL_HOST]
# setup things which involve being the primary host or not
-source /usr/local/lib/bash-bear
+set -e; . /usr/local/lib/bash-bear; set +e
script_name="${BASH_SOURCE[0]}"
script_name="${script_name##*/}"
source /a/bin/bash-bear-trap/bash-bear
source /a/bin/bash_unpublished/source-state
+if [[ ! $HOSTNAME ]]; then
+ HOSTNAME=$(cat /etc/hostname)
+fi
if [[ $HOSTNAME != "$HOST2" ]]; then
exit 0
fi
--- /dev/null
+#!/bin/bash
+
+exim -f '<>' vojdedIdNejyebni@b8.nz <"$1"
myi3status
mailbindwatchdog
check-mailq
+ unsaved-buffers
unsaved-buffers.el
mail-backup-clean
iptables-exim
[Appearance]
ColorScheme=ianktheme
-Font=DejaVu Sans Mono,12,-1,5,50,0,0,0,0,0
+Font=Noto Mono,12,-1,5,50,0,0,0,0,0
[General]
LocalTabTitleFormat=%w
#!/bin/bash
-source /usr/local/lib/bash-bear
+set -e; . /usr/local/lib/bash-bear; set +e
usage() {
cat <<EOF
die "failed: $old_shell switch-mail-host --check-installed"
fi
fi
- tmpf=$(mktemp)
- m scp -F $HOME/.ssh/confighome root@$old_host:/usr/local/bin/switch-mail-host $tmpf
- if ! diff -q $tmpf ${BASH_SOURCE[0]}; then
+ tmpd=$(mktemp -d)
+ files=(
+ /usr/local/{bin/{unsaved-buffers{,.el},switch-mail-host},lib/bash-bear}
+ )
+ m scp -F $HOME/.ssh/confighome \
+ ${files@/#/root@$old_host:} $tmpd
+ diff=false
+ for f in ${files[@]}; do
+ if ! diff -q $tmpd/${f##*/} $f; then
+ m install -T $tmpd/${f##*/} $f
+ diff=true
+ fi
+ done
+ if $diff; then
e "found different version on old_host=$old_hostname, reexecing"
- m install -T $tmpf /usr/local/bin/switch-mail-host
m /usr/local/bin/switch-mail-host --pull-reexec "${orig_args[@]}"
exit 0
fi
+ rm -r -- $tmpd
fi
f=/a/bin/bash_unpublished/source-state
# ensure these are unused before doing anything
e "On $new_host: umounting /m and /o, checking emacs"
{
- cat <<'EOF'
-set -eE
-if pgrep -G iank -u iank -f 'emacs --daemon' &>/dev/null; then
- bufs="$(sudo -u iank env XDG_RUNTIME_DIR=/run/user/1000 emacsclient --eval "$(cat /a/bin/ds/unsaved-buffers.el)"| sed '/^"nil"$/d;s/^"(/E: /;s/)"$//')"
- if [[ $bufs ]]; then
- echo "error: on $HOSTNAME, unsaved emacs files: $bufs" >&2
- exit 1
- fi
-fi
-EOF
+ cat /usr/local/bin/unsaved-buffers
if ! $host2_only; then
cat <<EOF
for dir in m o; do
} | $new_shell bash -s
if ! $mail_only; then
- $old_shell bash -s <<'EOF'
-set -e
-if pgrep -G iank -u iank -f 'emacs --daemon' &>/dev/null; then
- bufs="$(sudo -u iank env XDG_RUNTIME_DIR=/run/user/1000 emacsclient --eval "$(cat /a/bin/ds/unsaved-buffers.el)"| sed '/^"nil"$/d;s/^"(/E: /;s/)"$//')"
- if [[ $bufs ]]; then
- echo "error: on $HOSTNAME, unsaved emacs files: $bufs" >&2
- exit 1
- fi
-fi
+ cat /usr/local/bin/unsaved-buffers - <<'EOF' | $old_shell bash -s
# Try to prevent emacs from saving stale data it has in memory to disk. eg: files, recentf list, etc.
# But if emacs ignores the signal, let it live.
fi
case $bat in
100|9?)
- bitcoinon &
+ :
+ #bitcoinon &
;;
esac
fi
--- /dev/null
+#!/bin/bash
+shopt -s inherit_errexit 2>/dev/null ||: # ignore fail in bash < 4.4
+set -eE -o pipefail
+trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
+if pgrep -G iank -u iank -f '^emacs --daemon$' &>/dev/null; then
+ elisp=$(cat /usr/local/bin/unsaved-buffers.el)
+ emacsout=$(sudo -u iank env XDG_RUNTIME_DIR=/run/user/1000 emacsclient --eval "$elisp")
+ bufs=$(printf "%s\n" "$emacsout"|sed '/^"nil"$/d;s/^"(/E: /;s/)"$//')
+ if [[ $bufs ]]; then
+ echo "error: on $HOSTNAME, unsaved emacs files: $bufs" >&2
+ exit 1
+ fi
+fi
script=$(readlink -f -- "$BASH_SOURCE")
[[ $EUID == 0 ]] || exec sudo -E "$script" "$@"
-source /usr/local/lib/bash-bear
+set -e; . /usr/local/lib/bash-bear; set +e
# Explaining this whole thing. The host amy is used by someone else,
# Get screenshots from bow, discard them if they dont change much.
-source /usr/local/lib/bash-bear
[[ $EUID == 0 ]] || exec sudo -E "${BASH_SOURCE[0]}" "$@"
+set -e; . /usr/local/lib/bash-bear; set +e
+
dest_dir=/d/ziva-log
case $HOSTNAME in
sy)