2012-09-02 13:18:52 +02:00
|
|
|
#!/bin/bash
|
2012-09-10 17:48:21 +02:00
|
|
|
. /usr/share/autodist/webbuild-functions
|
2012-09-02 13:18:52 +02:00
|
|
|
. /etc/sysconfig/autoport
|
|
|
|
|
|
|
|
ENVIRONMENT=$1
|
|
|
|
PACKAGE=$2
|
|
|
|
COMMAND=$3
|
|
|
|
TMPFILE=$4
|
|
|
|
|
|
|
|
if [ "$ENVIRONMENT" = "local" ]; then
|
|
|
|
# echo "Command: $COMMAND"
|
|
|
|
$COMMAND 2>&1 | sed "s|<|\<|g"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "${AUTOPORT_CHROOT[$ENVIRONMENT]}" ]; then
|
|
|
|
ENVPREFIX="/var/autoport/${AUTOPORT_CHROOT[$ENVIRONMENT]}"
|
2012-09-10 17:48:21 +02:00
|
|
|
ENVUSER=${AUTOPORT_CHROOT_USER[$ENVIRONMENT]}
|
2012-09-02 13:18:52 +02:00
|
|
|
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=
|
2012-09-10 17:48:21 +02:00
|
|
|
ENVUSER=${AUTOPORT_CHROOT_USER[$ENVIRONMENT]}
|
2012-09-02 13:18:52 +02:00
|
|
|
WORKINGHOME=`getent passwd ${AUTOPORT_CHROOT_USER[$ENVIRONMENT]} | cut -d: -f6`
|
|
|
|
SUCMDPREFIX="su -l ${AUTOPORT_CHROOT_USER[$ENVIRONMENT]} -c"
|
|
|
|
else
|
|
|
|
ENVPREFIX=
|
2012-09-10 17:48:21 +02:00
|
|
|
ENVUSER=autodist
|
2012-09-02 13:18:52 +02:00
|
|
|
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
|
2012-09-10 17:48:21 +02:00
|
|
|
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
|
2012-09-06 18:56:32 +02:00
|
|
|
SPECVERSION=`grep -m1 "^Version:" ${SPECFILE} | sed "s|Version:[[:space:]]*||"`
|
2012-09-02 13:18:52 +02:00
|
|
|
BUILDROOT=$PACKAGE-root
|
|
|
|
#`grep ^BuildRoot: ${_tmpfile} | sed "s|BuildRoot:[[:space:]]*||"`
|
|
|
|
# SPECSETUP=`grep %setup ${_tmpfile} | sed "s|.*-n ||"`
|
2012-09-10 17:48:21 +02:00
|
|
|
[ "$BUILDDIR" ] || BUILDDIR=$PACKAGE-$SPECVERSION
|
2012-09-02 13:18:52 +02:00
|
|
|
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"`
|
|
|
|
|
2012-09-10 17:48:21 +02:00
|
|
|
cmdtmpfile=`mktemp`
|
|
|
|
chgrp nobody $cmdtmpfile
|
|
|
|
chmod 640 $cmdtmpfile
|
|
|
|
|
2012-09-02 13:18:52 +02:00
|
|
|
rettmpfile=`$SUCMDPREFIX mktemp`
|
2012-09-10 17:48:21 +02:00
|
|
|
|
|
|
|
echo "$$ $ENVUSER $ENVIRONMENT $cmdtmpfile $COMMAND" >> $WEBBUILD_STATEDIR/processes
|
|
|
|
|
|
|
|
$SUCMDPREFIX ". /etc/profile;cd $WORKINGHOME/RPM/SPECS;$COMMAND;echo \$? > $rettmpfile" 2>&1 | sed "s|<|\<|g" | tr -d '\f' | tee $cmdtmpfile
|
2012-09-02 13:18:52 +02:00
|
|
|
RET=`cat $rettmpfile`
|
|
|
|
$SUCMDPREFIX "rm -f $rettmpfile"
|
|
|
|
|
2012-09-10 17:48:21 +02:00
|
|
|
#echo "Command: $SUCMDPREFIX \"cd $WORKINGHOME/RPM/SPECS;$COMMAND\";RET=$RET" >&2
|
|
|
|
sed -i "/^$$ $ENVUSER/d" $WEBBUILD_STATEDIR/processes
|
|
|
|
rm -f $cmdtmpfile
|
2012-09-02 13:18:52 +02:00
|
|
|
|
|
|
|
if [ "$TMPFILE" -a "${AUTOPORT_CHROOT[$ENVIRONMENT]}" ]; then
|
|
|
|
rm -f /var/autoport/${AUTOPORT_CHROOT[$ENVIRONMENT]}/$TMPFILE
|
|
|
|
fi
|
|
|
|
exit $RET
|