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