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
|
|
|
|
|
2012-09-21 12:57:19 +02:00
|
|
|
MODE=$1
|
|
|
|
ENVIRONMENT=$2
|
|
|
|
PACKAGE=$3
|
|
|
|
COMMAND=$4
|
|
|
|
TMPFILE=$5
|
2012-09-02 13:18:52 +02:00
|
|
|
|
2012-09-21 12:57:19 +02:00
|
|
|
if [ "$MODE" = "killtree" ]; then
|
|
|
|
KILLPID=$2
|
|
|
|
[ $KILLPID -gt 1 ] && kill_tree $KILLPID
|
|
|
|
exit $?
|
|
|
|
elif [ "$MODE" = "finishprocess" ]; then
|
|
|
|
PROCESSPID=$2
|
|
|
|
PROCESSLOG=$3
|
|
|
|
RETCODE=`tail -n1 $PROCESSLOG | grep "^# WEBBUILD_EXITCODE=" | sed "s|^# WEBBUILD_EXITCODE=||"`
|
|
|
|
[ "$RETCODE" ] || RETCODE=257
|
|
|
|
sed -i "s|\(^$PROCESSPID [^[:space:]]* [^[:space:]]* [^[:space:]]* \)[^[:space:]]*|\1$RETCODE|" $WEBBUILD_STATEDIR/processes
|
|
|
|
exit $RETCODE
|
|
|
|
elif [ "$ENVIRONMENT" = "local" ]; then
|
2012-09-02 13:18:52 +02:00
|
|
|
# echo "Command: $COMMAND"
|
|
|
|
$COMMAND 2>&1 | sed "s|<|\<|g"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2012-09-21 12:57:19 +02:00
|
|
|
if [ "$ENVIRONMENT" = "local" ]; then
|
|
|
|
ENVPREFIX=
|
|
|
|
ENVUSER=root
|
|
|
|
WORKINGHOME=
|
|
|
|
SUCMDPREFIX=
|
|
|
|
elif [ "${AUTOPORT_CHROOT[$ENVIRONMENT]}" ]; then
|
2012-09-02 13:18:52 +02:00
|
|
|
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
|
2012-09-21 12:57:19 +02:00
|
|
|
if [ "$WORKINGHOME" ]; then
|
|
|
|
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
|
2012-09-21 12:57:19 +02:00
|
|
|
$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
|
2012-09-02 13:18:52 +02:00
|
|
|
#`grep ^BuildRoot: ${_tmpfile} | sed "s|BuildRoot:[[:space:]]*||"`
|
|
|
|
# SPECSETUP=`grep %setup ${_tmpfile} | sed "s|.*-n ||"`
|
2012-09-21 12:57:19 +02:00
|
|
|
[ "$BUILDDIR" ] || BUILDDIR=$PACKAGE-$SPECVERSION
|
|
|
|
fi
|
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-21 12:57:19 +02:00
|
|
|
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 "$! $ENVUSER $ENVIRONMENT $cmdtmpfile 256 $COMMAND" >> $WEBBUILD_STATEDIR/processes
|
|
|
|
echo "Started background command: $COMMAND"
|
|
|
|
RET=0
|
|
|
|
else
|
|
|
|
echo "$$ $ENVUSER $ENVIRONMENT $cmdtmpfile 256 $COMMAND" >> $WEBBUILD_STATEDIR/processes
|
|
|
|
rettmpfile=`$SUCMDPREFIX mktemp`
|
|
|
|
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 "/^$$ $ENVUSER/d" $WEBBUILD_STATEDIR/processes
|
|
|
|
if [ "$MODE" != "keeplog" ]; then
|
|
|
|
rm -f $cmdtmpfile
|
|
|
|
else
|
|
|
|
echo "$$ $ENVUSER $ENVIRONMENT $cmdtmpfile $RET $COMMAND" >> $WEBBUILD_STATEDIR/processes
|
|
|
|
fi
|
|
|
|
fi
|
2012-09-02 13:18:52 +02:00
|
|
|
|
2012-09-21 12:57:19 +02:00
|
|
|
if [ "$ENVIRONMENT" != "local" ]; then
|
|
|
|
if [ "$TMPFILE" -a "${AUTOPORT_CHROOT[$ENVIRONMENT]}" ]; then
|
|
|
|
rm -f /var/autoport/${AUTOPORT_CHROOT[$ENVIRONMENT]}/$TMPFILE
|
|
|
|
fi
|
2012-09-02 13:18:52 +02:00
|
|
|
fi
|
|
|
|
exit $RET
|