fixes
[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 [[ $EUID == 0 ]] || exec sudo -E "${BASH_SOURCE[0]}" "$@"
15
16 if [[ $1 ]]; then
17 new_host=$1
18 if [[ $new_host == localhost ]]; then
19 new_host=$HOSTNAME
20 fi
21 m sed -ri "s/MAIL_HOST=.*/MAIL_HOST=$new_host/" /a/bin/bash_unpublished/source-state
22 fi
23 source /a/bin/bash_unpublished/source-state
24
25
26 if dpkg -s rss2email &>/dev/null; then
27 if [[ $HOSTNAME == "$MAIL_HOST" ]]; then
28 # arbtt disabled for now
29 #DISPLAY=:0 arbtt-capture --sample-rate=10 &
30 m systemctl start rss2email.timer
31 m systemctl enable rss2email.timer
32 # off is in mail-setup. no reason for this to be in the rss2email block.
33 m systemctl start btrbk.timer
34 m systemctl enable btrbk.timer
35
36 else
37 m systemctl stop rss2email.timer
38 m systemctl stop rss2email.service
39 m systemctl disable rss2email.timer
40 # arbtt disabled for now
41 # for ((i=0; i<10; i++)); do
42 # killall arbtt-capture || break
43 # sleep 1
44 # if [[ $i == 9 ]]; then
45 # exit 1
46 # fi
47 # done
48 fi
49 fi
50
51 # todo: whats going on here? figure out if this should be removed.
52
53 # if dpkg -s radicale &>/dev/null; then
54 # if [[ $HOSTNAME == "$MAIL_HOST" ]]; then
55 # m systemctl restart radicale
56 # m systemctl enable radicale
57 # if [[ -e /etc/logrotate.d/radicale.disabled ]]; then
58 # m mv /etc/logrotate.d/radicale{.disabled,}
59 # fi
60 # else
61 # m systemctl stop radicale
62 # m systemctl disable radicale
63 # # weekly logrotate tries to restart radicale even if it's a disabled service in flidas.
64 # if [[ -e /etc/logrotate.d/radicale ]]; then
65 # m mv /etc/logrotate.d/radicale{,.disabled}
66 # fi
67 # fi
68 # fi
69
70
71 # todo: this needs to be disabled earlier than primary-setup in switch-mail-host
72
73 # if dpkg -s profile-sync-daemon &>/dev/null; then
74 # if [[ $HOSTNAME == "$MAIL_HOST" ]]; then
75 # m systemctl --user start psd
76 # m systemctl --user enable psd
77 # else
78 # m systemctl --user stop psd
79 # m systemctl --user disable psd
80 # fi
81 # fi
82
83
84 m /a/exe/mail-setup
85 exit 0