#!/bin/bash . /usr/share/autodist/webbuild-functions . /etc/sysconfig/autoport MODE=$1 ENVIRONMENT=$2 USER=$3 PACKAGE=$4 COMMAND=$5 TMPFILE=$6 echo "REQUEST: $@" >> $WEBBUILD_STATEDIR/commands_log if [ "$MODE" = "killtree" ]; then KILLPID=$2 [ $KILLPID -gt 1 ] && { echo "COMMAND: kill_tree $KILLPID" >> $WEBBUILD_STATEDIR/commands_log kill_tree $KILLPID } exit $? elif [ "$MODE" = "finishprocess" ]; then PROCESSPID=$2 PROCESSLOG=$4 if [ -e $PROCESSLOG ]; then RETCODE=`tail -n1 $PROCESSLOG | grep "^# WEBBUILD_EXITCODE=" | sed "s|^# WEBBUILD_EXITCODE=||"` [ "$RETCODE" ] || RETCODE=257 else RETCODE=0 fi sed -i "s|\(^$PROCESSPID [^[:space:]]* [^[:space:]]* [^[:space:]]* [^[:space:]]* \)[^[:space:]]*|\1$RETCODE|" $WEBBUILD_STATEDIR/processes exit $RETCODE elif [ "$ENVIRONMENT" = "local" ]; then echo "COMMAND: $COMMAND" >> $WEBBUILD_STATEDIR/commands_log $COMMAND 2>&1 | sed "s|<|\<|g" exit 0 fi if [ "$ENVIRONMENT" = "local" ]; then ENVPREFIX= ENVUSER=root WORKINGHOME= SUCMDPREFIX= elif [ "${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 if [ "$WORKINGHOME" ]; then eval `$SUCMDPREFIX "autospec --eval=tmppath_dir|grep -v '^#'"` RPMBUILDROOT=$tmppath_dir SPECFILE=${ENVPREFIX}${WORKINGHOME}/RPM/SPECS/$PACKAGE.spec if [ "$PACKAGE" -a -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 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"` COMMAND=`echo $COMMAND | sed "s|@WORKINGHOME@|$WORKINGHOME|g"` echo "COMMAND: $COMMAND" >> $WEBBUILD_STATEDIR/commands_log cmdtmpfile=`mktemp --suffix=.webbuildcmd` [ "$PACKAGE" ] || PACKAGE=nopackage if [ "$MODE" = "background" ]; then if [ "$WORKINGHOME" ]; then $SUCMDPREFIX ". /etc/profile;cd $WORKINGHOME/RPM/SPECS;$COMMAND;echo \"# WEBBUILD_EXITCODE=\$?\"" 2>&1 | sed "s|<|\<|g" | tr -d '\f' > $cmdtmpfile & else $SUCMDPREFIX "$COMMAND;echo \"# WEBBUILD_EXITCODE=\$?\"" 2>&1 | sed "s|<|\<|g" | tr -d '\f' > $cmdtmpfile & fi echo "$! $USER $ENVIRONMENT $PACKAGE $cmdtmpfile 256 $COMMAND" >> $WEBBUILD_STATEDIR/processes echo "Started background command: $COMMAND" RET=0 else echo "$$ $USER $ENVIRONMENT $PACKAGE $cmdtmpfile 256 $COMMAND" >> $WEBBUILD_STATEDIR/processes rettmpfile=`$SUCMDPREFIX "mktemp --suffix=.webbuildret"` if [ "$WORKINGHOME" ]; then $SUCMDPREFIX ". /etc/profile;cd $WORKINGHOME/RPM/SPECS;$COMMAND;echo \$? > $rettmpfile" 2>&1 | sed "s|<|\<|g" | tr -d '\f' | tee $cmdtmpfile else $SUCMDPREFIX "$COMMAND;echo \$? > $rettmpfile" 2>&1 | sed "s|<|\<|g" | tr -d '\f' | tee $cmdtmpfile fi RET=`cat $ENVPREFIX/$rettmpfile` [ "$RET" ] || RET=255 $SUCMDPREFIX "rm -f $rettmpfile" sed -i "/^$$ $USER/d" $WEBBUILD_STATEDIR/processes if [ "$MODE" != "keeplog" ]; then rm -f $cmdtmpfile else echo "$$ $USER $ENVIRONMENT $PACKAGE $cmdtmpfile $RET $COMMAND" >> $WEBBUILD_STATEDIR/processes fi fi if [ "$ENVIRONMENT" != "local" ]; then if [ "$TMPFILE" -a "${AUTOPORT_CHROOT[$ENVIRONMENT]}" ]; then rm -f /var/autoport/${AUTOPORT_CHROOT[$ENVIRONMENT]}/$TMPFILE fi fi if [ -e $cmdtmpfile ]; then chmod 666 $cmdtmpfile chown apache.nobody $cmdtmpfile fi exit $RET