run: drop to autobuild-ceph user before doing anything much
authorDan Mick <dan.mick@redhat.com>
Sat, 16 Jan 2016 05:21:29 +0000 (21:21 -0800)
committerDan Mick <dan.mick@redhat.com>
Sat, 16 Jan 2016 05:21:29 +0000 (21:21 -0800)
logrotate has changed such that, if root, it won't run if
logrotate.conf is not owned by root.  Since we really want to be
running as autobuild-ceph anyway, just do that first by reexecuting
ourselves with su - autobuild-ceph.

Signed-off-by: Dan Mick <dan.mick@redhat.com>
run

diff --git a/run b/run
index ef8324d43f1ab1d424fb7a3c96533ffcb8902173..c20354068b9281e00e2d8a4a4e1b822776b6b499 100755 (executable)
--- a/run
+++ b/run
@@ -1,29 +1,30 @@
 #!/bin/sh
 set -e
 
-if command -v logrotate >/dev/null; then
-  logrotate --state=logs/.logrotate.status logrotate.conf
-fi
-
-exec >>logs/stdout.log 2>>logs/stderr.log
-
-cd gitbuilder.git
-FILE_OWNER="$(stat --format='%U' out)"
+FILE_OWNER="$(stat --format='%U' gitbuilder.git/out)"
 CUR_USER="$(id -un)"
 if [ "$FILE_OWNER" = "root" ]; then
     echo "$0: root should never own the build tree, aborting." 1>&2
     exit 1
 fi
 
-if [ "$CUR_USER" = "$FILE_OWNER" ]; then
-    # we're already the right user
-
-    exec ../run-real
-elif [ "$CUR_USER" = "root" ]; then
-    # drop down to the right user;
+if [ "$CUR_USER" = "root" ]; then
+    # reexecute as the right user;
     # override /bin/false as shell in passwd
-    exec su -s /bin/sh -c ../run-real "$FILE_OWNER"
-else
+    echo "$0: I'm root, reexecuting as $FILE_OWNER"
+    exec su -s /bin/sh -c "$0 $*" $FILE_OWNER
+fi
+
+if [ "$CUR_USER" != "$FILE_OWNER" ]; then
     echo "$0: not root and not file owner, aborting." 1>&2
     exit 1
 fi
+
+if command -v logrotate >/dev/null; then
+  logrotate -v --state=logs/.logrotate.status logrotate.conf
+fi
+
+exec >>logs/stdout.log 2>>logs/stderr.log
+
+cd gitbuilder.git
+exec ../run-real