Blame rabbitmq-script-wrapper

Hubert Plociniczak 1b1224
#!/bin/sh
f44ad9
##  The contents of this file are subject to the Mozilla Public License
f44ad9
##  Version 1.1 (the "License"); you may not use this file except in
f44ad9
##  compliance with the License. You may obtain a copy of the License
f44ad9
##  at http://www.mozilla.org/MPL/
Hubert Plociniczak 1b1224
##
f44ad9
##  Software distributed under the License is distributed on an "AS IS"
f44ad9
##  basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
f44ad9
##  the License for the specific language governing rights and
f44ad9
##  limitations under the License.
Hubert Plociniczak 1b1224
##
f44ad9
##  The Original Code is RabbitMQ.
Hubert Plociniczak 1b1224
##
f44ad9
##  The Initial Developer of the Original Code is VMware, Inc.
f44ad9
##  Copyright (c) 2007-2011 VMware, Inc.  All rights reserved.
Hubert Plociniczak 1b1224
##
Hubert Plociniczak 1b1224
Hubert Plociniczak cc9fdf
# Escape spaces and quotes, because shell is revolting.
Hubert Plociniczak cc9fdf
for arg in "$@" ; do
Hubert Plociniczak cc9fdf
	# Escape quotes in parameters, so that they're passed through cleanly.
Hubert Plociniczak 1b1224
	arg=$(sed -e 's/"/\\"/g' <<-END
Hubert Plociniczak cc9fdf
		$arg
Hubert Plociniczak cc9fdf
		END
Hubert Plociniczak cc9fdf
	)
Hubert Plociniczak cc9fdf
	CMDLINE="${CMDLINE} \"${arg}\""
Hubert Plociniczak cc9fdf
done
Hubert Plociniczak cc9fdf
Hubert Plociniczak cc9fdf
cd /var/lib/rabbitmq
Hubert Plociniczak cc9fdf
Hubert Plociniczak cc9fdf
SCRIPT=`basename $0`
Hubert Plociniczak cc9fdf
Hubert Plociniczak cc9fdf
if [ `id -u` = 0 ] ; then
Hubert Plociniczak cc9fdf
    su rabbitmq -s /bin/sh -c "/usr/lib/rabbitmq/bin/${SCRIPT} ${CMDLINE}"
Hubert Plociniczak 1b1224
elif [ `id -u` = `id -u rabbitmq` ] ; then
Hubert Plociniczak 1b1224
    /usr/lib/rabbitmq/bin/${SCRIPT} "$@"
Hubert Plociniczak cc9fdf
else
f44ad9
    /usr/lib/rabbitmq/bin/${SCRIPT}
f44ad9
    echo
f44ad9
    echo "Only root or rabbitmq should run ${SCRIPT}"
f44ad9
    echo
f44ad9
    exit 1
Hubert Plociniczak cc9fdf
fi