Howdy--

Below find the config.pl I'm using for my organization.  It includes
some of the things from sample-config.pl (automatically find drivers,
determine CD Key based on OS name), but also collects some data we need
for all the new computers we build (Budget number, whether or not this
PC needs to be insured) and determines the computer's name (name is
comprised of a short code identifying location, a 7-digit inventory tag
number, and the first 3 letters of the primary user's first name
followed by the first letter of their last name. 

I'm not much of a perl person, so this probably isn't a good example of
perl coding style, but hopefully it can be of some use.

-Matt



config.pl --------------------------

# File to hold site-specific customizations.

# Enable maximum warnings and disallow sloppy constructs.
use warnings;
use strict;

# Remove spaces from around a string
sub trim {
    my ($arg) = @_;

    $arg =~ s/^\s+//;
    $arg =~ s/\s+$//;

    return $arg;
}

#returns true if we're installing a server version of windows
sub is_server {
    my $media_obj = Unattend::WinMedia->new
($u->{'_meta'}->{'OS_media'});
    my $os_name = $media_obj->name ();
    return $os_name =~ /Server/;
}

# Use tag number, user name, and location to build system name
# While we're at it, gather budget and insurance information as well.
$u->{'UserData'}->{'ComputerName'} =
    sub {
        my $is_new;
        my $budget;
        my $needs_insurance;
        my $insurance_budget;
        my $insurance_amount;
        my $is_laptop;
        my $is_loaner;
        my $location;
        my $first_name;
        my $last_name;
        my $initials;
        my $tag;
        my $computer_name;

        # Get budget information
        $is_new = yes_no_choice("Is this a brand-new PC (and not a
rebuild of an old one)?");
        $budget = $is_new ? simple_q("Enter the budget this PC was
purchased on: ") : "";

        # Get insurance info
        $needs_insurance = yes_no_choice("Does this PC need to be
insured?");
        if ($needs_insurance) {
            $insurance_budget = simple_q("Enter the budget to insure
this PC under: ");
            $insurance_amount = simple_q("Enter the amount to insure
this PC for: ");
        } else {
            $insurance_budget = "";
            $insurance_amount = 0;
        }

        # If we're installing a server version, prompt for a name.
Otherwise,
        # build a name
        if (is_server()) {
            $computer_name = trim(simple_q("Enter server name: "));
            $is_laptop = 0;
        }
        else {
            # Get info to build system name
            $is_laptop = yes_no_choice("Is this a laptop?");
        }


        if ($is_laptop) {
            $location = "LT";
        } else {
            print "Where will this computer be located (primarily):";
            $location = menu_choice("UWMC"         =>  "HSB",
                                    "VA"           =>  "VA",
                                    "Harborview"   =>  "HMC",
                                    "Fred Hutch"   =>  "FH",
                                    "Home"         =>  "HOME",
                                    "Madigan"      =>  "MAD");
        }

        $is_loaner = !is_server() && yes_no_choice('Is this a "loaner"
machine?');

        if ($is_loaner) {
            $first_name = "LOAN";
            $last_name = "";
            $initials = "LOAN";
        } else {
            if (is_server()) {
                $first_name = "Gastroenterology";
                $last_name = "Information Systems";
                $initials = "GIIS";
            }
            else {
                $first_name = trim(simple_q("User's first name: "));
                $last_name = trim(simple_q("User's last name: "));
                $initials = substr($first_name, 0, 3);
                if (length($last_name)) {
                    $initials = $initials . substr($last_name, 0, 1);
                } else {
                    $initials = $initials . substr($first_name, 3, 1);
                }
            }
        }


        $tag = simple_q("Machine's tag #: ");
        $tag =~ s/[^\d]//g;


        # Process everything & come up with a machine name
        if (!is_server()) {
            $computer_name = $location .
                             substr($tag, 0, 7) .
                             $initials;
            $computer_name = uc($computer_name);
        }

        # Just for kicks, save everything to the _meta section
        $u->{'_meta'}->{'is_new'} = $is_new;
        $u->{'_meta'}->{'budget'} = $budget;
        $u->{'_meta'}->{'needs_insurance'} = $needs_insurance;
        $u->{'_meta'}->{'insurance_budget'} = $insurance_budget;
        $u->{'_meta'}->{'insurance_amount'} = $insurance_amount;
        $u->{'_meta'}->{'is_laptop'} = $is_laptop;
        $u->{'_meta'}->{'is_loaner'} = $is_loaner;
        $u->{'_meta'}->{'location'} = $location;
        $u->{'_meta'}->{'first_name'} = $first_name;
        $u->{'_meta'}->{'last_name'} = $last_name;
        $u->{'_meta'}->{'initials'} = $initials;
        $u->{'_meta'}->{'tag'} = $tag;

        print "\n\nComputer Name: $computer_name\n";
        simple_q("Press [ENTER] to continue");

        return $computer_name;
    };

# Assign product key based on os type
$u->{'UserData'}->{'ProductKey'} =
    sub {
        my $media_obj = Unattend::WinMedia->new
($u->{'_meta'}->{'OS_media'});
        my $os_name = $media_obj->name ();
        if ($os_name =~ /Windows XP/) {
            return 'XP CD KEY';
        }
        elsif ($os_name =~ /Windows Server 2003/) {
            return 'Windows Server 2003 Key';
        }
        return undef;
    };

$u->{'UserData'}->{'ProductID'} =
    sub {
        my $media_obj = Unattend::WinMedia->new
($u->{'_meta'}->{'OS_media'});
        my $os_name = $media_obj->name ();
        if ($os_name =~ /Windows 2000 Pro/) {
            return 'Windows 200 Pro Key';
        }
        elsif ($os_name =~ /Windows 2000 .* Server/) {
            return 'Windows 2000 Server Key';
        }
        elsif (defined $u->{'UserData'}->{'ProductKey'}) {
            # It is OK for us to return undef as long as there is a
            # ProductKey.
            return undef;
        }
        die "No ProductKey nor ProductID!";
    };

# Include all drivers found under OS dir
$u->push_value ('Unattended', 'OemPnPDriversPath',
    sub {
        my $media_obj = Unattend::WinMedia->new
($u->{'_meta'}->{'OS_media'});
        my @pnp_driver_dirs = $media_obj->oem_pnp_dirs (1);
        # No driver directories means no drivers path
        scalar @pnp_driver_dirs > 0
            or return undef;
        print "...found some driver directories.\n";
        my $drivers = join ';', @pnp_driver_dirs;
        # Setup does not like empty OemPnPDriversPath
        $drivers =~ /\S/
            or undef $drivers;
        return $drivers;
    });

# Make this file evaluate to "true".
1;

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Stefan
Schlesinger
Sent: Tuesday, January 18, 2005 4:28 AM
To: unattended-info@lists.sourceforge.net
Subject: [Unattended] config.pl examples

Hey,

could anyone please send me some more complex samples of the unattended 
config.pl?

regards, sts.



Privileged, confidential or patient identifiable information may be contained 
in this message. This information is meant only for the use of the intended 
recipients. If you are not the intended recipient, or if the message has been 
addressed to you in error, do not read, disclose, reproduce, distribute, 
disseminate or otherwise use this transmission.  Instead, please notify the 
sender by reply e-mail, and then destroy all copies of the message and any 
attachments.


-------------------------------------------------------
The SF.Net email is sponsored by: Beat the post-holiday blues
Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek.
It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt
_______________________________________________
unattended-info mailing list
unattended-info@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/unattended-info

Reply via email to