#!/usr/bin/perl

$user = &GetUserName;

system("clear");
print "Welcome to the installation utility for Menu Interface v2.1!\n";
if($user eq "root") {
&install;
} else {
print "You MUST be root to use this installation utility.\n\n!";
exit;
}

sub install {
system("clear");
print "\n\n";
print "This program will put the files for Menu Interface v2.1 where they\n";
print "are needed. A list of where files were put will be put into /tmp\n";
print "when installatin is complete.\n\n";
print "Is this ok (y/n)? ";
$answer = <STDIN>;
if($answer =~ /^y\b/i) {
print "\n\nCopying...\n";
system("mv .\/menu.pl \/usr\/bin\/");
system("mv .\/menu \/usr\/bin\/");
system("cp .\/shell.db \/etc\/");
system("echo \"\/usr\/bin\/menu\" >> \/etc\/shells");
system("touch \/tmp\/menu.install");
open (LOG, ">>/tmp/menu.install") || die "Could not make LOG!!!";
print LOG "Installed \"menu.pl\" in \/usr\/bin\/\n";
print LOG "Installed \"menu\" in \/usr\/bin\/\n";
print LOG "Installed \"shell.db\" in \/etc\/\n";
print LOG "Added entry to \"\/etc\/shells\" \(\/usr\/bin\/menu\)\n";
close (LOG);
print "Installation Complete.\n";
print "Thank-You for installing Menu Interface v2.1\n\n";
print "-------------------------------------------------------\n";
print "MAKE SURE TO EDIT /etc/shell.db IT IS VERY IMPORTANT!!!\n";
print "-------------------------------------------------------\n\n";
print "To start the menu, simply type 'menu' on the command line.\n\n";
exit;
} elsif($answer =~ /^n\b/i) {
print "Exiting the installation utility.\n";
} else {
print "Invalid Selection!\n";
sleep 1;
&install;
}
}

sub GetUserName {
	($user, $junk) = getpwuid($<);
	return $user;
}
