#! /usr/bin/perl

# version 1.1 2007/01/31

# let's make sure /sbin is in the path as this is the default location
$ENV{'PATH'}="$ENV{'PATH'}:/sbin"; #/sbin is the default location
$ENV{'PERL5LIB'}="";

$emyastdir="" ;

if ( $ENV{'EM_YAST_DIR'} ne "" ) {
	$emyastdir=$ENV{'EM_YAST_DIR'};
	$emyastdir="" unless  -e "$emyastdir/EM-test.ycp";
}

if ( $emyastdir eq "" ) {
	$emyastdir="/usr/share/YaST2/clients/";
	$emyastdir="" unless  -e "$emyastdir/EM-test.ycp";
}

open (WHICH, "/usr/bin/which yast2 2>/dev/null|");
chop($yast2path=<WHICH>);
close WHICH;


$outpp="FAILED";
$patched=0;
if ( ($yast2path ne "")  && ($emyastdir ne "")) {
	
	if (open (PATCH, "$emyastdir/RunYast.sh  $yast2path $emyastdir/EM-test.ycp list 2>&1|") ) {

		chop($outpp=<PATCH>);
		close PATCH;
		$patched=1 if ($outpp eq "OK");
	} else {
		$outpp="open $emyastdir/RunYast.sh  $yast2path $emyastdir/EM-test.ycp list failed";
	}
} 

#print "Yast=\"$yast2path\" YastPatch=\"$patched\" EMScripts=\"$emyastdir"\n";
print "em_result=$yast2path|$patched|$emyastdir\n";