various improvements
[distro-setup] / primary-setup
index 4641c9340908b29d4ed365fdcbb822c2630003fc..09ae728bc6c02c13a7b61fbab1951da362023154 100755 (executable)
@@ -1,36 +1,45 @@
 #!/bin/bash
 
 # usage $0 [MAIL_HOST]
+# setup things which involve being the primary host or not
 
 set -eE -o pipefail
 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
 
-# setup things which involve being the primary host or not
+
+if [[ $EUID == 0 && ! $SUDO_USER ]]; then
+  echo "$0: error: requires running as nonroot or sudo"
+  exit 1
+fi
 
 if [[ $1 ]]; then
   new_host=$1
-  sed -ri "s/MAIL_HOST=.*/MAIL_HOST=$new_host/" /a/bin/bash_unpublished/source-semi-priv
-  source /a/bin/bash_unpublished/source-semi-priv
+  sed -ri "s/MAIL_HOST=.*/MAIL_HOST=$new_host/" /a/bin/bash_unpublished/source-state
+  source /a/bin/bash_unpublished/source-state
 fi
 
-if [[ $HOSTNAME == $MAIL_HOST ]]; then
-  DISPLAY=:0 arbtt-capture --sample-rate=10 &
+if [[ $HOSTNAME == "$MAIL_HOST" ]]; then
+  # arbtt disabled for now
+  #DISPLAY=:0 arbtt-capture --sample-rate=10 &
   sudo systemctl start rss2email.timer
   sudo systemctl enable rss2email.timer
+  sudo systemctl start btrbk.timer
+  sudo systemctl enable btrbk.timer
 
 else
-  for ((i=0; i<10; i++)); do
-    killall arbtt-capture || break
-    sleep 1
-    if [[ $i == 9 ]]; then
-      exit 1
-    fi
-    sudo systemctl stop rss2email.timer
-    sudo systemctl stop rss2email.service
-    sudo systemctl disable rss2email.timer
-  done
+  sudo systemctl stop rss2email.timer
+  sudo systemctl stop rss2email.service
+  sudo systemctl disable rss2email.timer
+  # arbtt disabled for now
+  # for ((i=0; i<10; i++)); do
+  #   killall arbtt-capture || break
+  #   sleep 1
+  #   if [[ $i == 9 ]]; then
+  #     exit 1
+  #   fi
+  # done
 fi
 
-mail-setup exim4
+/a/exe/mail-setup
 exit 0
 :