# which we could test for, but I can't think of a way to make that
# inherently limited to a single ssh command. I choose to set SendEnv
# and AcceptEnv ssh config vars to allow the environment variable
-# BASH_LOGIN_SHELL to propagate across ssh.
+# BASH_LOGIN_SHELL to propagate across ssh. This also requires that we
+# wrap ssh in interactive shells, because, once we export the var, it
+# will go into scripts and theres no way to automatically set it.
-# assume we want ssh commands to source this file if we are sourcing it,
-# and we haven't specified otherwise already
-[[ ! $BASH_LOGIN_SHELL ]] && export BASH_LOGIN_SHELL=true
-#BASH_LOGIN_SHELL=false # temporary override
# first conditions show that we are an ssh command without an interactive shell
if [[ $SSH_CONNECTION ]] \
&& [[ $- == *c* ]] \
&& [[ ! $SSH_TTY ]] \
&& [[ $- != *i* ]] \
- && [[ ! $BASH_LOGIN_SHELL == true ]]; then
+ && [[ $BASH_LOGIN_SHELL != true ]]; then
return 0
else
if [[ -r /etc/profile ]]; then
# works in addition to HISTCONTROL to do more flexible things
# it could also do the same things as HISTCONTROL and thus replace it,
# but meh. dunno why, but just " *" does glob expansion, so use [ ] to avoid it.
-HISTIGNORE='pass *:[ ]*:lom*:gram*'
+HISTIGNORE='pass *:[ ]*:otp *:oathtool *'
export BC_LINE_LENGTH=0
ssh $1 /tmp/${2##*/} "${@:2}"
}
+ssh() {
+ BASH_LOGIN_SHELL=true command ssh "$@"
+}
sss() { # ssh solo
ssh -oControlMaster=no -oControlPath=/ "$@"
}
# always run this first, edit the test files, then run the following
testsieve() {
- _dosieve ~/sieve/maintest.sieve INBOX delete
+ _dosieve ~/sieve/maintest.sieve ${1:-INBOX} delete
}
runsieve() {
c ~/sieve; cp personal{test,}.sieve; cp lists{test,}.sieve
- _dosieve ~/sieve/main.sieve -eW INBOX delete
+ _dosieve ~/sieve/main.sieve -eW ${1:-INBOX} delete
}
# mail related
if [[ -e /nocow/btrfs-stale ]] && ((`command ls -AUq /nocow/btrfs-stale|wc -l`)); then
ps_char="! $ps_char"
fi
+ if [[ -e /nocow/mailtest-failure ]]; then
+ ps_char="@#$@#$ $ps_char"
+ fi
+ source /a/bin/bash_unpublished/source-state
if [[ ! $SSH_CLIENT && $MAIL_HOST != $HOSTNAME ]]; then
ps_char="@ $ps_char"
fi
# todo: if we cancel in the middle of a btrfs send, then run again immediately, the received subvolume doesn't get a Received UUID: field, and we won't mount it. Need to figure out a solution that will fix this.
-set -eE -o pipefail
-trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
+err-bash-trace() {
+ local -i argc_index=0 frame i start=${1:-0} max_indent=8 indent
+ local source
+ local extdebug=false
+ if [[ $(shopt -p extdebug) == *-s* ]]; then
+ extdebug=true
+ fi
+ for ((frame=0; frame < ${#FUNCNAME[@]}-1; frame++)); do
+ argc=${BASH_ARGC[frame]}
+ argc_index+=$argc
+ ((frame < start)) && continue
+ if (( ${#BASH_SOURCE[@]} > 1 )); then
+ source="${BASH_SOURCE[frame+1]}:${BASH_LINENO[frame]}:"
+ fi
+ indent=$((frame-start + 1))
+ indent=$((indent < max_indent ? indent : max_indent))
+ printf "%${indent}s↳%sin \`%s" '' "$source" "${FUNCNAME[frame]}"
+ if $extdebug; then
+ for ((i=argc_index-1; i >= argc_index-argc; i--)); do
+ printf " %s" "${BASH_ARGV[i]}"
+ done
+ fi
+ echo \'
+ done
+ return 0
+}
+err-catch() {
+ set -E; shopt -s extdebug
+ _err-trap() {
+ err=$?
+ exec >&2
+ set +x
+ echo "${BASH_SOURCE[1]}:${BASH_LINENO[0]}: \`$BASH_COMMAND' returned $err"
+ err-bash-trace 2
+ set -e # err trap does not work within an error trap
+ "${_errcatch_cleanup[@]:-:}" # note :-: is to be compatible with set -u
+ echo "$0: exiting with code $err"
+ exit $err
+ }
+ trap _err-trap ERR
+ set -o pipefail
+}
+err-catch
+
[[ $EUID == 0 ]] || exec sudo -E "$BASH_SOURCE" "$@"
die() { printf "$pre %s\n" "$*" >&2; exit 1; }
# latest $MAIL_HOST
-if [[ -e /b/bash_unpublished/source-semi-priv ]]; then
- source /b/bash_unpublished/source-semi-priv
+if [[ -e /b/bash_unpublished/source-state ]]; then
+ source /b/bash_unpublished/source-state
fi
# note q is owned by root:1000
if ping -q -c1 -w1 iank.vpn.office.fsf.org &>/dev/null; then
home=iank.vpn.office.fsf.org
else
- home=$HOME_DOMAIN
+ home=b8.nz
fi
;;&
kw)
--- /dev/null
+#!/bin/bash
+set -eE -o pipefail
+trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
+
+cd /m/md/l/testignore/new
+shopt -s nullglob
+
+last_sec=0
+for file in *; do
+ if [[ $file -nt $latest ]]; then
+ latest=$file
+ fi
+done
+
+if [[ $latest ]]; then
+ last_sec=$(awk '/^Subject: / {print $3}' $latest)
+fi
+
+now=$(date +%s)
+limit=$(( now - 60 * 22 ))
+
+if (( last_sec < limit )); then
+ echo $HOSTNAME mailtest failure
+ touch /nocow/mailtest-failure
+else
+ rm -f /nocow/mailtest-failure
+fi
+
+find -type f -mtime +1 -delete
x="$(readlink -f "$BASH_SOURCE")"; cd ${x%/*}
-e() { echo "$*"; "$@"; }
-
# scripts that would interfere with unmounting /a, put them elsewhere
-e install /a/bin/log-quiet/log-once switch-mail-host btrbk-run mount-latest-subvol check-subvol-stale /usr/local/bin
+echo install /a/bin/log-quiet/log-once switch-mail-host btrbk-run mount-latest-subvol check-subvol-stale /usr/local/bin
+install /a/bin/log-quiet/log-once switch-mail-host btrbk-run mount-latest-subvol check-subvol-stale /usr/local/bin
exim4-config exim4/use_split_config boolean true
EOF
-source /a/bin/bash_unpublished/source-semi-priv
+source /a/bin/bash_unpublished/source-state
mkdir -p /etc/exim4/conf.d/{main,transport,auth,router}
cat >/etc/exim4/rcpt_local_acl <<'EOF'
[[ $EUID == 0 ]] || exec sudo "$BASH_SOURCE" "$@"
-f=/a/bin/bash_unpublished/source-semi-priv
+f=/a/bin/bash_unpublished/source-state
if [[ -e $f ]]; then
source $f
fi
# Other destinations for which mail is accepted:
# iank.bid is for testing
# mail.iankelling.org is for machines i own
-exim4-config exim4/dc_other_hostnames string *.iankelling.org;iankelling.org;*iank.bid;iank.bid;*zroe.org;zroe.org;*.b8.nz;b8.nz
-
+exim4-config exim4/dc_other_hostnames string *.iankelling.org;iankelling.org;*iank.bid;iank.bid;*zroe.org;zroe.org;*.b8.nz;b8.nz;*.fsf.org;fsf.org
systemctl restart exim4
systemctl enable exim4
+
+if [[ $HOSTNAME == $MAIL_HOST ]]; then
+ cat >/etc/cron.d/mailtest <<'EOF'
+*/10 * * * * iank echo body_test | mail -s "primary_test $(date +%s) $(date +%Y-%m-%dT%H:%M:%S%z)" iank@posteo.de
+2/10 * * * * root /usr/local/bin/mailtest-check
+EOF
+ cp /a/bin/distro-setup/filesystem/usr/local/bin/mailtest-check /usr/local/bin
+else
+ rm -f /etc/cron.d/mailtest
+fi
+
# MAIL_HOST also does radicale, and easier to start and stop it here
# for when MAIL_HOST changes, so radicale gets the synced files and
# does not stop us from remounting /o.
}
-errcatch() {
- set -E; shopt -s extdebug
- _err-trap() {
- err=$?
- exec >&2
- set +x
- echo "${BASH_SOURCE[1]}:${BASH_LINENO[0]}:in \`$BASH_COMMAND' returned $err"
- bash-trace 2
- echo "$0: exiting with code $err"
- exit $err
- }
- trap _err-trap ERR
- set -o pipefail
-}
-bash-trace() {
- local -i argc_index=0 frame i start=${1:-1} max_indent=8 indent
+err-bash-trace() {
+ local -i argc_index=0 frame i start=${1:-0} max_indent=8 indent
local source
local extdebug=false
if [[ $(shopt -p extdebug) == *-s* ]]; then
extdebug=true
fi
-
for ((frame=0; frame < ${#FUNCNAME[@]}-1; frame++)); do
argc=${BASH_ARGC[frame]}
argc_index+=$argc
if (( ${#BASH_SOURCE[@]} > 1 )); then
source="${BASH_SOURCE[frame+1]}:${BASH_LINENO[frame]}:"
fi
- indent=$((frame-start+1))
+ indent=$((frame-start + 1))
indent=$((indent < max_indent ? indent : max_indent))
printf "%${indent}s↳%sin \`%s" '' "$source" "${FUNCNAME[frame]}"
if $extdebug; then
fi
echo \'
done
+ return 0
+}
+err-catch() {
+ set -E; shopt -s extdebug
+ _err-trap() {
+ err=$?
+ exec >&2
+ set +x
+ echo "${BASH_SOURCE[1]}:${BASH_LINENO[0]}: \`$BASH_COMMAND' returned $err"
+ err-bash-trace 2
+ set -e # err trap does not work within an error trap
+ "${_errcatch_cleanup[@]:-:}" # note :-: is to be compatible with set -u
+ echo "$0: exiting with code $err"
+ exit $err
+ }
+ trap _err-trap ERR
+ set -o pipefail
}
-errcatch
+err-catch
tu() {
while read -r line; do
if [[ $1 ]]; then
new_host=$1
- sed -ri "s/MAIL_HOST=.*/MAIL_HOST=$new_host/" /a/bin/bash_unpublished/source-semi-priv
- source /a/bin/bash_unpublished/source-semi-priv
+ sed -ri "s/MAIL_HOST=.*/MAIL_HOST=$new_host/" /a/bin/bash_unpublished/source-state
+ source /a/bin/bash_unpublished/source-state
fi
if [[ $HOSTNAME == $MAIL_HOST ]]; then
-#!/bin/bash -l
-set -x
+#!/bin/bash
+
[[ $EUID == 0 ]] || exec sudo -E "$BASH_SOURCE" "$@"
+if [[ -e /b/errhandle/err ]]; then
+ source /b/errhandle/err
+else
+ set -eE -o pipefail
+ trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
+fi
+source /a/bin/bash_unpublished/source-state
+source /a/bin/distro-functions/src/package-manager-abstractions
# davdroid setup instructions at the bottom
# main docs:
d=/etc/systemd/system/radicale.service.d
mkdir -p $d
-sudo dd of=$d/override.conf <<EOF
+cat >$d/override.conf <<EOF
[Unit]
# this unit is configured to start and stop whenever openvpn-client@mail.service
# does
[Install]
RequiredBy=$vpn_ser@mail.service
EOF
-ser daemon-reload # not sure this is needed
+systemctl daemon-reload # not sure this is needed
pi-nostart radicale
# I moved /var/lib/radicale after it's initialization.
# I did a sudo -u radicale git init in the collections subfolder
# after it gets created, per the git docs.
-lnf -T /o/radicale /var/lib/radicale
+/a/exe/lnf -T /o/radicale /var/lib/radicale
# from https://www.williamjbowman.com/blog/2015/07/24/setting-up-webdav-caldav-and-carddav-servers/
setini hosts 10.8.0.4:5232 server
if [[ $HOSTNAME == $MAIL_HOST ]]; then
- sgo radicale
+ systemctl start radicale
+ systemctl enable radicale
fi
# disable power management feature, set to 240 min sync interval,
old_host=$1
new_host=$2
-source /a/bin/bash_unpublished/source-semi-priv
+source /a/bin/bash_unpublished/source-state
if [[ $old_host != $MAIL_HOST ]]; then
read -p "warning: \$old_host != \$MAIL_HOST: $old_host != $MAIL_HOST, proceed? y/N "
fi
echo "$0: at_home = $at_home"
-source /a/bin/bash_unpublished/source-semi-priv
+source /a/bin/bash_unpublished/source-state
#### begin convert private hostnames to public hostnames ####
#if ! $at_home; then
# for var in old_host new_host; do