robustness
[distro-setup] / primary-setup
index 4ce132c3c94452274079ee66917c73b0f50051d7..30c4222a7bc9c3cdfb6885546a147c4b8225438f 100755 (executable)
@@ -1,16 +1,21 @@
 #!/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 [[ ! $SUDO_USER || $EUID == 0 ]]; 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
@@ -33,6 +38,6 @@ else
   # done
 fi
 
-mail-setup
+/a/exe/mail-setup
 exit 0
 :