#!/usr/bin/perl

$II2PKGDIR = $ENV{"II2PKGDIR"};
$II2INSTALLDIR = $ENV{"II2INSTALLDIR"};
$II2RESOURCES = $ENV{"II2RESOURCES"};
$II2DOSERVER = $ENV{"II2DOSERVER"};
$II2BUILDSTAMP = $ENV{"II2BUILDSTAMP"};

if (${II2BUILDSTAMP} < 1160910526) {
    warn "### You need at least i-Installer 2.83 for this package. Bailing out...\n";
    exit 1;
}

$PROGNAME = `"${II2RESOURCES}/basename" "$0"`;
chomp( $PROGNAME);

print "### ${PROGNAME}: Started...\n";

require "${II2PKGDIR}/texpkgs.sharedscript.pm";

checkPrerequisites( "MusixTeX");

if (${II2INSTALLDIR} =~ m|^/usr/local/teTeX|) {
    my $msg = "You are now installing in the location for de deprecated gwTeX 2003-2005 i-Package in part based on teTeX. This is probably not what you want. I suggest you make sure you have the gwTeX i-Package based on TeX Live installed. Then the best thing is to reset this i-Package to its default package properties. It will then pick up the new default location.";
    $doresult = `"${II2RESOURCES}/doalerter" -s "${II2DOSERVER}" -V -t Alert -T "Ar you sure you want to install in this location?" -I \"${msg}\" -1 "Yes" -2 "No"`;
    chomp( $doresult);
    if (($? >> 8) != 0) {
	print "i-Package process aborted at user request\n";
	exit 0;
    }
    `"${II2RESOURCES}/doalerter" -s "${II2DOSERVER}" -V -t Environment -E "TEXIPKGUSEDEPRECATED=YES"`;
}
if (${II2INSTALLDIR} =~ m|^/usr/local/TeXLive|) {
    my $msg = "You are now installing in the old location for gwTeX based on TeX Live. This is probably not what you want. I suggest you make sure your TeX i-Package has migrated to /usr/local/gwTeX, then the best thing is to reset this i-Package to its default package properties. It will then pick up the new default location.";
    $doresult = `"${II2RESOURCES}/doalerter" -s "${II2DOSERVER}" -V -t Alert -T "Ar you sure you want to install in this location?" -I \"${msg}\" -1 "Yes" -2 "No"`;
    chomp( $doresult);
    if (($? >> 8) != 0) {
	print "i-Package process aborted at user request\n";
	exit 0;
    }
    `"${II2RESOURCES}/doalerter" -s "${II2DOSERVER}" -V -t Environment -E "TEXIPKGUSEDEPRECATED=YES"`;
}

print "### ${PROGNAME}: Removing MusixTeX. Please wait...\n";
ipkgsystem( "/bin/rm -rf \"${II2INSTALLDIR}\"/doc/generic/musixtex");
ipkgsystem( "/bin/rm -rf \"${II2INSTALLDIR}\"/doc/latex/musixlyr");
ipkgsystem( "/bin/rm -rf \"${II2INSTALLDIR}\"/dvips/musixtex");
ipkgsystem( "/bin/rm -rf \"${II2INSTALLDIR}\"/fonts/map/dvips/musixtex");
ipkgsystem( "/bin/rm -rf \"${II2INSTALLDIR}\"/fonts/*/public/musixtex");
ipkgsystem( "/bin/rm -rf \"${II2INSTALLDIR}\"/tex/generic/musixtex");
ipkgsystem( "/bin/rm -rf \"${II2INSTALLDIR}\"/tex/generic/musixlyr");
ipkgsystem( "/bin/rm -rf \"${vartexfonts}\"/*/public/musixtex") if -d ${vartexfonts};

ipkgsystem( "(cd \"${II2INSTALLDIR}\"; rmdir -p tex/generic)");
ipkgsystem( "(cd \"${II2INSTALLDIR}\"; rmdir -p doc/generic)");
ipkgsystem( "(cd \"${II2INSTALLDIR}\"; rmdir -p doc/latex)");
ipkgsystem( "(cd \"${II2INSTALLDIR}\"; rmdir -p dvips)");
ipkgsystem( "(cd \"${II2INSTALLDIR}\"; rmdir -p fonts/*/public)");
ipkgsystem( "(cd \"${II2INSTALLDIR}\"; rmdir -p fonts/map/dvips)");

warn "### ${PROGNAME}: Finished.\n";
print "### ${PROGNAME}: Finished.\n";

exit( 0);

# $Id: musixtex.prepare 110 2006-12-28 21:58:00Z gctwnl $
