"Aron Mangano" <[EMAIL PROTECTED]> writes:
> Firstly, what has happended to the mailing list. I used to receive
> emails regulary but I haven't received one now for more than 2
> months. I used to receive them almost daily.
Well, you successfully sent this message to the list :-).
Perhaps mail to you was bouncing and you got unsubscribed? Try using
the Web interface (linked from the home page
http://unattended.sourceforge.net/) to retrieve your subscription
preferences, and resubscribe if necessary.
> Secondly you mentioned once that it is possible to extract the
> correct product key from a spreadsheet when building OEM machines.
> Could you please tell me how to do this. It would be greatly
> appreciated. Many thanks and keep up the great work.
You have to write some Perl. Below is (most of) the Z:\site\config.pl
that I use.
It assumes you have comma-separated-value (CSV) spreadsheets named
"hardware.csv" and "software.csv" under Z:\lib. It assumes both are
indexed by an asset tag field named "Tag". Our asset tags are of the
form "" or "e" (don't ask).
The hardware.csv sheet is only used for setting the host name, which
lives in the "Etc" column of the spreadsheet.
Each software asset has an "Owner" field which is a hardware asset
tag. (Conceptually, each software license is "owned" by a machine.)
It has a "Type" field which is something like "Microsoft Windows 2000
Professionsal". It has a "Key" field which is the license key.
When I say "field", I guess I mean "column".
I really should document this better and turn it into a real
example... If anybody feels like writing this up and submitting a
patch to advanced.html, let me know.
- Pat
use warnings;
use strict;
use Carp;
# Look up an entry in a hash, bombing out if it does not exist.
sub hash_ref ($$) {
my ($hash, $key) = @_;
my $type = ref $hash;
$type eq 'HASH'
or croak "You blew it: What should be a hash is a $type";
(exists $hash->{$key})
or croak "$key not found in hash -- bailing out";
return $hash->{$key};
}
# Asset tag stuff
require 'csv.pl';
# Routine to canonicalize field names for indexing purposes.
sub canonicalize_field ($) {
my ($val) = @_;
# Convert to lower case.
$val = lc $val;
# Local custom: Comments may appear in parens. Strip them.
$val =~ s/\s*\(.*?\)//g;
return $val;
}
# Read hardware inventory list, and index it by tag.
my $hard_inv = 'z:\\site\\hardware.csv';
my $hardware = CSV->read_file ($hard_inv);
my $hard_by_tag = $hardware->index_by ('Tag', \&canonicalize_field);
# Read software inventory list, and index it by owner (hardware tag).
my $soft_inv = 'z:\\site\\software.csv';
my $software = CSV->read_file ($soft_inv);
my $soft_by_owner = $software->index_by ('Owner', \&canonicalize_field);
# Create new [_meta]/asset_tag attribute.
$u->{'_meta'}->{'asset_tag'} =
sub {
my $ret = simple_q ('Enter asset tag (default = none): ');
defined $ret
or print "OK, have it your way.\n";
return defined $ret ? lc $ret : undef;
};
# Compute computer name from inventory sheet, if possible.
sub computer_name {
my $tag = $u->{'_meta'}->{'asset_tag'};
defined $tag
or return undef;
my @systems = @{$hard_by_tag->{$tag}};
scalar @systems == 0
and die "Tag $tag not found in $hard_inv -- bailing";
scalar @systems > 1
and die "Tag $tag found more than once in $hard_inv -- bailing";
my $name = hash_ref ($systems[0], 'Etc');
$name =~ /\S/
or undef $name;
my $text = (defined $name
? "Found hostname for tag $tag: $name\n"
: "No hostname found for tag $tag in $hard_inv\n");
print $text;
return $name;
}
$u->push_value ('UserData', 'ComputerName', \&computer_name);
# Compute product key from inventory sheet, if possible.
sub product_key {
my $tag = $u->{'_meta'}->{'asset_tag'};
defined $tag
or return undef;
my $licenses = $soft_by_owner->{$tag} || [ ];
my $key;
foreach my $license (@$licenses) {
my $desc = hash_ref ($license, 'Type');
$desc =~ /^Microsoft Windows/
or next;
$key = hash_ref ($license, 'Key');
$key =~ /\S/
and last;
undef $key;
}
my $text = (defined $key
? "Found product key for tag $tag: $key\n"
: "No product key found for tag $tag in $soft_inv\n");
print $text;
return $key;
}
$u->push_value ('UserData', 'ProductKey', \&product_key);
$u->push_value ('_meta', 'ntp_servers',
sub {
my $tag = $u->{'_meta'}->{'asset_tag'};
defined $tag
or return undef;
my ($tail) = $tag =~ /(\d)\z/;
defined $tail
or return undef;
return ($tail % 2
? 'ntp-1 ntp-0'
: 'ntp-0 ntp-1');
});
1;
---
SF.Net is sponsored by: Speed St