fixes and some improvements
[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 mailhost_p=1
20 new_host=$HOSTNAME
21 else
22 mailhost_p=0
23 fi
24
25 # https://www.robustperception.io/how-to-have-labels-for-machine-roles
26 dir=/var/lib/prometheus/node-exporter
27 if [[ -e $dir ]]; then
28 cat > $dir/mailhost.prom <<EOF
29 host_role{role="mailhost"} $mailhost_p
30 EOF
31 fi
32
33 m sed -ri "s/MAIL_HOST=.*/MAIL_HOST=$new_host/" /a/bin/bash_unpublished/source-state
34 fi
35 source /a/bin/bash_unpublished/source-state
36
37 # fixing up a bad state that servers got in.
38 if [[ -e /dev/shm/iank-status ]]; then
39 chown iank.iank /dev/shm/iank-status
40 fi
41
42
43 if [[ $HOSTNAME == "$MAIL_HOST" || $HOSTNAME == kd ]]; then
44 m systemctl --now enable btrbk.timer
45 else
46 m systemctl --now disable btrbk.timer
47 fi
48
49
50 if dpkg -s rss2email &>/dev/null; then
51 if [[ $HOSTNAME == "$MAIL_HOST" ]]; then
52 # arbtt disabled for now
53 #DISPLAY=:0 arbtt-capture --sample-rate=10 &
54 m systemctl --now enable rss2email.timer
55 else
56 files=(/sysd-mail-once/btrbk*)
57 if (( ${#files[@]} )); then
58 rm -f ${files[@]}
59 fi
60
61 m systemctl stop rss2email.service
62 m systemctl --now disable rss2email.timer
63 # arbtt disabled for now
64 # for ((i=0; i<10; i++)); do
65 # killall arbtt-capture || break
66 # sleep 1
67 # if [[ $i == 9 ]]; then
68 # exit 1
69 # fi
70 # done
71 fi
72 fi
73
74 # todo: whats going on here? figure out if this should be removed.
75
76 # if dpkg -s radicale &>/dev/null; then
77 # if [[ $HOSTNAME == "$MAIL_HOST" ]]; then
78 # m systemctl restart radicale
79 # m systemctl enable radicale
80 # if [[ -e /etc/logrotate.d/radicale.disabled ]]; then
81 # m mv /etc/logrotate.d/radicale{.disabled,}
82 # fi
83 # else
84 # m systemctl stop radicale
85 # m systemctl disable radicale
86 # # weekly logrotate tries to restart radicale even if it's a disabled service in flidas.
87 # if [[ -e /etc/logrotate.d/radicale ]]; then
88 # m mv /etc/logrotate.d/radicale{,.disabled}
89 # fi
90 # fi
91 # fi
92
93
94 # todo: this needs to be disabled earlier than primary-setup in switch-mail-host
95
96 # if dpkg -s profile-sync-daemon &>/dev/null; then
97 # if [[ $HOSTNAME == "$MAIL_HOST" ]]; then
98 # m systemctl --user start psd
99 # m systemctl --user enable psd
100 # else
101 # m systemctl --user stop psd
102 # m systemctl --user disable psd
103 # fi
104 # fi
105
106
107 m /a/exe/mail-setup
108 exit 0