2 # I, Ian Kelling, follow the GNU license recommendations at
3 # https://www.gnu.org/licenses/license-recommendations.en.html. They
4 # recommend that small programs, < 300 lines, be licensed under the
5 # Apache License 2.0. This file contains or is part of one or more small
6 # programs. If a small program grows beyond 300 lines, I plan to switch
9 # Copyright 2024 Ian Kelling
11 # Licensed under the Apache License, Version 2.0 (the "License");
12 # you may not use this file except in compliance with the License.
13 # You may obtain a copy of the License at
15 # http://www.apache.org/licenses/LICENSE-2.0
17 # Unless required by applicable law or agreed to in writing, software
18 # distributed under the License is distributed on an "AS IS" BASIS,
19 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 # See the License for the specific language governing permissions and
21 # limitations under the License.
24 # usage $0 [MAIL_HOST]
25 # setup things which involve being the primary host or not
27 set -e; .
/usr
/local
/lib
/bash-bear
; set +e
29 script_name
="${BASH_SOURCE[0]}"
30 script_name
="${script_name##*/}"
31 pre
="$script_name:${0##*/}:${SSH_CLIENT:+ $HOSTNAME:}"
32 m
() { printf "$pre %s\n" "$*"; "$@"; }
33 e
() { printf "$pre %s\n" "$*"; }
34 err
() { echo "[$(date +'%Y-%m-%d %H:%M:%S%z')]: $0: $*" >&2; }
39 if [[ ! -s /etc
/systemd
/system
/$service ]]; then
45 [[ $EUID == 0 ]] ||
exec sudo
-E "${BASH_SOURCE[0]}" "$@"
49 if [[ $new_host == localhost
]]; then
52 m
sed -ri "s/MAIL_HOST=.*/MAIL_HOST=$new_host/" /a
/bin
/bash_unpublished
/source-state
54 source /a
/bin
/bash_unpublished
/source-state
56 # fixing up a bad state that servers got in.
57 if [[ -e /dev
/shm
/iank-status
]]; then
58 chown iank.iank
/dev
/shm
/iank-status
62 if [[ $HOSTNAME == "$MAIL_HOST" ]]; then
67 # https://www.robustperception.io/how-to-have-labels-for-machine-roles
68 dir
=/var
/lib
/prometheus
/node-exporter
69 if [[ -e $dir ]]; then
70 cat > $dir/mailhost.prom
<<EOF
71 host_role{role="mailhost"} $mailhost_p
77 if [[ $HOSTNAME == "$MAIL_HOST" ||
$HOSTNAME == kd
]]; then
78 m systemctl
--now enable btrbk.timer
80 serm systemctl
--now disable btrbk.timer
84 if dpkg
-s rss2email
&>/dev
/null
; then
85 if [[ $HOSTNAME == "$MAIL_HOST" ]]; then
86 # arbtt disabled for now
87 #DISPLAY=:0 arbtt-capture --sample-rate=10 &
88 m systemctl
--now enable rss2email.timer
90 files
=(/sysd-mail-once
/btrbk
*)
91 if (( ${#files[@]} )); then
95 serm systemctl stop rss2email.service
96 serm systemctl
--now disable rss2email.timer
97 # arbtt disabled for now
98 # for ((i=0; i<10; i++)); do
99 # killall arbtt-capture || break
101 # if [[ $i == 9 ]]; then
108 # todo: whats going on here? figure out if this should be removed.
110 # if dpkg -s radicale &>/dev/null; then
111 # if [[ $HOSTNAME == "$MAIL_HOST" ]]; then
112 # m systemctl restart radicale
113 # m systemctl enable radicale
114 # if [[ -e /etc/logrotate.d/radicale.disabled ]]; then
115 # m mv /etc/logrotate.d/radicale{.disabled,}
118 # m systemctl stop radicale
119 # m systemctl disable radicale
120 # # weekly logrotate tries to restart radicale even if it's a disabled service in flidas.
121 # if [[ -e /etc/logrotate.d/radicale ]]; then
122 # m mv /etc/logrotate.d/radicale{,.disabled}
128 # todo: this needs to be disabled earlier than primary-setup in switch-mail-host
130 # if dpkg -s profile-sync-daemon &>/dev/null; then
131 # if [[ $HOSTNAME == "$MAIL_HOST" ]]; then
132 # m systemctl --user start psd
133 # m systemctl --user enable psd
135 # m systemctl --user stop psd
136 # m systemctl --user disable psd