conflink
f=/var/lib/bind/db.b8.nz
ser stop bind9
-s rm -fv $f.jnl
-s install -m 644 -o bind -g bind /p/c/machine_specific/linode/bind-initial/db.b8.nz $f
+sudo rm -fv $f.jnl
+sudo install -m 644 -o bind -g bind /p/c/machine_specific/linode/bind-initial/db.b8.nz $f
ser restart bind9
EOF
done
}
bbk() { # btrbk wrapper
+
+ local pid
c /
local active=true
systemctl is-active btrbk.timer || active=false
fi
# run latest
install-my-scripts
- btrbk-run "$@" |& pee cat "systemd-cat -t btrbk-run"
+ jrun -p btrbk btrbk-run "$@"
if $active; then
- ser enable btrbk.timer
+ if (( $ret )); then
+ echo bbk: WARNING: btrbk.timer not reenabled due to failure
+ else
+ ser enable btrbk.timer
+ fi
fi
+ return $ret
}
bfg() { java -jar /a/opt/bfg-1.12.14.jar "$@"; }
xclock -digital -update 1 -face 'arial black-80:bold'
}
-bpull() {
- [[ $1 ]] || return 1
- c /
- # run latest
- install-my-scripts
- switch-mail-host pull $1 |& pee cat "systemd-cat -t switch-mail-host"
+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.
+ local pid pattern jr_pid sedscript cmd_name ended
+ ret=0
+ case $1 in
+ -p)
+ pattern="$2|"
+ shift 2
+ ;;
+ esac
+ cmd_name=${1##*/}
+ systemd-cat -t "$cmd_name" "$@" 2>&1 &
+ pid=$!
+ 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
+ ended=false
+ # 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
+ fi
+ done
+ 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.
+ _jrun "$@" 2>/dev/null
}
-bpush() {
- [[ $1 ]] || return 1
+
+sm() {
c /
# run latest
install-my-scripts
- switch-mail-host push $1 |& pee cat "systemd-cat -t switch-mail-host"
+ jrun -p btrbk switch-mail-host "$@"
+ return $ret
}
+
lipush() {
# note, i had --delete-excluded, but that deletes all files in --exclude-from on
# the remote site, which doesn't make sense, so not sure why i had it.
local p a
- p=(/a/bin /a/exe /a/h /a/c /p/c/machine_specific/linode{,.hosts} /a/opt/{emacs,emacs-debianstable,mu})
+ p=(/a/bin /a/exe /a/h /a/c /p/c/machine_specific/linode{,.hosts} /a/opt/{emacs-debianstable,mu})
a="-ahviSAXPH --specials --devices --delete --relative --exclude-from=/p/c/li-rsync-excludes"
ret=0
m rsync "$@" $a ${p[@]} /p/c/machine_specific/l2 root@l2.b8.nz:/ || ret=$?
ran_d=true
;;&
*DISTRO-END!*|*DISTRO!*)
- pushd
+ pushd /
/b/ds/distro-end || return $?
popd
ran_d=true
done < "$file"
}
+failfunc() { asdf a b c; }
+failfunc2() { failfunc d e f; }
# one that comes with distros is too old for newer devices
fastboot() {
hr
e "s lshw -C network"
hr
- s lshw -C network
+ sudo lshw -C network
}
nk() {
ser stop NetworkManager
ser stop dnsmasq
- s resolvconf -d NetworkManager
+ sudo resolvconf -d NetworkManager
ser start dnsmasq
- s ifup br0
+ sudo ifup br0
}
ngo() {
- s ifdown br0
+ sudo ifdown br0
ser start NetworkManager
sleep 4
- s nmtui-connect
+ sudo nmtui-connect
}
otp() {
#rbp() { rbt post -o "$@"; }
rebr() {
- s ifdown br0
- s ifup br0
+ sudo ifdown br0
+ sudo ifup br0
}
resolvcat() {
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
hr; echo $f:; ccat $f
- hr; m grr '^ *servers-file *=' /etc/dnsmasq.conf /etc/dnsmasq.d
+ hr; m grr '^ *(servers-file|server) *=|^ *no-resolv *$' /etc/dnsmasq.conf /etc/dnsmasq.d
f=/etc/dnsmasq-servers.conf
hr; echo $f:; ccat $f
}
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
}
spend() {
- s systemctl suspend
+ sudo systemctl suspend
}
# ssh, copy my universal config over if needed.
done
fi
else
- dorsync=true
# use this weird yes thing to ensure we know ssh succeeded
if ! tmp=$(command ssh "${args[@]}" "$remote" "if test -e /a/bin/ds/.bashrc -a -L .bashrc; then echo yes; fi"); then
echo failed sl test. doing plain ssh -v
if [[ $tmp == yes ]]; then
type=a
else
+ dorsync=true
type=b
fi
fi
- if [[ $type == b ]] && $dorsync; then
- if ! RSYNC_RSH="ssh ${args[*]}" rsync -rptL /b/ds/sl/.iank "$remote":; then
- echo WARNING: rsync failed. remove $sshinfo to try again
- fi
+ if $dorsync; then
+ RSYNC_RSH="ssh ${args[*]}" rsync -rptL /b/ds/sl/.iank "$remote":
fi
if $dorsync || ! $haveinfo; then
sshinfo=/p/sshinfo/$now$type"$remote"
chmod 666 $sshinfo
fi
if [[ $type == b ]]; then
- if $dorsync; then
- RSYNC_RSH="ssh ${args[*]}" rsync -rptL /b/ds/sl/.iank "$remote":
- fi
if (( ${#@} )); then
# Theres a couple ways to do this. im not sure whats best,
}
# kill off old shared socket then ssh
ssk() {
- m ssh -O exit "$@"
+ m ssh -O exit "$@" || [[ $? == 255 ]]
m sl "$@"
}
# plain limited ssh
[[ $1 ]] || { echo need arg; return 1; }
journalctl --unit=$vpn_service@$1 -f -n0 &
- s systemctl start $vpn_service@$1
+ sudo systemctl start $vpn_service@$1
# sometimes the ask-password agent does not work and needs a delay.
sleep .5
# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=779240
# noticed around 8-2017 after update from around stretch release
# on debian testing, even though the bug is much older.
- s systemd-tty-ask-password-agent
+ sudo systemd-tty-ask-password-agent
}
vpnoff() {
else
local vpn_service=openvpn
fi
- s systemctl stop $vpn_service@$1
+ sudo systemctl stop $vpn_service@$1
}
vpnoffc() { # vpn off client
ser stop openvpn-nn@client
xevkb() { xev -event keyboard; }
+ziva() { e "toot! i love dancing. fart"; }
+
# * misc stuff
# from curl cheat.sh/:bash_completion