From: Dan Mick Date: Sat, 16 Jan 2016 05:21:29 +0000 (-0800) Subject: run: drop to autobuild-ceph user before doing anything much X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=9864199effb1c74c281a18448331de9dbce78296;p=autobuild-ceph.git run: drop to autobuild-ceph user before doing anything much 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 --- diff --git a/run b/run index ef8324d..c203540 100755 --- 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