autodist/webbuild/webbuild-sudo

81 lines
2.9 KiB
Bash
Executable File

#!/bin/bash
. /usr/share/autodist/webbuild-functions
. /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]}"
ENVUSER=${AUTOPORT_CHROOT_USER[$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=
ENVUSER=${AUTOPORT_CHROOT_USER[$ENVIRONMENT]}
WORKINGHOME=`getent passwd ${AUTOPORT_CHROOT_USER[$ENVIRONMENT]} | cut -d: -f6`
SUCMDPREFIX="su -l ${AUTOPORT_CHROOT_USER[$ENVIRONMENT]} -c"
else
ENVPREFIX=
ENVUSER=autodist
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
rm -f $SPECFILE.tmp
$SUCMDPREFIX "rpm -q --specfile ${WORKINGHOME}/RPM/SPECS/$PACKAGE.spec --specedit > ${WORKINGHOME}/RPM/SPECS/$PACKAGE.spec.tmp 2>/dev/null"
if [ -e $SPECFILE.tmp ]; then
BUILDDIR=`grep -m1 "^%setup.*-n " $SPECFILE.tmp | sed "s|.*-n \([^[:space:]]*\).*|\1|"`
rm -f $SPECFILE.tmp
fi
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" ] || 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"`
cmdtmpfile=`mktemp`
chgrp nobody $cmdtmpfile
chmod 640 $cmdtmpfile
rettmpfile=`$SUCMDPREFIX mktemp`
echo "$$ $ENVUSER $ENVIRONMENT $cmdtmpfile $COMMAND" >> $WEBBUILD_STATEDIR/processes
$SUCMDPREFIX ". /etc/profile;cd $WORKINGHOME/RPM/SPECS;$COMMAND;echo \$? > $rettmpfile" 2>&1 | sed "s|<|\&lt;|g" | tr -d '\f' | tee $cmdtmpfile
RET=`cat $rettmpfile`
$SUCMDPREFIX "rm -f $rettmpfile"
#echo "Command: $SUCMDPREFIX \"cd $WORKINGHOME/RPM/SPECS;$COMMAND\";RET=$RET" >&2
sed -i "/^$$ $ENVUSER/d" $WEBBUILD_STATEDIR/processes
rm -f $cmdtmpfile
if [ "$TMPFILE" -a "${AUTOPORT_CHROOT[$ENVIRONMENT]}" ]; then
rm -f /var/autoport/${AUTOPORT_CHROOT[$ENVIRONMENT]}/$TMPFILE
fi
exit $RET