minor bug fix
[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 source /usr/local/lib/err
7
8 pre="${0##*/}:"
9 m() { printf "$pre %s\n" "$*"; "$@"; }
10 e() { printf "$pre %s\n" "$*"; }
11 err() { echo "[$(date +'%Y-%m-%d %H:%M:%S%z')]: $0: $*" >&2; }
12
13
14 if [[ $EUID == 0 && ! $SUDO_USER ]]; then
15 err "requires running as nonroot or sudo"
16 exit 1
17 fi
18
19 if [[ $1 ]]; then
20 new_host=$1
21 m sed -ri "s/MAIL_HOST=.*/MAIL_HOST=$new_host/" /a/bin/bash_unpublished/source-state
22 source /a/bin/bash_unpublished/source-state
23 fi
24
25 if [[ $HOSTNAME == "$MAIL_HOST" ]]; then
26 # arbtt disabled for now
27 #DISPLAY=:0 arbtt-capture --sample-rate=10 &
28 m sudo systemctl start rss2email.timer
29 m sudo systemctl enable rss2email.timer
30 m sudo systemctl start btrbk.timer
31 m sudo systemctl enable btrbk.timer
32
33 else
34 m sudo systemctl stop rss2email.timer
35 m sudo systemctl stop rss2email.service
36 m sudo systemctl disable rss2email.timer
37 # arbtt disabled for now
38 # for ((i=0; i<10; i++)); do
39 # killall arbtt-capture || break
40 # sleep 1
41 # if [[ $i == 9 ]]; then
42 # exit 1
43 # fi
44 # done
45 fi
46
47 m /a/exe/mail-setup
48 exit 0
49 :