#!/usr/bin/perl -w
#
# This script is used by xdebconfigurator to install a version 3 xserver
# When done, it will restart xdebconfigurator
#
# This is a work-around since xdebconfigurator can't run apt or dpkg itself.
# It doesn't fully work this way either, the package gets installed but not
# configured. But we're gonna do that with xdebconfigurator anyways.

my $xdebconf="/usr/sbin/xdebconfigurator";

# Get what server to install
if ($#ARGV < 0)
	{
		die "Usage: xdeb3server [package-name]";
	}
else
{
	my $pckg = $ARGV[0];
	# warn "Argument is $pckg";
	if( system("apt-get install -y $pckg") )
	{
		warn "Package $pckg installed!\n";
	}
	else
	{
		warn "Couldn't install package $pckg !!!\n";
		# bomb out to avoid possible infinite loop
		die "You should install it with the command: apt-get install $pckg\n";
	}
}

# Rerun xdebconfigurator
system("$xdebconf");
