File: diskless-newhost

package info (click to toggle)
diskless 0.3.17
  • links: PTS
  • area: main
  • in suites: woody
  • size: 728 kB
  • ctags: 119
  • sloc: perl: 2,628; xml: 740; sh: 403; makefile: 104
file content (86 lines) | stat: -rwxr-xr-x 1,602 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/perl -w
use lib "/usr/lib/diskless";
use strict;
use diskless;
use imagedir;
use hostdir;

my $ip="";
my $m=0;

if ($#ARGV >= 0) 
{ 
	if ($ARGV[0] eq "--help")
	{
		print<<EOT;

No help currently available

EOT
		exit 0;
	}
}

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"->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;