# shellcheck disable=SC2120
r() {
- history -a # save history
+ if [[ $HISTFILE ]]; then
+ history -a # save history
+ fi
trap ERR # this avoids a segfault
exit ${1:0}
# i had this redir, not sure why
local ps_char ps_color
unset IFS
- history -a # save history
+ if [[ $HISTFILE ]]; then
+ history -a # save history
+ fi
case $return in
0) ps_color="$term_purple"
xclock -digital -update 1 -face 'arial black-80:bold'
}
+inttrap() {
+ pid=$1
+ # just passing on -INT doesnt work.
+ kill -TERM $pid
+ sleep .05
+ if [[ ! -e /proc/$pid ]]; then
+ if [[ $old_int_trap ]]; then
+ $old_int_trap
+ else
+ trap INT
+ fi
+ fi
+}
+
_jrun() { # journal run. run args, log to journal, tail and grep the journal.
# Redirect all commands which might have stderr to stdout because of
# wrapping.
cmd_name=${1##*/}
systemd-cat -t "$cmd_name" "$@" 2>&1 &
pid=$!
- sedscript="/$pattern$cmd_name/p;/^.{16}[^ ]+ $cmd_name\[$pid]: $cmd_name: exiting with status [0-9]+\$/q"
+ old_int_trap="$(trap -p INT)"
+ # Note, just passing along INT wont actually stop it.
+ # Oddly, the log says ERROR: /script.sh returned 130
+ # but it continues on.
+ trap "inttrap $pid" INT
+ sedscript="/$pattern$cmd_name/p;/^.{16}[^ ]+ $cmd_name\[$pid]: ([^ ]*\/)?$cmd_name: exiting with status [0-9]+\$/q"
+ # debug:
+ #echo "sedscript: sed -nr '$sedscript'"
journalctl -S "4 seconds ago" -f |& sed -nr "$sedscript" 2>&1 &
jr_pid=$!
wait $pid 2>&1 || ret=$?
if (( $ret )); then
echo "$0: ERROR: $* returned $ret"
fi
- jobs %'journalctl -S "4 seconds ago" -f' &>/dev/null
ended=false
- # give it about 5 seconds to find the end of the log
- for (( i=0; i<20; i++ )); do
- if jobs %'journalctl -S "4 seconds ago" -f' &>/dev/null; then
- sleep .3 2>&1
+ # give it 4 seconds to find the end of the log
+ for (( i=0; i<80; i++ )); do
+ if [[ -e /proc/$jr_pid ]]; then
+ sleep .05 2>&1
else
ended=true
break
if ! $ended; then
kill $jr_pid 2>&1
fi
+ if [[ $old_int_trap ]]; then
+ $old_int_trap
+ else
+ trap INT
+ fi
+ return 0
}
jrun() {
# ditching stderr avoids the jobs status change output.
}
sm() {
- (( $# == 2 )) || return 1
- action=$1
- shift
- host=$1
- shift
- case $action in
- pull|push) : ;;
- *) return 1 ;;
- esac
c /
# run latest
install-my-scripts
- jrun -p btrbk switch-mail-host $action $host
+ jrun -p btrbk switch-mail-host "$@"
return $ret
}
m s nscd -i hosts
f=/etc/resolv.conf
echo $f:; ccat $f
- hr; m ser status dnsmasq | cat
+ # this will fail is dnsmasq is failed
+ hr; m ser status dnsmasq | cat || :
hr; s ss -lpn 'sport = 53'
#hr; echo dnsmasq is $(systemctl is-active dnsmasq)
f=/var/run/dnsmasq/resolv.conf
rcat() {
resolvcat | less
}
+reresolv() {
+ sudo nscd -i hosts
+ sudo systemctl restart dnsmasq
+}
# only run on MAIL_HOST. simpler to keep this on one system.
r2eadd() { # usage: name url
xevkb() { xev -event keyboard; }
+ziva() { e "toot! i love dancing. fart"; }
+
# * misc stuff
# from curl cheat.sh/:bash_completion
rate_limit=no
verbose=true; verbose_arg=-v
progress_arg="--progress"
+incremental_strict=true
pull_reexec=false
default_args_file=/etc/btrbk-run.conf
cron=false
orig_args=("$@")
-temp=$(getopt -l cron,pull-reexec,help cl:m:npqs:t:vh "$@") || usage 1
+temp=$(getopt -l cron,pull-reexec,help cil:m:npqs:t:vh "$@") || usage 1
eval set -- "$temp"
while true; do
case $1 in
;;
# only creates the config file, does not run btrbk
-c) conf_only=true; shift ;;
+ -i) incremental_strict=false; shift ;;
# bytes per second, suffix k m g
-l) rate_limit=$2; shift 2 ;;
# Comma separated mountpoints to backup. This has defaults set below.
fi
### end options parsing
+if ! btrbk --version |& grep 0.29.0 >/dev/null; then
+ cd /a/opt/btrbk
+ m sudo make install
+fi
# TODO: i wonder if there should be an option to send to the default
# targets, plus any given on the command line.
;;&
x2|x3)
if ping -q -c1 -w1 hal.office.fsf.org \
- && ip n show 192.168.0.26 | grep . &>/dev/null; then
- at_work=true
+ && ip n show 192.168.0.26 | grep . &>/dev/null; then
+ at_work=true
fi
;;&
kw|x2|x3)
fi
;;&
kw)
- targets=($home x2)
+ targets=($home x3)
;;
x2|x3)
targets=($home kw)
rate_limit $rate_limit
EOF
-
-
-
+if $incremental_strict; then
+ cat >>/etc/btrbk.conf <<EOF
+incremental strict
+EOF
+fi
vol=/mnt/root
for m in ${mountpoints[@]}; do
snaps=($root_dir/btrbk/$subvol_dir.20*) # Assumes we are in the 21st century.
if [[ ! ${snaps[*]} ]]; then
# no snapshots yet
+ # TODO: make this an error and override with a cli flag
echo "$0: warning: no snapshots found at $root_dir/btrbk/$subvol_dir.20*. this is expected for a brand new volume"
continue
fi
# but it happened too late in the shutdown process.
sudo dd of=/etc/systemd/system/keyscripton.service <<'EOF'
[Unit]
-Description=Turn on automatic decryption of drives on boot
+Description=keyscripton
# This is triggered by reboot and when keyscriptoff stops.
# tried using graphical.target, but it made my display manager restart before rebooting.
sudo dd of=/etc/systemd/system/keyscriptoff.service <<'EOF'
[Unit]
-Description=Turn off automatic decryption of drives on boot
+Description=keyscriptoff
[Service]
Type=oneshot
echo $HOSTNAME > /etc/hostname
hostname -F /etc/hostname
fi
+# office vpn dhcp adds to /etc/resolv.conf search office.fsf.org which
+# makes that be #1 priority, which makes dnsmasq resolve that for
+# unqualified hosts first, which means we skip the hosts file. Ya, its
+# kinda dumb, but it is what it is. There is a dnsmasq config option to
+# override it too, but this seems simpler.
sudo sed -i --follow-symlinks -f - /etc/hosts <<EOF
-\$a 127.0.1.1 $HOSTNAME.b8.nz $HOSTNAME
+\$a 127.0.1.1 $HOSTNAME.b8.nz $HOSTNAME.office.fsf.org $HOSTNAME
/^127\.0\.1\.1/d
EOF
Package: *
Pin: release a=xenial-security
Pin-Priority: -100
+
+Package: firefox
+Pin: release n=xenial
+Pin-Priority: 500
EOF
sd /etc/apt/sources.list.d/xenial.list 2>/dev/null <<EOF
deb http://us.archive.ubuntu.com/ubuntu/ xenial main
;;
bionic)
pi gnome-core
+ # by default, it sleeps when not logged in to x/wayland and on ac power.
+ # stop that.
+ sudo -u gdm dbus-launch gsettings set org.gnome.settings-daemon.plugins.power sleep-inactive-ac-type 'nothing'
+ systemctl --user stop gvfs-daemon
+ systemctl --user disable gvfs-daemon
;;
esac
pi gnupg-doc
fi
-if [[ $codename == flidas ]]; then
- pi abrowser
-else
- pi firefox
- sudo ln -sf /usr/bin/firefox /usr/local/bin/abrowser
-fi
+# abrowser is not in etiona yet, abrowser version is 68,
+# abrowser won't run on a firefox profile that was on firefox
+# version 70. firefox in ubuntu is at version 70.
+# have to rm compabibility.ini to even try downgrade.
+pi firefox
+sudo update-alternatives --set x-www-browser /usr/bin/firefox
# TODO: some of the X programs can be removed from pall when using wayland
+++ /dev/null
-server=/fsf.org/gnu.org/192.168.0.10
-server=/fsf.org/gnu.org/192.168.0.25
-server=//192.168.0.10
-server=//192.168.0.25
-rev-server=192.168.0.0/24,192.168.0.10
-rev-server=192.168.0.0/24,192.168.0.25
-rev-server=172.16.0.0/23,192.168.0.10
-rev-server=172.16.0.0/23,192.168.0.25
set $mod Mod4
bindsym $mod+2 exec "pavucontrol"
-bindsym $mod+3 exec "abrowser"
-bindsym $mod+4 exec "abrowser -no-remote -P firefox-main-profile"
+bindsym $mod+3 exec "x-www-browser"
+bindsym $mod+4 exec "x-www-browser -no-remote -P firefox-main-profile"
bindsym $mod+5 exec "/a/bin/redshift.sh"
bindsym $mod+w focus parent
# you can remove this if you do not have options which can have args with spaces or empty.
-verbose=false
+verbose=true
force=false
temp=$(getopt -l help,force,verbose hfv "$@") || usage 1
eval set -- "$temp"
lvm2
mbuffer
screen
+ nscd
)
p2=(
bash-completion
eatmydata
fping
git
+ haveged
htop
iptables
mailutils
set $mod Mod4
bindsym $mod+2 exec "pavucontrol"
-bindsym $mod+3 exec "abrowser"
-bindsym $mod+4 exec "abrowser -no-remote -P firefox-main-profile"
+bindsym $mod+3 exec "x-www-browser"
+bindsym $mod+4 exec "x-www-browser -no-remote -P firefox-main-profile"
bindsym $mod+5 exec "/a/bin/redshift.sh"
bindsym $mod+w focus parent
set $mod Mod4
bindsym $mod+2 exec "pavucontrol"
-bindsym $mod+3 exec "abrowser"
-bindsym $mod+4 exec "abrowser -no-remote -P firefox-main-profile"
+bindsym $mod+3 exec "x-www-browser"
+bindsym $mod+4 exec "x-www-browser -no-remote -P firefox-main-profile"
bindsym $mod+5 exec "/a/bin/redshift.sh"
bindsym $mod+w focus parent
}
}
+
+
+if anyof (
+ header :contains "list-id" "<~sircmpwn/sr.ht-discuss.lists.sr.ht>"
+ ) {
+ fileinto :create "l/sr.ht-discuss";
+ stop;
+ }
+
+
if anyof (
header :contains "list-id" "<activists_masspirates.org.lists.mayfirst.org>",
header :contains "list-id" "<gnu-prog-discuss.gnu.org>",
header :contains "list-id" "<gnu-misc-discuss.gnu.org>",
header :contains "list-id" "<Spdx-legal.lists.spdx.org>",
header :contains "list-id" "<info-gnu.gnu.org>",
+ header :contains "list-id" "<discussion.lists.fsfe.org>",
+ header :contains "list-id" "<gnu-system-discuss.gnu.org>",
header :contains "from" "<general-info@artisansasylum.com>",
header :contains "list-id" "<spdx.lists.spdx.org>"
) {
stop;
}
+
if allof (
address :is "from" "mailman-owner@zope.org",
header :is "subject" "zope.org mailing list memberships reminder"
}
}
+
+
+if anyof (
+ header :contains "list-id" "<~sircmpwn/sr.ht-discuss.lists.sr.ht>"
+ ) {
+ fileinto :create "l/sr.ht-discuss";
+ stop;
+ }
+
+
if anyof (
header :contains "list-id" "<activists_masspirates.org.lists.mayfirst.org>",
header :contains "list-id" "<gnu-prog-discuss.gnu.org>",
header :contains "list-id" "<gnu-misc-discuss.gnu.org>",
header :contains "list-id" "<Spdx-legal.lists.spdx.org>",
header :contains "list-id" "<info-gnu.gnu.org>",
+ header :contains "list-id" "<discussion.lists.fsfe.org>",
+ header :contains "list-id" "<gnu-system-discuss.gnu.org>",
header :contains "from" "<general-info@artisansasylum.com>",
header :contains "list-id" "<spdx.lists.spdx.org>"
) {
stop;
}
+
if allof (
address :is "from" "mailman-owner@zope.org",
header :is "subject" "zope.org mailing list memberships reminder"
pre="${0##*/}:"
m() { printf "$pre %s\n" "$*"; "$@"; }
e() { printf "$pre %s\n" "$*"; }
-err() { echo "$pre: ERROR: $*" >&2; }
-mexit() { echo "$pre: exiting with status $1"; exit $1; }
+err() { echo "$pre ERROR: $*" >&2; }
+mexit() { echo "$pre exiting with status $1"; exit $1; }
##### begin command line parsing ########
-temp=$(getopt -l help owh "$@") || usage 1
+force=false
mp_args="-m /o,/q,/a"
+temp=$(getopt -l force,help owh "$@") || usage 1
eval set -- "$temp"
while true; do
case $1 in
+ --force) force=true ;;
-o) mp_args="-m /o"; shift ;;
-h|--help) usage ;;
--) shift; break ;;
case $1 in
push)
old_host=$HOSTNAME
+ old_hostname=$HOSTNAME
new_host=$2
- bbk_args="-s $old_host"
+ bbk_args="-t $new_host"
new_shell="ssh $new_host"
new_hostname=$($new_shell hostname)
;;
old_host=$2
new_host=$HOSTNAME
new_hostname=$HOSTNAME
- bbk_args="-t $new_host"
bbk_args="-s $old_host"
old_shell="ssh $old_host"
- # test ssh connection
- $old_shell :
+ # tests ssh connection
+ old_hostname=$($old_shell hostname)
;;
*)
err invalid first argument
source /a/bin/bash_unpublished/source-state
-if [[ $old_host != "$MAIL_HOST" ]]; then
- e "WARNING: \$old_host != \$MAIL_HOST. Sleeping for 5 seconds in case you want to reconsider"
- sleep 5
+if [[ $old_hostname != "$MAIL_HOST" ]] && ! $force; then
+ err "\$old_hostname($old_hostname) != \$MAIL_HOST($MAIL_HOST). Rerun with --force if you really want this."
+ mexit 1
fi
if [[ ! $new_host || ! $old_host ]]; then
fi
btrbk_test="systemctl is-active btrbk.service"
-while true; do
+active=true
+while $active; do
+ active=false
for shell in "$new_shell" "$old_shell"; do
e $shell $btrbk_test
status=$($shell $btrbk_test) ||:
case $status in
inactive|failed) : ;;
*)
+ # This covers conditions like "activating", which still return 3 from
+ # systemctl is-active.
+ active=true
e "btrbk active on shell:$shell, status:$status, sleeping 8 seconds"
sleep 8
- continue
+ break
;;
esac
done
- break
done
# ensure these are unused before doing anything
m $old_shell /a/exe/primary-setup $new_hostname
e Running main btrbk
-if ! m btrbk-run -v $bbk_args -m /o; then
- ret=$?
+m btrbk-run -v $bbk_args -m /o || ret=$?
+if (( ret )); then
bang="$(printf "$(tput setaf 5)█$(tput sgr0)%.0s" 1 2 3 4 5 6 7)"
e $bang failed btrbk of /o. restoring old host as primary
m $old_shell /a/exe/primary-setup localhost