ci = commit
lol = log --graph --pretty=oneline --abbrev-commit --all
dt = difftool
+# https://stackoverflow.com/questions/17369254/is-there-a-way-to-cause-git-reflog-to-show-a-date-alongside-each-entry
+rl = reflog --format='%C(auto)%h %<|(17)%gd %C(blue)%ci%C(reset) %s'
[core]
excludesfile = ~/.gitignore_global
--- /dev/null
+#!/bin/bash
+# Copyright (C) 2019 Ian Kelling
+# SPDX-License-Identifier: AGPL-3.0-or-later
+
+source /a/bin/errhandle/err
+
+[[ $EUID == 0 ]] || exec sudo -E "${BASH_SOURCE[0]}" "$@"
+
+# shellcheck source=/a/bin/ds/.bashrc
+export LC_USEBASHRC=t; if [[ -s ~/.bashrc ]]; then . ~/.bashrc; fi
+
+# dependency of node exporter, per README.md
+pi python3-passlib
+
+# after running ansible, run
+# conflink
+# ser restart prometheus
---
-- hosts: kd.b8.nz
+- hosts: localhost
roles:
- role: prom
tags: a
# key_file: /etc/node_exporter/privkey.pem
node_exporter_web_listen_address: "127.0.1.1:9100"
node_exporter_basic_auth_users:
- prom: incarnadine.bloodied.maker
+ prom: "incarnadine.bloodied.maker"
- role: alertmanager
alertmanager_smtp:
}
_khfix_common() {
- local host ip port
+ local host ip port file key
read -r host ip port < <(timeout -s 9 2 ssh -oBatchMode=yes -oControlMaster=no -oControlPath=/ -v $1 |& sed -rn "s/debug1: Connecting to ([^ ]+) \[([^\]*)] port ([0-9]+).*/\1 \2 \3/p" ||: )
+ file=$(readlink -f ~/.ssh/known_hosts)
if [[ ! $ip ]]; then
echo "khfix: ssh failed"
return 1
ip_entry=$ip
host_entry=$host
fi
+ tmpfile=$(mktemp)
if [[ $host != $ip ]]; then
- m ssh-keygen -R "$host_entry" -f $(readlink -f ~/.ssh/known_hosts)
- ll ~/.ssh/known_hosts
+ key=$(ssh-keygen -F "$host_entry" -f $file | sed -r 's/^.*([^ ]+ +[^ ]+) *$/\1/')
+ if [[ $key ]]; then
+ grep -Fv "$key" "$file" | sponge "$file"
+ fi
+ fi
+ key=$(ssh-keygen -F "$ip_entry" -f $file | sed -r 's/^.*([^ ]+ +[^ ]+) *$/\1/')
+ if [[ $key ]]; then
+ grep -Fv "$key" "$file" | sponge "$file"
fi
- m ssh-keygen -R "$ip_entry" -f $(readlink -f ~/.ssh/known_hosts)
ll ~/.ssh/known_hosts
rootsshsync
}
local l base
if [[ $1 == /* ]]; then
base=${1##*/}
- if mountpoint /mnt/$base; then
+ if mountpoint -q /mnt/$base; then
return 0
fi
- l=$(sudo losetup -f)
- sudo losetup $l $1
- if ! sudo cryptsetup luksOpen $l $base; then
- sudo losetup -d $l
- return 1
+ l=$(losetup -j $1 | sed -rn 's/^([^ ]+): .*/\1/p' | head -n1 ||:)
+ if [[ ! $l ]]; then
+ l=$(sudo losetup -f)
+ sudo losetup $l $1
+ fi
+ if ! sudo cryptsetup status /dev/mapper/$base &>/dev/null; then
+ if ! sudo cryptsetup luksOpen $l $base; then
+ sudo losetup -d $l
+ return 1
+ fi
fi
sudo mkdir -p /mnt/$base
sudo mount /dev/mapper/$base /mnt/$base
if mountpoint /mnt/$base &>/dev/null; then
sudo umount /mnt/$base
fi
- l=$(sudo cryptsetup status /dev/mapper/$base|sed -rn 's/^\s*device:\s*(.*)/\1/p')
- sudo cryptsetup luksClose /dev/mapper/$base || return 1
- sudo losetup -d $l
+ if sudo cryptsetup status /dev/mapper/$base &>/dev/null; then
+ if ! sudo cryptsetup luksClose /dev/mapper/$base; then
+ echo lom: failed cryptsetup luksClose /dev/mapper/$base
+ return 1
+ fi
+ fi
+ l=$(losetup -j $1 | sed -rn 's/^([^ ]+): .*/\1/p' | head -n1 ||:)
+ if [[ $l ]]; then
+ sudo losetup -d $l
+ else
+ echo lom: warning: no loopback device found
+ fi
fi
}
sdnbash() { # systemd namespace bash
local unit=$1
- m sudo nsenter -t $(systemctl status $unit | sed -n '/^ *Main PID:/s/[^0-9]//gp') -n -m sudo -u $USER -i bash
+ m sudo nsenter -t $(systemctl show --property MainPID --value $unit') -n -m sudo -u $USER -i bash
}
mailnnbash() {
- m sudo nsenter -t $(systemctl status mailnn| sed -n '/^ *Main PID:/s/[^0-9]//gp') -n -m sudo -u $USER -i bash
+ m sudo nsenter -t $(systemctl show --property MainPID --value mailnn') -n -m sudo -u $USER -i bash
}
mailvpnbash() {
}
spamnn() {
local spamdpid
- spamdpid=$(systemctl status spamassassin| sed -n '/^ *Main PID:/s/[^0-9]//gp')
+ spamdpid=$(systemctl show --property MainPID --value spamassassin)
m sudo nsenter -t $spamdpid -n -m sudo -u Debian-exim spamassassin "$@"
}
unboundbash() {
}
mailnncheck() {
- local pid ns mailnn
- for p in mailnn mailvpn unbound dovecot spamassassin exim4 radicale; do
- pid=$(s systemctl status $p| sed -n '/^ *Main PID:/s/[^0-9]//gp')
+ local p pid ns mailnn
+ # mailvpn would belong on the list if using openvpn
+ for p in mailnn unbound dovecot spamassassin exim4 radicale; do
+ case $p in
+ exim4|radicale)
+ pid=$(ps -eo pid,cgroup | grep /system.slice/$p.service | awk '{print $1}')
+ ;;
+ *)
+ pid=$(s systemctl show --property MainPID --value $p)
+ ;;
+ esac
+ echo p=$p pid=$pid
if [[ ! $pid ]]; then
echo failed to find pid for $p
continue
sed -i "/$regex/d" $pl
fi
+ # this is a strange message due to running as nonroot
+ # regex='exim user lost privilege for using -C option'
+ # sed -i "/$regex/d" $pl
+
# seems to randomly be caused by
# Starting exim4-base housekeeping, exim4-base.service
regex="^[^ ]* 00:00:0.* Failed writing transport results to pipe: Broken pipe$"
folders=(/m/md/l/testignore)
froms=(testignore@je.b8.nz testignore@expertpathologyreview.com testignore@amnimal.ninja ian@iankelling.org z@zroe.org iank@gnu.org)
if ! $int; then
- timeout 120 rsync -e "ssh -oIdentitiesOnly=yes -F /dev/null -i /root/.ssh/jtuttle" -t --inplace -r 'jtuttle@fencepost.gnu.org:/home/j/jtuttle/Maildir/new/' /m/md/l/testignore/new
+ timeout 120 rsync --chown iank:iank -e "ssh -oIdentitiesOnly=yes -F /dev/null -i /root/.ssh/jtuttle" -t --inplace -r 'jtuttle@fencepost.gnu.org:/home/j/jtuttle/Maildir/new/' /m/md/l/testignore/new
fi
;;
esac
done
fi
+# if [[ $(grep -v "exim user lost privilege for using -C option" /var/log/exim4/paniclog 2>/dev/null ||:) ]]; then
if [[ -s /var/log/exim4/paniclog ]]; then
chars+=("PANIC!")
# leave it up to epanic-clean to send email notification