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
|
|
|
|
|
2019-07-15 17:42:52 +02:00
|
|
|
export LANG="C.UTF-8"
|
2012-09-21 12:57:19 +02:00
|
|
|
MODE=$1
|
|
|
|
ENVIRONMENT=$2
|
2012-10-18 00:49:13 +02:00
|
|
|
USER=$3
|
|
|
|
PACKAGE=$4
|
|
|
|
COMMAND=$5
|
|
|
|
TMPFILE=$6
|
2012-09-02 13:18:52 +02:00
|
|
|
|
2013-05-23 13:02:22 +02:00
|
|
|
[ -e $WEBBUILD_STATEDIR/cache/config-dynamic ] && . $WEBBUILD_STATEDIR/cache/config-dynamic
|
|
|
|
|
2012-10-18 00:49:13 +02:00
|
|
|
echo "REQUEST: $@" >> $WEBBUILD_STATEDIR/commands_log
|
2012-09-21 12:57:19 +02:00
|
|
|
if [ "$MODE" = "killtree" ]; then
|
|
|
|
KILLPID=$2
|
2012-10-18 00:49:13 +02:00
|
|
|
[ $KILLPID -gt 1 ] && {
|
|
|
|
echo "COMMAND: kill_tree $KILLPID" >> $WEBBUILD_STATEDIR/commands_log
|
|
|
|
kill_tree $KILLPID
|
|
|
|
}
|
2012-09-21 12:57:19 +02:00
|
|
|
exit $?
|
|
|
|
elif [ "$MODE" = "finishprocess" ]; then
|
|
|
|
PROCESSPID=$2
|
2012-10-18 00:49:13 +02:00
|
|
|
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
|
2012-09-21 12:57:19 +02:00
|
|
|
exit $RETCODE
|
|
|
|
elif [ "$ENVIRONMENT" = "local" ]; then
|
2012-10-18 00:49:13 +02:00
|
|
|
echo "COMMAND: $COMMAND" >> $WEBBUILD_STATEDIR/commands_log
|
2013-11-09 14:31:17 +01:00
|
|
|
$COMMAND 2>&1
|
|
|
|
# | sed "s|<|\<|g"
|
|
|
|
RET=$?
|
|
|
|
exit $RET
|
2012-09-02 13:18:52 +02:00
|
|
|
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]}
|
2013-02-02 14:22:14 +01:00
|
|
|
if [ "${AUTOPORT_CHROOT_USER[$ENVIRONMENT]}" = "autodist" ]; then
|
|
|
|
WORKINGHOME="/var/autodist/"
|
|
|
|
RPMBUILDROOT="/var/tmp/autodist/"
|
|
|
|
else
|
|
|
|
WORKINGHOME="/usr/src/"
|
|
|
|
RPMBUILDROOT="/var/tmp/"
|
|
|
|
fi
|
2012-09-02 13:18:52 +02:00
|
|
|
SUCMDPREFIX="chroot $ENVPREFIX su -l ${AUTOPORT_CHROOT_USER[$ENVIRONMENT]} -c"
|
|
|
|
[ "$TMPFILE" ] && {
|
|
|
|
cp $TMPFILE /var/autoport/${AUTOPORT_CHROOT[$ENVIRONMENT]}/$TMPFILE
|
2013-06-05 14:03:56 +02:00
|
|
|
chmod +r /var/autoport/${AUTOPORT_CHROOT[$ENVIRONMENT]}/$TMPFILE
|
2012-09-02 13:18:52 +02:00
|
|
|
}
|
|
|
|
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`
|
2013-05-23 13:02:22 +02:00
|
|
|
[ -e "$WORKINGHOME/RPM" ] || WORKINGHOME="/usr/src/"
|
2012-09-02 13:18:52 +02:00
|
|
|
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"
|
2012-11-19 23:52:30 +01:00
|
|
|
# [ "$TMPFILE" ] && chown autodist $TMPFILE
|
2012-09-02 13:18:52 +02:00
|
|
|
fi
|
2012-11-19 23:52:30 +01:00
|
|
|
if [ "$MODE" = "specinfo" ]; then
|
2012-09-21 12:57:19 +02:00
|
|
|
eval `$SUCMDPREFIX "autospec --eval=tmppath_dir|grep -v '^#'"`
|
|
|
|
RPMBUILDROOT=$tmppath_dir
|
|
|
|
SPECFILE=${ENVPREFIX}${WORKINGHOME}/RPM/SPECS/$PACKAGE.spec
|
2012-10-18 00:49:13 +02:00
|
|
|
if [ "$PACKAGE" -a -r "$SPECFILE" ]; then
|
2012-09-10 17:48:21 +02:00
|
|
|
rm -f $SPECFILE.tmp
|
2012-11-19 23:52:30 +01:00
|
|
|
while read line; do
|
|
|
|
case "$line" in
|
|
|
|
"## AUTOBUILDREQ-BEGIN"*) AUTOBUILDREQ_BEGIN=1 ;;
|
|
|
|
"## AUTOBUILDREQ-END"*) AUTOBUILDREQ_END=1 ;;
|
|
|
|
"## note: run "*" to get the list of build requirements") AUTOBUILDREQ_UNDONE=1 ;;
|
|
|
|
esac
|
|
|
|
done < ${ENVPREFIX}${WORKINGHOME}/RPM/SPECS/$PACKAGE.spec
|
|
|
|
[ "$AUTOBUILDREQ_BEGIN" -a "$AUTOBUILDREQ_END" -a ! "$AUTOBUILDREQ_UNDONE" ] || \
|
|
|
|
echo "SPECVAR_CHECK_NOAUTOBUILDREQ=1"
|
2019-07-21 11:37:20 +02:00
|
|
|
$SUCMDPREFIX "rpmspec -P ${WORKINGHOME}/RPM/SPECS/$PACKAGE.spec > ${WORKINGHOME}/RPM/SPECS/$PACKAGE.spec.tmp 2>/dev/null"
|
2012-09-21 12:57:19 +02:00
|
|
|
if [ -e $SPECFILE.tmp ]; then
|
2012-11-19 23:52:30 +01:00
|
|
|
echo "SPECVAR_Specfile=\"$SPECFILE\""
|
2012-09-21 12:57:19 +02:00
|
|
|
BUILDDIR=`grep -m1 "^%setup.*-n " $SPECFILE.tmp | sed "s|.*-n \([^[:space:]]*\).*|\1|"`
|
2012-11-19 23:52:30 +01:00
|
|
|
while read line; do
|
|
|
|
set -- $line
|
|
|
|
[ "$1" = "%package" -o "$1" = "%description" ] && break
|
|
|
|
if [[ "$1" =~ ^[a-zA-Z]*[0-9]*:.* ]]; then
|
|
|
|
line="$(echo ${line/$1})"
|
2013-06-01 00:30:05 +02:00
|
|
|
specvarfull="SPECVAR_${1/:*}"
|
|
|
|
specvar="${specvarfull/[0-9]*}"
|
|
|
|
specvaridx="${specvarfull/$specvar}"
|
|
|
|
[ "$specvar" = "$lastspecvar" ] && varidx=$(($varidx + 1)) || varidx=0
|
2013-04-22 12:33:50 +02:00
|
|
|
echo "$specvar[$varidx]=\"${line//\"/}\""
|
2013-06-01 00:30:05 +02:00
|
|
|
[ "$specvaridx" != "" ] && echo "${specvar}_idx[$varidx]=$specvaridx"
|
2012-11-19 23:52:30 +01:00
|
|
|
[ "$specvar" = "SPECVAR_Version" -a ! "$BUILDDIR" ] && BUILDDIR="$PACKAGE-${line}"
|
|
|
|
fi
|
|
|
|
lastspecvar=$specvar
|
|
|
|
done < $SPECFILE.tmp
|
2012-09-21 12:57:19 +02:00
|
|
|
rm -f $SPECFILE.tmp
|
2012-11-19 23:52:30 +01:00
|
|
|
echo "SPECVAR_BUILDDIR=\"$BUILDDIR\""
|
|
|
|
echo "SPECVAR_BUILDROOT=\"$PACKAGE-root\""
|
|
|
|
echo "SPECVAR_RPMBUILDDIR=\"${WORKINGHOME}/RPM/BUILD\""
|
|
|
|
echo "SPECVAR_RPMSOURCESDIR=\"${WORKINGHOME}/RPM/SOURCES\""
|
|
|
|
echo "SPECVAR_RPMBUILDROOT=\"$RPMBUILDROOT\""
|
|
|
|
echo "SPECVAR_WORKINGHOME=\"$WORKINGHOME\""
|
|
|
|
exit 0
|
2012-09-21 12:57:19 +02:00
|
|
|
fi
|
2012-11-19 23:52:30 +01:00
|
|
|
else
|
|
|
|
exit 1
|
2012-09-21 12:57:19 +02:00
|
|
|
fi
|
2012-09-02 13:18:52 +02:00
|
|
|
fi
|
2012-10-18 00:49:13 +02:00
|
|
|
echo "COMMAND: $COMMAND" >> $WEBBUILD_STATEDIR/commands_log
|
2012-09-02 13:18:52 +02:00
|
|
|
|
2013-04-22 12:33:50 +02:00
|
|
|
cmdtmpfile=`mktemp --tmpdir=$WEBBUILD_STATEDIR/tmp --suffix=.webbuildcmd`
|
2012-09-10 17:48:21 +02:00
|
|
|
|
2012-10-18 00:49:13 +02:00
|
|
|
[ "$PACKAGE" ] || PACKAGE=nopackage
|
2012-09-21 12:57:19 +02:00
|
|
|
if [ "$MODE" = "background" ]; then
|
|
|
|
if [ "$WORKINGHOME" ]; then
|
2014-04-25 12:10:30 +02:00
|
|
|
[ "$DEBUG" ] && echo "=> . /etc/profile;cd $WORKINGHOME/RPM/SPECS;stdbuf -oL -eL $SUCMDPREFIX \"$COMMAND\""
|
2014-02-01 14:55:11 +01:00
|
|
|
# WARNING: don't add pipes after $COMMAND or command pid will be wrong
|
2014-04-25 12:10:30 +02:00
|
|
|
$SUCMDPREFIX ". /etc/profile;cd $WORKINGHOME/RPM/SPECS;stdbuf -oL -eL $COMMAND 2>&1;echo \"# WEBBUILD_EXITCODE=\$?\"" 2>&1 > $cmdtmpfile &
|
2014-02-01 14:55:11 +01:00
|
|
|
# | tr -d '\f'
|
2012-11-19 23:52:30 +01:00
|
|
|
#sed "s|<|\<|g" |
|
2012-09-21 12:57:19 +02:00
|
|
|
else
|
2014-04-25 12:10:30 +02:00
|
|
|
[ "$DEBUG" ] && echo "=> $SUCMDPREFIX \"stdbuf -oL -eL $COMMAND\""
|
2014-02-01 14:55:11 +01:00
|
|
|
# WARNING: don't add pipes after $COMMAND or command pid will be wrong
|
2014-04-25 12:10:30 +02:00
|
|
|
$SUCMDPREFIX "stdbuf -oL -eL $COMMAND;echo \"# WEBBUILD_EXITCODE=\$?\"" 2>&1 > $cmdtmpfile &
|
2014-02-01 14:55:11 +01:00
|
|
|
# | sed "s|<|\<|g" | tr -d '\f'
|
2012-09-21 12:57:19 +02:00
|
|
|
fi
|
2012-10-18 00:49:13 +02:00
|
|
|
echo "$! $USER $ENVIRONMENT $PACKAGE $cmdtmpfile 256 $COMMAND" >> $WEBBUILD_STATEDIR/processes
|
2012-09-21 12:57:19 +02:00
|
|
|
echo "Started background command: $COMMAND"
|
2012-11-19 23:52:30 +01:00
|
|
|
echo
|
|
|
|
echo "You may watch command live output and result in the <b>Webbuild jobs</b> box above."
|
2012-09-21 12:57:19 +02:00
|
|
|
RET=0
|
|
|
|
else
|
2012-10-18 00:49:13 +02:00
|
|
|
echo "$$ $USER $ENVIRONMENT $PACKAGE $cmdtmpfile 256 $COMMAND" >> $WEBBUILD_STATEDIR/processes
|
|
|
|
rettmpfile=`$SUCMDPREFIX "mktemp --suffix=.webbuildret"`
|
2012-09-21 12:57:19 +02:00
|
|
|
if [ "$WORKINGHOME" ]; then
|
2014-04-25 12:10:30 +02:00
|
|
|
[ "$DEBUG" ] && echo "=> . /etc/profile;cd $WORKINGHOME/RPM/SPECS;\"$COMMAND\""
|
2013-07-11 11:03:09 +02:00
|
|
|
if [ "$MODE" = "binary" ]; then
|
|
|
|
$SUCMDPREFIX ". /etc/profile;cd $WORKINGHOME/RPM/SPECS;$COMMAND;echo \$? > $rettmpfile" 2>&1
|
|
|
|
else
|
2014-07-08 17:56:49 +02:00
|
|
|
$SUCMDPREFIX ". /etc/profile;cd $WORKINGHOME/RPM/SPECS;$COMMAND;echo \$? > $rettmpfile" 2>&1 | tr -d '\f' | tee $cmdtmpfile | parse_generic_output
|
2013-07-11 11:03:09 +02:00
|
|
|
fi
|
2012-11-19 23:52:30 +01:00
|
|
|
# sed "s|<|\<|g" |
|
2012-09-21 12:57:19 +02:00
|
|
|
else
|
2013-01-19 16:24:26 +01:00
|
|
|
[ "$DEBUG" ] && echo "=> $SUCMDPREFIX \"$COMMAND\""
|
2013-07-11 11:03:09 +02:00
|
|
|
if [ "$MODE" = "binary" ]; then
|
|
|
|
$SUCMDPREFIX "$COMMAND;echo \$? > $rettmpfile" 2>&1
|
|
|
|
else
|
|
|
|
$SUCMDPREFIX "$COMMAND;echo \$? > $rettmpfile" 2>&1 | tr -d '\f' | tee $cmdtmpfile
|
|
|
|
fi
|
2012-11-19 23:52:30 +01:00
|
|
|
# sed "s|<|\<|g" |
|
2012-09-21 12:57:19 +02:00
|
|
|
fi
|
|
|
|
RET=`cat $ENVPREFIX/$rettmpfile`
|
2012-11-19 23:52:30 +01:00
|
|
|
[ "$RET" ] || RET=254
|
2012-09-21 12:57:19 +02:00
|
|
|
$SUCMDPREFIX "rm -f $rettmpfile"
|
2012-10-18 00:49:13 +02:00
|
|
|
sed -i "/^$$ $USER/d" $WEBBUILD_STATEDIR/processes
|
2012-09-21 12:57:19 +02:00
|
|
|
if [ "$MODE" != "keeplog" ]; then
|
|
|
|
rm -f $cmdtmpfile
|
|
|
|
else
|
2012-10-18 00:49:13 +02:00
|
|
|
echo "$$ $USER $ENVIRONMENT $PACKAGE $cmdtmpfile $RET $COMMAND" >> $WEBBUILD_STATEDIR/processes
|
2012-09-21 12:57:19 +02:00
|
|
|
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
|
2012-10-18 00:49:13 +02:00
|
|
|
if [ -e $cmdtmpfile ]; then
|
|
|
|
chmod 666 $cmdtmpfile
|
|
|
|
chown apache.nobody $cmdtmpfile
|
|
|
|
fi
|
2012-11-19 23:52:30 +01:00
|
|
|
|
2012-09-02 13:18:52 +02:00
|
|
|
exit $RET
|