+#
+# Usage:
+#
+# get-token $USER
+# - If user is root, call this script as $USER
+#
+# get-token $USER norecurse
+# - Don't recursively call this script, even if user if root
+
+REALUSER=$(whoami)
+USER=$1
+LOGFILE=/tmp/exim4/get-token-log.$USER
+
+if [ "$REALUSER" = "root" ]; then
+ if [ -n "$2" ]; then
+ echo "Error: running as root even after trying to change to $USER" \
+ > $LOGFILE
+ exit 1
+ fi
+
+ # Decide whether the user exists: getent returns 0 error code if so
+ getent passwd "$USER" >/dev/null
+ if [ $? -ne 0 ]; then
+ echo "$USER is not a local user, so ignoring them"
+ exit 1
+ else
+ exec su $USER -c "$0 $1 norecurse"
+ fi
+fi