2014-05-23 21:17:27 +02:00
#
# webbuild functions-private include file
# Copyright (c) 2012-2014 by Silvan Calarco <silvan.calarco@mambasoft.it>
#
2013-05-22 12:09:19 +02:00
repository_list() {
if [ "$WEBBUILD_REPOSITORIES" ]; then
echo "${WEBBUILD_REPOSITORIES[*]}"
else
2014-05-23 21:17:27 +02:00
$SUDO_WRAPPER 0 local "$USER" "" "/usr/sbin/autodist-repository list"
2013-05-22 12:09:19 +02:00
fi
}
2012-11-19 23:52:30 +01:00
function showlog() {
local LOGDIR LOGFILES LOGFILE1 LOGFILE2 LOGFILE3 LOGFILE4
if [ "$LOGTYPE" = "processoutput" -o "$LOGTYPE" = "processtail" ]; then
LOGFILES=$LOGFILE
LOGOUTPUTID=outputbottom
else
LOGOUTPUTID=outputbottom
case $LOGTYPE in
autoupdate) LOGFILE=update; ;;
buildinstall|rebuild) LOGFILE=build ;;
*) LOGFILE=$LOGTYPE ;;
esac
if [ "$LOGSTATUSOK" = "true" ]; then
LOGFILE=$LOGFILE/ok
LOGSTATUSAPPEND=" ok"
else
LOGFILE=$LOGFILE/failed
LOGSTATUSAPPEND=" failed"
fi
LOGFILE1=$LOGFILE/${PACKAGE/\//_}.${AUTOPORT_ARCH[$ENVIRONMENT]}
LOGFILE2=$LOGFILE/${PACKAGE/\//_}__*.${AUTOPORT_ARCH[$ENVIRONMENT]}
LOGFILE3=$LOGFILE/*_${PACKAGE/\//_}__*.${AUTOPORT_ARCH[$ENVIRONMENT]}
LOGFILE4=$LOGFILE/*_${PACKAGE/\//_}.${AUTOPORT_ARCH[$ENVIRONMENT]}
2013-11-09 14:31:17 +01:00
LOGDIR=`environment_logdir $ENVIRONMENT 1`
2012-11-19 23:52:30 +01:00
LOGFILES="$LOGDIR/$LOGFILE1 $LOGDIR/$LOGFILE2 $LOGDIR/$LOGFILE3 $LOGDIR/$LOGFILE4"
2013-05-23 15:44:13 +02:00
# sort by most recent and take first
2013-11-09 14:31:17 +01:00
LOGFILES=`$SUDO_WRAPPER 0 $ENVIRONMENT "$USER" "" "ls -t $LOGFILES 2>/dev/null | head -1"`
2012-11-19 23:52:30 +01:00
fi
echo -n "<output><![CDATA[<hr><b>Console output for $PACKAGE ($LOGTYPE$LOGSTATUSAPPEND):</b>"
2019-07-28 21:57:52 +02:00
echo "<div align=left class=\"outputbox\" id=\"$LOGOUTPUTID\">"
2012-11-19 23:52:30 +01:00
for f in $LOGFILES; do
if [ -r $f ]; then
LOGFILESIZE=`stat -c %s $f`
LOGDATE=`stat -c %y $f`
else
LOGFILESIZE=`$SUDO_WRAPPER 0 $ENVIRONMENT "$USER" "" "stat -c %s $f"`
LOGDATE=`$SUDO_WRAPPER 0 $ENVIRONMENT "$USER" "" "stat -c %y $f"`
[ $? -eq 0 ] || continue
fi
echo -n "<b>`basename $f` ($LOGDATE; $LOGFILESIZE):</b>"
echo -n "<pre>"
if [ "$LOGTYPE" = "processtail" ]; then
echo -n "<!-- SCROLL -->"
2014-11-22 12:35:08 +01:00
tail -n +0 -f $f --pid $PROCESSPID | stdbuf -oL sed "s|<\([/]pre>\)|\<\1|g"
2012-11-19 23:52:30 +01:00
echo -n "<!-- ENDSCROLL -->"
else
2016-07-04 21:39:40 +02:00
if [ $LOGFILESIZE -lt 12097152 ]; then
2012-11-19 23:52:30 +01:00
if [ -r $f ]; then
cat $f | parse_build_output $PACKAGE
else
$SUDO_WRAPPER 0 $ENVIRONMENT "$USER" "" "cat $f" | parse_build_output $PACKAGE
fi
else
if [ -r $f ]; then
2014-09-21 02:34:47 +02:00
head -c 1048576 $f | parse_build_output $PACKAGE
2012-11-19 23:52:30 +01:00
echo "<br><font style=\"background-color:yellow;color:black\"><------ CUT (long file) -------></font>"
2014-09-21 02:34:47 +02:00
tail -c 1048576 $f | parse_build_output $PACKAGE
2012-11-19 23:52:30 +01:00
else
2014-09-21 02:34:47 +02:00
$SUDO_WRAPPER 0 $ENVIRONMENT "$USER" "" "head -c 1048576 $f" | parse_build_output $PACKAGE
2012-11-19 23:52:30 +01:00
echo "<br><font style=\"background-color:yellow;color:black\"><------ CUT (long file) -------></font>"
2014-09-21 02:34:47 +02:00
$SUDO_WRAPPER 0 $ENVIRONMENT "$USER" "" "tail -c 1048576 $f" | parse_build_output $PACKAGE
2012-11-19 23:52:30 +01:00
fi
fi
fi
echo -n "</pre>"
done
echo -n "</div>]]></output>"
}
function showEnvironmentPanel() {
2014-11-22 22:57:12 +01:00
echo -n "Host: <b>`hostname`</b><br>"
2012-11-19 23:52:30 +01:00
echo -n "Environment: <b>"
if [ "${AUTOPORT_CHROOT_USER[$ENVIRONMENT]}" ]; then
echo -n "${AUTOPORT_CHROOT_USER[$ENVIRONMENT]} - "
else
echo -n "autodist - "
fi
if [ "${AUTOPORT_UPDATE[$ENVIRONMENT]}" ]; then
echo -n "update"
elif [ "${AUTOPORT_CHROOT[$ENVIRONMENT]}" ]; then
echo -n "chroot"
elif [ "${AUTOPORT_NATIVE[$ENVIRONMENT]}" ]; then
echo -n "native"
elif [ "${AUTOPORT_CROSS[$ENVIRONMENT]}" ]; then
echo -n "cross"
else
echo -n "unknown type"
fi
echo -n " (${AUTOPORT_ARCH[$ENVIRONMENT]})</b>"
#echo "<br>Base repository: <b>${AUTOPORT_BASE_REPOSITORY[$ENVIRONMENT]}</b>"
2013-01-19 16:24:26 +01:00
# toolchain
echo -n "<br>"
2014-09-21 02:34:47 +02:00
if [ ! -e $WEBBUILD_STATEDIR/cache/environment-$ENVIRONMENT-data -o \
"`find $WEBBUILD_STATEDIR/cache/environment-$ENVIRONMENT-data -mmin +5`" ]; then
local toolchain_output=`LANGUAGE=C $SUDO_WRAPPER 0 $ENVIRONMENT "$USER" "" "gcc --version | head -n1; LANGUAGE=C clang -v | head -n1; LANGUAGE=C ld -v"`
local gcc_ver=`echo $toolchain_output | sed "s|.*(GCC) \([0-9.]*\) .*|\1|"`
local binutils_ver=`echo $toolchain_output | sed "s|.*GNU \(.*\) (GNU Binutils.*)\(.*\)|\1 \2|"`
local clang_ver=`echo $toolchain_output | sed "s|.*clang version \([0-9.]*\) .*|\1|"`
local toolchain_text="gcc $gcc_ver, clang $clang_ver, $binutils_ver"
echo "$toolchain_text" > $WEBBUILD_STATEDIR/cache/environment-$ENVIRONMENT-data
else
local toolchain_text=`cat $WEBBUILD_STATEDIR/cache/environment-$ENVIRONMENT-data`
fi
echo "Toolchain: $toolchain_text"
2013-01-19 16:24:26 +01:00
2012-11-19 23:52:30 +01:00
}
2013-06-03 13:46:04 +02:00
function print_showlogcontrols() {
echo -n "<showlogcontrols><![CDATA["
# autodist logs
echo -n "<hr><b>Show last autodist logs:</b> "
echo -n "<input type=button value=\"prepare\" onclick=ajax_getvalues(\"ENVIRONMENT=$ENVIRONMENT&PACKAGE=$PACKAGEENCODED&"
echo -n "REQUEST=showlog&LOGTYPE=prepare&LOGSTATUSOK=\"+document.all.logstatusOK.checked);>"
echo -n "<input type=button value=\"update\" onclick=ajax_getvalues(\"ENVIRONMENT=$ENVIRONMENT&PACKAGE=$PACKAGEENCODED&"
echo -n "REQUEST=showlog&LOGTYPE=update&LOGSTATUSOK=\"+document.all.logstatusOK.checked);>"
echo -n "<input type=button class=boldbutton value=\"build\" onclick=ajax_getvalues(\"ENVIRONMENT=$ENVIRONMENT&PACKAGE=$PACKAGEENCODED&"
echo -n "REQUEST=showlog&LOGTYPE=build&LOGSTATUSOK=\"+document.all.logstatusOK.checked);>"
echo -n "<input type=button value=\"install\" onclick=ajax_getvalues(\"ENVIRONMENT=$ENVIRONMENT&PACKAGE=$PACKAGEENCODED&"
echo -n "REQUEST=showlog&LOGTYPE=install&LOGSTATUSOK=\"+document.all.logstatusOK.checked);>"
echo -n "<input type=button value=\"send\" onclick=ajax_getvalues(\"ENVIRONMENT=$ENVIRONMENT&PACKAGE=$PACKAGEENCODED&"
echo -n "REQUEST=showlog&LOGTYPE=send&LOGSTATUSOK=\"+document.all.logstatusOK.checked);> with status: "
echo -n "OK <input id=\"logstatusOK\" type=\"radio\" name=\"logstatus\" value=\"OK\"> "
echo -n "FAILED <input type=\"radio\" name=\"logstatus\" value=\"FAILED\" checked=\"checked\">"
2016-05-29 00:23:38 +02:00
# console cmd
echo -n "<hr><b>Command:</b> "
echo -n " ["
if [ "${AUTOPORT_CHROOT_USER[$ENVIRONMENT]}" ]; then
echo -n "${AUTOPORT_CHROOT_USER[$ENVIRONMENT]}@"
else
echo -n "autodist@"
fi
echo -n "`hostname -s` ${SPECVAR_BUILDDIR}]\$ <input type=text id=consolecmd value=\"\" size=\"40\"> "
echo -n "<input type=button id=consolecmdbutton value=\"submit\" onclick="
echo -n "ajax_getvalues(\"ENVIRONMENT=$ENVIRONMENT&REPOSITORY=$REPOSITORY&PACKAGE=$PACKAGEENCODED&"
echo -n "REQUEST=consolecmd&CONSOLECMD=\"+getElementById('consolecmd').value+\"&"
echo -n "RPMFORCE=\"+getElementById('rpmforce').checked+\"&"
echo -n "DEBUG=\"+getElementById('debug').checked+\"&"
echo -n "SPECTEXT=\"+encodeURIComponent(editor.getValue()));>"
2013-06-03 13:46:04 +02:00
# close tag
echo -n "]]></showlogcontrols>"
}
2012-11-19 23:52:30 +01:00
function print_editorcontrols() {
echo -n "<editcontrols><![CDATA["
# specfile save
2016-10-17 12:57:27 +02:00
echo -n "<div style=\"width:100%;overflow:hidden;\"><span style=\"width:100%;display:block\">"
2012-11-19 23:52:30 +01:00
echo -n "<input type=button id=savebutton value=\"save\" onclick="
echo -n "ajax_getvalues(\"ENVIRONMENT=$ENVIRONMENT&REPOSITORY=$REPOSITORY&PACKAGE=$PACKAGEENCODED&"
2013-11-09 14:31:17 +01:00
echo -n "REQUEST=savespec&SENDREPOSITORY=$SENDREPOSITORY&SPECTEXT=\"+encodeURIComponent(editor.getValue()));"
2012-11-19 23:52:30 +01:00
echo -n "this.disabled=true; disabled=disabled class=redbutton>"
# specfile reload
echo -n "<input type=button id=updatespecbutton value=\"reload\" onclick="
echo -n "ajax_getvalues(\"ENVIRONMENT=$ENVIRONMENT&REPOSITORY=$REPOSITORY&PACKAGE=$PACKAGEENCODED&"
echo -n "REQUEST=reloadspec\""
echo -n ",\"`cgi_encodevar "Reload <b>$PACKAGE.spec</b>?<br><br>Warning: current unsaved .spec file changes will be lost."`\");>"
2013-05-04 15:46:24 +02:00
# specfile delete
echo -n "<input type=button id=updatespecbutton value=\"delete\" onclick="
echo -n "ajax_getvalues(\"ENVIRONMENT=$ENVIRONMENT&REPOSITORY=$REPOSITORY&PACKAGE=$PACKAGEENCODED&"
echo -n "REQUEST=deletespec\",\"`cgi_encodevar "Really delete <b>$PACKAGE.spec</b>?"`\")>"
2012-11-19 23:52:30 +01:00
# specfile rename
2014-11-22 19:51:49 +01:00
echo -n "<input type=button id=updatespecbutton value=\"rename:\" onclick="
2012-11-19 23:52:30 +01:00
echo -n "ajax_getvalues(\"ENVIRONMENT=$ENVIRONMENT&REPOSITORY=$REPOSITORY&RENAMESPECFROM=$PACKAGE&"
echo -n "SPECTEXT=\"+encodeURIComponent(editor.getValue())+\"&"
echo -n "REQUEST=renamespec&PACKAGE=\"+encodeURIComponent(getElementById('specnewname').value));>"
2014-11-22 19:51:49 +01:00
echo -n "<input type=text id=specnewname value=\"\" size=6>"
# unpack
echo -n "<input type=button value=\"prepare\" onclick="
echo -n "ajax_getvalues(\"ENVIRONMENT=$ENVIRONMENT&REPOSITORY=$REPOSITORY&PACKAGE=$PACKAGEENCODED&REQUEST=rpmprepare&"
echo -n "RPMBUILDARCH=\"+getSelectedValueById('rpmbuildarch')+\"&"
echo -n "SPECTEXT=\"+encodeURIComponent(editor.getValue()));>"
# build
echo -n "<input type=button value=\"build\" onclick="
echo -n "ajax_getvalues(\"ENVIRONMENT=$ENVIRONMENT&REPOSITORY=$REPOSITORY&PACKAGE=$PACKAGEENCODED&REQUEST=rpmbuild&"
echo -n "RPMBUILDARCH=\"+getSelectedValueById('rpmbuildarch')+\"&"
echo -n "SPECTEXT=\"+encodeURIComponent(editor.getValue())+\"&RPMFORCE=\"+getElementById('rpmforce').checked); class=boldbutton>"
# unpackaged files
echo -n "<input type=button value=\"unpackaged list\" onclick="
echo -n "ajax_getvalues(\"ENVIRONMENT=$ENVIRONMENT&REPOSITORY=$REPOSITORY&PACKAGE=$PACKAGEENCODED&REQUEST=autospeclistcheck&"
echo -n "RPMBUILDARCH=\"+getSelectedValueById('rpmbuildarch')+\"&"
echo -n "SPECTEXT=\"+encodeURIComponent(editor.getValue()));>"
# build requirements
echo -n "<input type=button value=\"build reqs\" onclick="
echo -n "ajax_getvalues(\"ENVIRONMENT=$ENVIRONMENT&REPOSITORY=$REPOSITORY&PACKAGE=$PACKAGEENCODED&REQUEST=autospecbuildreq\");>"
# rpm install
[ ! "$USER_CANINSTALL" ] && DISABLED="disabled=disabled"
echo -n "<input type=button id=rpminstallbutton value=\"install\" onclick="
echo -n "ajax_getvalues(\"ENVIRONMENT=$ENVIRONMENT&REPOSITORY=$REPOSITORY&PACKAGE=$PACKAGEENCODED&REQUEST=rpminstall&"
echo -n "RPMFORCE=\"+getElementById('rpmforce').checked"
echo -n ",\"`cgi_encodevar "Install <b>$PACKAGE</b> in current environment?"`\""
echo -n "); class=redbutton $DISABLED>"
# rpm send
if [ "$SPECVAR_CHECK_NOAUTOBUILDREQ" ]; then
HREFADD="disabled=disabled title=\"WARNING: fix specfile build requirements before you can send the package\""
else
HREFADD=
fi
echo -n "<input type=button id=sendpackagebutton value=\"send\" onclick="
echo -n "ajax_getvalues(\"ENVIRONMENT=$ENVIRONMENT&REPOSITORY=$REPOSITORY&PACKAGE=$PACKAGEENCODED&REQUEST=sendpackage&"
echo -n "SENDRECREATESRPM=\"+getElementById('sendrecreatesrpm').checked+\"&"
echo -n "SPECTEXT=\"+encodeURIComponent(editor.getValue())+\"&"
echo -n "AUTODISTARCH=\"+getSelectedValueById('rpmbuildarch')+\"&"
echo -n "SENDREPOSITORY=\"+getSelectedValueById('sendrepository')"
echo -n ",\"`cgi_encodevar "Send <b>$PACKAGE</b> built packages to <b>"`\"+getSelectedValueById('sendrepository')+"
echo -n "\"`cgi_encodevar "</b>?<br><br><font color=goldenrod>HINT: does summary look short and good?</font><br><b>${SPECVAR_Name[0]} - ${SPECVAR_Summary[0]}.</b>"`\""
echo -n "); class=redbutton $HREFADD>"
# recreate and send SRPM
if [ "$SPECVAR_CHECK_NOAUTOBUILDREQ" ]; then
HREFADD="disabled=disabled title=\"WARNING: fix specfile build requirements before you can send the package\""
else
HREFADD=
fi
echo -n "<input type=button id=sendsourcebutton value=\"send SRPM\" onclick="
echo -n "ajax_getvalues(\"ENVIRONMENT=$ENVIRONMENT&REPOSITORY=$REPOSITORY&PACKAGE=$PACKAGEENCODED&REQUEST=sendsource&"
echo -n "RPMFORCE=\"+getElementById('rpmforce').checked+\"&"
echo -n "SENDRECREATESRPM=\"+getElementById('sendrecreatesrpm').checked+\"&"
2012-11-19 23:52:30 +01:00
echo -n "SPECTEXT=\"+encodeURIComponent(editor.getValue())+\"&"
2014-11-22 19:51:49 +01:00
echo -n "SENDREPOSITORY=\"+getSelectedValueById('sendrepository')"
echo -n ",\"`cgi_encodevar "Send <b>$PACKAGE</b> source package only to <b>"`\"+getSelectedValueById('sendrepository')+"
echo -n "\"`cgi_encodevar "</b>?<br><br>WARNING: use this to refresh the SRPM of a package which already exists with same release in repository"`\""
echo -n "); class=redbutton $HREFADD>"
# recreate SRPM before sending checkbox
echo -n "<label style=\"color:red;padding:0;\"><input type=checkbox id=\"sendrecreatesrpm\" value=\"force\">recreate SRPM</label>"
2012-11-19 23:52:30 +01:00
# specfile update
2016-10-17 12:57:27 +02:00
echo -n "<div style=\"width:100%;overflow:hidden;\"><span style=\"display:flex\">"
2013-05-04 15:46:24 +02:00
echo -n "<input type=button id=updatespecbutton value=\"update\" onclick="
2012-11-19 23:52:30 +01:00
echo -n "ajax_getvalues(\"ENVIRONMENT=$ENVIRONMENT&REPOSITORY=$REPOSITORY&PACKAGE=$PACKAGEENCODED&"
2024-06-07 13:49:45 +02:00
echo -n "REQUEST=updatespec&UPDATESPECVERSION=\"+encodeURIComponent(getElementById('updatespecversion').value)+\"&"
2012-11-19 23:52:30 +01:00
echo -n "RPMFORCE=\"+getElementById('rpmforce').checked+\"&"
2013-01-19 16:24:26 +01:00
echo -n "DEBUG=\"+getElementById('debug').checked+\"&"
2012-11-19 23:52:30 +01:00
echo -n "REBUILDSPECCHANGELOG=\"+encodeURIComponent(getElementById('rebuildspecchangelog').value)+\"&"
echo -n "SPECTEXT=\"+encodeURIComponent(editor.getValue()));>"
2016-10-17 12:57:27 +02:00
echo -n " <label>to new version:</label><input type=text id=updatespecversion value=\"\" size=\"10\">"
echo -n " <label>or to new release with changelog:</label>"
echo -n "<input style=\"flex:1\" type=text id=rebuildspecchangelog value=\"$REBUILDSPECCHANGELOG\">"
echo -n "</div>"
2012-11-19 23:52:30 +01:00
# close tag
echo -n "]]></editcontrols>"
}
2013-07-11 11:03:09 +02:00
function show_docs() {
2013-11-09 14:31:17 +01:00
local f RET ftype
2013-07-11 11:03:09 +02:00
for f in $@; do
echo -n "<a href=#logfile-$f>$f</a><br>"
done
echo -n "<br>"
for f in $@; do
2015-08-22 17:58:14 +02:00
echo -n "<a name=logfile-$f></a><p><b>File $f:</b><pre>"
2013-11-09 14:31:17 +01:00
ftype="`$SUDO_WRAPPER 0 $ENVIRONMENT "$USER" $PACKAGE "cd $SPECVAR_RPMBUILDDIR/$SPECVAR_BUILDDIR && file $f"`"
if [ "${ftype/text}" = "${ftype}" ]; then
echo "<p>Binary file; skipping."
continue
fi
2013-07-11 11:03:09 +02:00
$SUDO_WRAPPER 0 $ENVIRONMENT "$USER" $PACKAGE \
2015-08-22 17:58:14 +02:00
"cd $SPECVAR_RPMBUILDDIR/$SPECVAR_BUILDDIR && head -c 10240 $f | strings | sed \"s|<|\<|g;s|[[:cntrl:]]\[[0-9;]*m||g\"" | parse_generic_output
2013-07-11 11:03:09 +02:00
RET=$?
echo -n "</pre>"
done
return $RET
}
function download_file() {
local RET
local download_environment=$1
local download_files=$2
local f
for f in $download_files; do
echo -e "Content-Type: application/octet-stream"
echo -e "Content-Disposition: attachment; filename=\"${f/*\/}\"\n"
if [ "$download_environment" ]; then
$SUDO_WRAPPER binary $download_environment "$USER" "" "cat $f 2>/dev/null"
else
cat $f 2>/dev/null
fi
done
2015-01-30 11:11:23 +01:00
2013-07-11 11:03:09 +02:00
RET=$?
return $RET
}
function resolve_rpmmanagerdir() {
local RPMMANAGERDIR=$1
local RPMMANAGERARCH=$2
local REPOSITORY=$3
case $RPMMANAGERDIR in
REP_SRPMS) rpmmanagerdir=$local_ftp/$REPOSITORY/SRPMS.base
rpmmanagermask="*.src.rpm"
rpmmanagermode=repository ;;
REP_RPMS) rpmmanagerdir=$local_ftp/$REPOSITORY/RPMS.$RPMMANAGERARCH
rpmmanagermask="*.$RPMMANAGERARCH.rpm"
rpmmanagermode=repository ;;
REP_RPMSNOARCH) rpmmanagerdir=$local_ftp/$REPOSITORY/RPMS.$RPMMANAGERARCH
rpmmanagermask="*.noarch.rpm"
rpmmanagermode=repository ;;
SRPMS) rpmmanagerdir=../SRPMS
rpmmanagermask="*.src.rpm"
rpmmanagermode=environment ;;
RPMSNOARCH) rpmmanagerdir=../RPMS/noarch
rpmmanagermask="*.noarch.rpm"
rpmmanagermode=environment ;;
2016-10-17 12:57:27 +02:00
RPMS_arm) rpmmanagerdir=../RPMS/arm
rpmmanagermask="*.arm.rpm"
rpmmanagermode=environment ;;
RPMS_i586) rpmmanagerdir=../RPMS/i586
rpmmanagermask="*.i586.rpm"
rpmmanagermode=environment ;;
2013-07-11 11:03:09 +02:00
*) rpmmanagerdir=../RPMS/$RPMMANAGERARCH
rpmmanagermask="*.$RPMMANAGERARCH.rpm"
rpmmanagermode=environment ;;
esac
}