1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
|
#!/usr/bin/perl -w
use lib "/usr/lib/diskless";
use strict;
use diskless;
use imagedir_base;
use hostdir;
my $ip="";
my $m=0;
if ($#ARGV >= 0)
{
if ($ARGV[0] eq "--help")
{
print<<EOT;
No help currently available
EOT
exit 0;
}
}
sub input
{
my($message)=$_[0];
my($defanswer)=$_[1];
my($reply);
printf "%-39s [%-20s]: ",$message,$defanswer;
$reply=<STDIN>; chop($reply); if ($reply eq "") { $reply=$defanswer; }
return $reply;
}
sub yninput
{
my($message)=$_[0];
my($defanswer)=$_[1];
my($reply);
printf "%s? (y/n) [%s]: ",$message,$defanswer;
$reply=<STDIN>; chop($reply); if ($reply eq "") { $reply=$defanswer; }
return $reply;
}
my $imagedir;
if ($m <= $#ARGV)
{
$imagedir=$ARGV[$m]; $m++
}
else
{
$imagedir = "diskless"->input("Directory of group","/var/lib/diskless/default/root");
}
my $error = undef;
my $theimagedir = "imagedir_base"->get($imagedir,\$error);
if (!$theimagedir)
{
die($error->msg."\n");
}
my $ip_on_cmdline = 0;
my @list = ();
while (!$ip_on_cmdline || $m <= $#ARGV)
{
if ($m <= $#ARGV)
{
$ip=$ARGV[$m]; $m++;
$ip_on_cmdline = 1;
}
else
{
$ip = "diskless"->input("IP Address of client","stop");
}
last if ($ip =~ /[a-zA-Z ]/);
my %options = ();
while ($m <= $#ARGV && $ARGV[$m] =~ /^([A-Za-z_0-9]+)=(.*)$/)
{
$options{$1}=$2; $m++;
}
$error = undef;
my $host = undef;
my $thehostdir = "hostdir"->get($theimagedir,$ip,\$error);
if (defined($error) and $error->id == "error"->notfound)
{
$error=undef;
$thehostdir = "hostdir"->create($theimagedir,$ip,\$error);
die($error->msg."\n") if (defined($error));
}
elsif (defined($error))
{
die($error->msg."\n");
}
print "\n-------------------------------------\n";
print "Configure host $ip...\n";
"diskless"->config($thehostdir,\%options);
$thehostdir->save(\$error) or die($error->msg."\n");
print "... host $ip configured.\n";
print "-------------------------------------\n";
@list = (@list,$thehostdir);
}
"hostdir"->update_many(\@list,\$error) or die($error->msg."\n");
exit 0;
|