X-Git-Url: https://iankelling.org/git/?a=blobdiff_plain;f=primary-setup;h=df30f294662019352acd32ac79d9251a7f391b87;hb=6061d88c7d5beda3e974943eb8676f7c39d4ae9f;hp=4641c9340908b29d4ed365fdcbb822c2630003fc;hpb=b857462732e15f455e41f26e3048a390d7b399c0;p=distro-setup diff --git a/primary-setup b/primary-setup index 4641c93..df30f29 100755 --- a/primary-setup +++ b/primary-setup @@ -1,36 +1,69 @@ #!/bin/bash # usage $0 [MAIL_HOST] +# setup things which involve being the primary host or not -set -eE -o pipefail -trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR +source /usr/local/lib/err -# setup things which involve being the primary host or not +pre="${0##*/}:" +m() { printf "$pre %s\n" "$*"; "$@"; } +e() { printf "$pre %s\n" "$*"; } +err() { echo "[$(date +'%Y-%m-%d %H:%M:%S%z')]: $0: $*" >&2; } + + +if [[ $EUID == 0 && ! $SUDO_USER ]]; then + err "requires running as nonroot or sudo" + exit 1 +fi 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 + if [[ $new_host == localhost ]]; then + new_host=$HOSTNAME + fi + m 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 - DISPLAY=:0 arbtt-capture --sample-rate=10 & - sudo systemctl start rss2email.timer - sudo systemctl enable rss2email.timer +if [[ $HOSTNAME == "$MAIL_HOST" ]]; then + # arbtt disabled for now + #DISPLAY=:0 arbtt-capture --sample-rate=10 & + m sudo systemctl start rss2email.timer + m sudo systemctl enable rss2email.timer + m sudo systemctl start btrbk.timer + m sudo systemctl enable btrbk.timer else - for ((i=0; i<10; i++)); do - killall arbtt-capture || break - sleep 1 - if [[ $i == 9 ]]; then - exit 1 + m sudo systemctl stop rss2email.timer + m sudo systemctl stop rss2email.service + m sudo systemctl disable rss2email.timer + # arbtt disabled for now + # for ((i=0; i<10; i++)); do + # killall arbtt-capture || break + # sleep 1 + # if [[ $i == 9 ]]; then + # exit 1 + # fi + # done +fi + +if dpkg -s radicale &>/dev/null; then + if [[ $HOSTNAME == "$MAIL_HOST" ]]; then + m sudo systemctl restart radicale + m sudo systemctl enable radicale + if [[ -e /etc/logrotate.d/radicale.disabled ]]; then + m sudo mv /etc/logrotate.d/radicale{.disabled,} + fi + else + m sudo systemctl stop radicale + m sudo systemctl disable radicale + # weekly logrotate tries to restart radicale even if it's a disabled service in flidas. + if [[ -e /etc/logrotate.d/radicale ]]; then + m sudo mv /etc/logrotate.d/radicale{,.disabled} fi - sudo systemctl stop rss2email.timer - sudo systemctl stop rss2email.service - sudo systemctl disable rss2email.timer - done + fi fi -mail-setup exim4 +m /a/exe/mail-setup exit 0 :