bunch of fixes, change sy host, deploy some new 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 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 --now enable rss2email.timer
31 # off is in mail-setup. no reason for this to be in the rss2email block.
32 m systemctl --now enable btrbk.timer
33 else
34 m systemctl --now disable btrbk.timer
35
36 m systemctl stop rss2email.service
37 m systemctl --now disable rss2email.timer
38 # arbtt disabled for now
39 # for ((i=0; i<10; i++)); do
40 # killall arbtt-capture || break
41 # sleep 1
42 # if [[ $i == 9 ]]; then
43 # exit 1
44 # fi
45 # done
46 fi
47 fi
48
49 # todo: whats going on here? figure out if this should be removed.
50
51 # if dpkg -s radicale &>/dev/null; then
52 # if [[ $HOSTNAME == "$MAIL_HOST" ]]; then
53 # m systemctl restart radicale
54 # m systemctl enable radicale
55 # if [[ -e /etc/logrotate.d/radicale.disabled ]]; then
56 # m mv /etc/logrotate.d/radicale{.disabled,}
57 # fi
58 # else
59 # m systemctl stop radicale
60 # m systemctl disable radicale
61 # # weekly logrotate tries to restart radicale even if it's a disabled service in flidas.
62 # if [[ -e /etc/logrotate.d/radicale ]]; then
63 # m mv /etc/logrotate.d/radicale{,.disabled}
64 # fi
65 # fi
66 # fi
67
68
69 # todo: this needs to be disabled earlier than primary-setup in switch-mail-host
70
71 # if dpkg -s profile-sync-daemon &>/dev/null; then
72 # if [[ $HOSTNAME == "$MAIL_HOST" ]]; then
73 # m systemctl --user start psd
74 # m systemctl --user enable psd
75 # else
76 # m systemctl --user stop psd
77 # m systemctl --user disable psd
78 # fi
79 # fi
80
81
82 m /a/exe/mail-setup
83 exit 0