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