autodist/webbuild/webbuild-sudo

70 lines
2.3 KiB
Bash
Executable File

#!/bin/bash
. /etc/sysconfig/autoport
ENVIRONMENT=$1
PACKAGE=$2
COMMAND=$3
TMPFILE=$4
if [ "$ENVIRONMENT" = "local" ]; then
# echo "Command: $COMMAND"
$COMMAND 2>&1 | sed "s|<|\&lt;|g"
exit 0
fi
if [ "${AUTOPORT_CHROOT[$ENVIRONMENT]}" ]; then
ENVPREFIX="/var/autoport/${AUTOPORT_CHROOT[$ENVIRONMENT]}"
WORKINGHOME="/usr/src/"
SUCMDPREFIX="chroot $ENVPREFIX su -l ${AUTOPORT_CHROOT_USER[$ENVIRONMENT]} -c"
RPMBUILDROOT="/var/tmp/"
[ "$TMPFILE" ] && {
cp $TMPFILE /var/autoport/${AUTOPORT_CHROOT[$ENVIRONMENT]}/$TMPFILE
chmod 755 /var/autoport/${AUTOPORT_CHROOT[$ENVIRONMENT]}/$TMPFILE
}
elif [ "${AUTOPORT_NATIVE[$ENVIRONMENT]}" ]; then
ENVPREFIX=
WORKINGHOME=`getent passwd ${AUTOPORT_CHROOT_USER[$ENVIRONMENT]} | cut -d: -f6`
SUCMDPREFIX="su -l ${AUTOPORT_CHROOT_USER[$ENVIRONMENT]} -c"
else
ENVPREFIX=
WORKINGHOME="/var/autodist"
SUCMDPREFIX="su -l autodist -c"
RPMBUILDROOT="/var/tmp/autodist"
[ "$TMPFILE" ] && chown autodist $TMPFILE
fi
eval `$SUCMDPREFIX "autospec --eval=tmppath_dir|grep -v '^#'"`
RPMBUILDROOT=$tmppath_dir
SPECFILE=${ENVPREFIX}${WORKINGHOME}/RPM/SPECS/$PACKAGE.spec
if [ -r "$SPECFILE" ]; then
# _tmpfile=`mktemp`
# _errtmpfile=`mktemp`
# rpm -q --specfile $SPECFILE --specedit > ${_tmpfile} 2>${_errtmpfile}
# [ -s ${_errtmpfile} ] && {
# cat ${_errtmpfile}
# rm -f ${_tmpfile} ${_errtmpfile}
# exit 254
# }
SPECVERSION=`grep -m1 "^Version:" ${SPECFILE} | sed "s|Version:[[:space:]]*||"`
BUILDROOT=$PACKAGE-root
#`grep ^BuildRoot: ${_tmpfile} | sed "s|BuildRoot:[[:space:]]*||"`
# SPECSETUP=`grep %setup ${_tmpfile} | sed "s|.*-n ||"`
BUILDDIR=$PACKAGE-$SPECVERSION
fi
RPMBUILDDIR=${WORKINGHOME}/RPM/BUILD
COMMAND=`echo $COMMAND | sed "s|@BUILDDIR@|$BUILDDIR|g"`
COMMAND=`echo $COMMAND | sed "s|@BUILDROOT@|$BUILDROOT|g"`
COMMAND=`echo $COMMAND | sed "s|@RPMBUILDDIR@|$RPMBUILDDIR|g"`
COMMAND=`echo $COMMAND | sed "s|@RPMBUILDROOT@|$RPMBUILDROOT|g"`
rettmpfile=`$SUCMDPREFIX mktemp`
$SUCMDPREFIX ". /etc/profile;cd $WORKINGHOME/RPM/SPECS;$COMMAND;echo \$? > $rettmpfile" 2>&1 | sed "s|<|\&lt;|g"
RET=`cat $rettmpfile`
$SUCMDPREFIX "rm -f $rettmpfile"
echo "Command: $SUCMDPREFIX \"cd $WORKINGHOME/RPM/SPECS;$COMMAND\";RET=$RET" >&2
if [ "$TMPFILE" -a "${AUTOPORT_CHROOT[$ENVIRONMENT]}" ]; then
rm -f /var/autoport/${AUTOPORT_CHROOT[$ENVIRONMENT]}/$TMPFILE
fi
exit $RET