ccomp less eless
eqcat() {
exiqgrep -i | while read -r i; do
- m exim -Mvh $i
- m exim -Mvb $i
- hr
- m exigrep $i /var/log/exim4/mainlog | cat ||:
+ hlm exim -Mvh $i
+ echo
+ hlm exim -Mvb $i
+ echo
+ hlm exigrep $i /var/log/exim4/mainlog | cat ||:
done
}
printf "$(tput setaf 5 2>/dev/null ||:)█$(tput sgr0 2>/dev/null||:)%.0s" $(eval echo "{1..${COLUMNS:-60}}")
echo
}
+# highlight
+hl() {
+ local col input_len=0
+ for arg; do
+ input_len=$((input_len + 1 + ${#arg}))
+ done
+ col=$((60 - input_len))
+ printf "\e[1;97;41m%s" "$*"
+ if (( col > 0 )); then
+ printf "\e[1;97;41m \e[0m%.0s" $(eval echo "{1..${col}}")
+ fi
+ echo
+}
+hlm() { hl "$*"; "$@"; }
hrcat() { local f; for f; do [[ -f $f ]] || continue; hr; echo "$f"; cat "$f"; done }
ser enable $service
fi
}
-soff() { # service go
- service=$1
- ser stop $service
- ser disable $service
+soff () {
+ for service; do
+ # ignore services that dont exist
+ if systemctl cat $service &>/dev/null; then
+ ser stop $service;
+ ser disable $service
+ fi
+ done
}
sgu() {
if $haveinfo && [[ $type == b ]]; then
info_sec=${tmp::10}
- read files_sec _ < <(find -L $SL_FILES_DIR -printf "%T@ %p\n" | sort -nr || [[ $? == 141 ]])
+ read files_sec _ < <(find -L $SL_FILES_DIR -printf "%T@ %p\n" | sort -nr || [[ $? == 141 || ${PIPESTATUS[0]} == 32 ]] )
files_sec=${files_sec%%.*}
if (( files_sec > info_sec )); then
dorsync=true
unix_time=$(date -d $(sed -r 's/(.{4})(..)(.{5})(..)(.*)/\1-\2-\3:\4:\5/' <<<${f#$vol.}) +%s)
printf "%s %s\n" $unix_time $s
# sort will fail
- done | sort -r | head -n 1 | awk '{print $2}' || [[ ${PIPESTATUS[1]} == 141 ]]
+ done | sort -r | head -n 1 | awk '{print $2}' || [[ ${PIPESTATUS[1]} == 141 || ${PIPESTATUS[0]} == 32 ]]
)
if [[ ! $last_snap ]]; then
# should not happen.
sudo systemctl stop nscd ||: # fails if already stopped
fi
+# http://strugglers.net/~andy/blog/2020/12/03/starting-services-only-when-the-network-is-ready-on-debiansystemd/
+systemctl enable ifupdown-wait-online.service
+
if bitfolk; then
# remove line like this: 85.119.82.128 je.iankelling.org je
# it messes with hostname -f.
# Copyright (C) 2019 Ian Kelling
# SPDX-License-Identifier: AGPL-3.0-or-later
+# todo: run mailping test after running, or otherwise
+# clear out terminal alert
+
+# todo: in err can we print out variables?
+
# todo setup better backup/sync of MAIL_HOST emails
# todo: reinstall bk with bigger filesystem
pre="${0##*/}:"
m() { printf "$pre %s\n" "$*"; "$@"; }
e() { printf "$pre %s\n" "$*"; }
-err() { echo "[$(date +'%Y-%m-%d %H:%M:%S%z')]: $0: $*" >&2; exit 1; }
+err() { printf "$pre %s\n" "$*" >&2; exit 1; }
reload=false
i() { # install file
local tmp tmpdir dest="$1"
[Service]
-Type=oneshot
+Type=simple
RemainAfterExit=true
PrivateNetwork=true
ExecStart=/usr/bin/flock -w 20 /tmp/newns.flock /a/bin/newns/newns -n 10.173.8 start mail
[Service]
Type=simple
PrivateNetwork=true
-ExecStartPre=/usr/bin/flock -w 20 /tmp/newns.flock /a/bin/newns/newns -n 10.173.8 start mail
ExecStart=/bin/sleep infinity
-ExecStopPost=/usr/bin/flock -w 20 /tmp/newns.flock /a/bin/newns/newns stop mail
[Install]
WantedBy=multi-user.target
$MAIL_HOST)
i /etc/systemd/system/unbound.service.d/nn.conf <<EOF
[Unit]
+After=mailnn.service
JoinsNamespaceOf=mailnn.service
BindsTo=mailnn.service
StartLimitIntervalSec=0
for unit in ${nn_progs[@]}; do
i /etc/systemd/system/$unit.service.d/nn.conf <<EOF
[Unit]
-After=network.target
Requires=mailvpn.service
-After=mailvpn.service
+After=network.target mailnn.service mailvpn.service
JoinsNamespaceOf=mailnn.service
BindsTo=mailnn.service
StartLimitIntervalSec=0
[Unit]
# this unit is configured to start and stop whenever
# openvpn-client-mail@mail does
-After=network.target
+After=network.target network-online.target mailnn.service mailvpn.service
+Wants=network-online.target
BindsTo=mailvpn.service
-After=mailvpn.service
JoinsNamespaceOf=mailnn.service
StartLimitIntervalSec=0
### end nextcloud settings
EOF
if [[ ! -e $rcdir/config/secret ]]; then
- base64 </dev/urandom | head -c24 >$rcdir/config/secret || [[ $? == 141 ]]
+ base64 </dev/urandom | head -c24 >$rcdir/config/secret || [[ $? == 141 || ${PIPESTATUS[0]} == 32 ]]
fi
secret=$(cat $rcdir/config/secret)
\$CONFIG['htaccess.RewriteBase'] = '/nextcloud';
\$CONFIG['trusted_domains'] = array (
0 => '$domain',
- );
+ );s
#\$CONFIG[''] = '';
fwrite(STDOUT, "<?php\n\\\$CONFIG = ");
var_export(\$CONFIG);
dc_smarthost='$smarthost'
EOF
- hostname -A|awk '{print $1}' |i /etc/mailname
+ hostname -f |i /etc/mailname
cat >>/etc/exim4/update-exim4.conf.conf <<EOF
# The manpage incorrectly states this will do header rewriting, but
fi
i /etc/systemd/system/exim4.service.d/override.conf <<'EOF'
[Unit]
-# without this on exim, we get these kind of errors in paniclog on shutdown:
+# without local-fs on exim, we get these kind of errors in paniclog on shutdown:
# Failed to create spool file /var/spool/exim4//input//1jCLxz-0008V4-V9-D: Permission denied
After=local-fs.target
-After=network.target
EOF
if ! mountpoint -q $sdir; then
stopifactive exim4 exim4in
# add any argument to say we are running interactively
if [[ $SUDO_USER && ! $1 ]]; then
int=true
+elif [[ $1 ]]; then
+ int=false
else
int=false
sleep 60
done
if [[ $bsub ]]; then
tmp=$(mktemp)
- # in testing, same subvol is 136 bytes. allow some overhead
- btrfs send --no-data -p $bsub $leaf | head -c 1000 > $tmp || [[ $? == 141 ]]
+ # in testing, same subvol is 136 bytes. allow some overhead. 32 happens sometimes under systemd.
+ # $ errno 32
+ # EPIPE 32 Broken pipe
+ btrfs send --no-data -p $bsub $leaf | head -c 1000 > $tmp || [[ $? == 141 || ${PIPESTATUS[0]} == 32 ]]
if (( $(stat -c%s $tmp) < 1000)); then
# example output for an empty diff:
# Found a valid Btrfs stream header, version 1
# fi
if [[ $HOSTNAME == "$MAIL_HOST" ]]; then
+ m sudo systemctl --user start psd
+ m sudo systemctl --user enable psd
m sudo systemctl start openvpn-client@hole
m sudo systemctl enable openvpn-client@hole
else
+ m sudo systemctl --user stop psd
+ m sudo systemctl --user disable psd
m sudo systemctl stop openvpn-client@hole
m sudo systemctl disable openvpn-client@hole
fi
# allow failure in case there are no snapshots yet.
# shellcheck disable=SC2012
shopt -u nullglob
- snaps=($(ls -1avdr /mnt/root/btrbk/$vol.20* 2>/dev/null |head -n1 || : ))
+ files=(/mnt/root/btrbk/$vol.20*)
shopt -s nullglob
+ snaps=()
+ if (( ${#files[@]} )); then
+ snaps=($(ls -1avdr "${files[@]}" 2>/dev/null |head -n1 || : ))
+ fi
now=$(date +%s)
maxtime=0
for s in ${snaps[@]}; do