avoid sudo resolv alert on rerun
[distro-setup] / primary-setup
1 #!/bin/bash
2
3 # usage $0 [MAIL_HOST]
4 # setup things which involve being the primary host or not
5
6 set -eE -o pipefail
7 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
8
9
10 if [[ $EUID == 0 && ! $SUDO_USER ]]; then
11 echo "$0: error: requires running as nonroot or sudo"
12 exit 1
13 fi
14
15 if [[ $1 ]]; then
16 new_host=$1
17 sed -ri "s/MAIL_HOST=.*/MAIL_HOST=$new_host/" /a/bin/bash_unpublished/source-state
18 source /a/bin/bash_unpublished/source-state
19 fi
20
21 if [[ $HOSTNAME == "$MAIL_HOST" ]]; then
22 # arbtt disabled for now
23 #DISPLAY=:0 arbtt-capture --sample-rate=10 &
24 sudo systemctl start rss2email.timer
25 sudo systemctl enable rss2email.timer
26 sudo systemctl start btrbk.timer
27 sudo systemctl enable btrbk.timer
28
29 else
30 sudo systemctl stop rss2email.timer
31 sudo systemctl stop rss2email.service
32 sudo systemctl disable rss2email.timer
33 # arbtt disabled for now
34 # for ((i=0; i<10; i++)); do
35 # killall arbtt-capture || break
36 # sleep 1
37 # if [[ $i == 9 ]]; then
38 # exit 1
39 # fi
40 # done
41 fi
42
43 /a/exe/mail-setup
44 exit 0
45 :