# yum-lib.pl
# Functions for installing packages with yum

# update_system_input()
# Returns HTML for entering a package to install
sub update_system_input
{
return "$text{'yum_input'} <input name=update size=20> <input type=button onClick='window.ifield = document.forms[2].update; chooser = window.open(\"yum_find.cgi\", \"chooser\", \"toolbar=no,menubar=no,scrollbars=yes,width=600,height=500\")' value=\"$text{'yum_find'}\">";
}

# update_system_install()
# Install some package with yum
sub update_system_install
{
local (@rv, @newpacks);
print "<b>",&text('yum_install', "<tt>yum -y install $in{'update'}</tt>"),"</b><p>\n";
print "<pre>";
&additional_log('exec', undef, "yum -y install $in{'update'}");
open(CMD, "yum -y install $in{'update'} 2>&1 </dev/null |");
while(<CMD>) {
	if (/^\[(update|install|deps):\s+(\S+)\s+/) {
		push(@rv, $2);
		}
	if (!/ETA/ && !/\%\s+done\s+\d+\/\d+\s*$/) {
		print &html_escape($_);
		}
	}
close(CMD);
print "</pre>\n";
if ($?) {
	print "<b>$text{'yum_failed'}</b><p>\n";
	return ( );
	}
else {
	print "<b>$text{'yum_ok'}</b><p>\n";
	return @rv;
	}
}

# update_system_form()
# Shows a form for updating all packages on the system
sub update_system_form
{
print "<h3>$text{'yum_form'}</h3>\n";
print "<form action=yum_upgrade.cgi>\n";
print "<input type=submit value='$text{'yum_apply'}'></form>\n";
}

