#!/usr/bin/perl

$INSTALL_BIN = "/usr/bin/install -g 0 -o 0";
$GZIP_BIN = "/bin/gzip -9";
$LN_BIN = "/bin/ls -sf";
$DIR = "-d";
$BIN = "-m 0755";
$EXE = "-m 0755 -s";
$SCRIPT = "-m 0755";
$MAN = "-m 0644";
$DOC = "-m 0644";
$INFO = "-m 0644";
$FILE = "-m 0644";

unless (open(FILE, "@ARGV[0]")) {
	die("@ARGV[0] cannot be opened!!");
}

sub build_command {
	local($line) = @_;

	$CMD = "$INSTALL_BIN";

	@args = split(/ /, $line);
	$type = splice(@args, 0,1);

	if ($type eq "BIN") {
		$CMD = join(" ", ($CMD, $BIN, @args));
	} elsif ($type eq "EXE") {
		$CMD = join(" ",($CMD, $BIN, @args));
	} elsif ($type eq "SCRIPT") {
		$CMD = join(" ", ($CMD, $SCRIPT, @args));
	} elsif ($type eq "MAN") {
		$CMD = join(" ", ($CMD, $MAN, @args));
	} elsif ($type eq "DOC") {
		$CMD = join(" ", ($CMD, $DOC, @args));
	} elsif ($type eq "INFO") {
		$CMD = join(" ", ($CMD, $DOC, @args));
	} elsif ($type eq "FILE") {
		$CMD = join(" ", ($CMD, $DOC, @args));
	} elsif ($type eq "DIR") {
		$CMD = join(" ", ($CMD, $DIR, @args));
	} elsif ($type eq "GZIP") {
		$CMD = join(" ", ($GZIP_BIN, @args));
	} elsif ($type eq "LN") {
		$CMD = join(" ", ($LN_BIN, @args));
	} elsif ($type eq "CMD") {
		$CMD = join(" ", (@args));
	} else {
		$CMD = "";
	}

	return($CMD);
}


sub main {
	print("Debian/Linux Package Management Installer\n");
	while ($line = <FILE>) {
		chop($line);
		@line = split(/ /, $line);
		$cmd = &build_command($line, @line);
		system("$cmd > /dev/null");
	}
}

&main;
