[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/se3-unattended/var/se3/unattended/install/site/ -> config.pl (source)

   1  # This module needs to include a conf-<configtype>.pl 
   2  # module that defineds two subroutines.  On called 'setup'
   3  # that calls setups up the interface to that module and
   4  # another called 'lookup_value' that returns a value for
   5  # a given Lookup,Property pair.
   6  #
   7  # Be sure to also look at the conf-csv.pl/conf-mysql.pl
   8  # in the lib directory for setup instructions.
   9  #
  10  # The following table shows what Lookup values are used for a
  11  # given Property value.  The order shown is the order searched.
  12  # The search ends when a valid entry is returned with the 
  13  # exception of UnattendedFile.  UnattendedFile will search and
  14  # apply all files in order listed.  Default is sort of redundant
  15  # for UnattendedFile as z:\site\unattend.txt is considered Default.
  16  #
  17  # Property                 Lookup Order
  18  # =====================    ========================================================
  19  # ComputerName             <macaddr>,Default
  20  # FullName                 <macaddr>,<ComputerName>,Default
  21  # OrgName                  <macaddr>,<ComputerName>,<FullName>,Default
  22  # JoinDomain               <macaddr>,<ComputerName>,<FullName>,<OrgName>,Default
  23  # JoinWorkgroup            <macaddr>,<ComputerName>,<FullName>,<OrgName>,Default
  24  # AdminPassword            <macaddr>,<ComputerName>,<FullName>,<OrgName>,Default
  25  # OS_media                 <macaddr>,<ComputerName>,<FullName>,<OrgName>,Default
  26  # <os_name> ProductKey     <macaddr>,<ComputerName>,<FullName>,<OrgName>,Default
  27  # <os_name> ProductID      <macaddr>,<ComputerName>,<FullName>,<OrgName>,Default
  28  # top_scripts              <macaddr>,<ComputerName>,<FullName>,<OrgName>,Default
  29  # middle_scripts           <macaddr>,<ComputerName>,<FullName>,<OrgName>,Default
  30  # bottom_scripts           <macaddr>,<ComputerName>,<FullName>,<OrgName>,Default
  31  # ntp_servers              <macaddr>,<ComputerName>,<FullName>,<OrgName>,Default
  32  # Partitions               <macaddr>,<ComputerName>,<os_name>,Default
  33  # DriverPath               <macaddr>,<ComputerName>,<os_name>,Default
  34  # UnattendedFile           Default,<os_name>,<OrgName>,<FullName>,<ComputerName>,<macaddr>
  35  
  36  use warnings;
  37  use strict;
  38  
  39  # Set db for mysql interface
  40  #require "conf-mysql.pl";
  41  #CONFIG->setup('DBI:mysql:database=unattended;host=192.168.2.1', 'username', 'password');
  42  
  43  # Set db for PostgreSQL interface
  44  #require "conf-mysql.pl";
  45  #CONFIG->setup('dbi:PgPP:dbname=unattended;host=192.168.2.1', 'username', 'password');
  46  
  47  # Setup db for CSV interface
  48  require "conf-csv.pl";
  49  CONFIG->setup(dos_to_host('z:\\site\\unattend.csv'), '', '');
  50  
  51  # Lookup property value using all possible owners
  52  sub lookup_property ($) {
  53      my ($property) = @_;
  54      defined $property
  55          or return undef;
  56      foreach my $lookup ($u->{'_meta'}->{'macaddr'}, 
  57                          $u->{'UserData'}->{'ComputerName'},
  58                          $u->{'UserData'}->{'FullName'},
  59                          $u->{'UserData'}->{'OrgName'},
  60                          'Default') {
  61          my $value = CONFIG->lookup_value($lookup, $property);
  62          defined $value
  63              and return $value;
  64      }
  65      return undef;
  66  }
  67  
  68  # Lookup fdisk (partitioning) commands from database, if possible.
  69  $u->push_value ('_meta', 'fdisk_cmds',
  70      sub {
  71          my $os_media = $u->{'_meta'}->{'OS_media'};
  72          defined $os_media
  73              or return undef;
  74          my $media_obj = Unattend::WinMedia->new ($os_media);
  75          defined $media_obj
  76              or return undef;
  77          my $os_name = $media_obj->name ();
  78          my $partitions;
  79          foreach my $lookup ($u->{'_meta'}->{'macaddr'}, 
  80                              $u->{'UserData'}->{'ComputerName'},
  81                              "$os_name",
  82                              'Default') {
  83              my $value = CONFIG->lookup_value($lookup, 'Partitions');
  84              defined $value
  85                  and return $value;
  86          }
  87          return undef;
  88      });
  89  
  90  # Lookup computer name from database, if possible.
  91  $u->push_value ('UserData', 'ComputerName', 
  92      sub {
  93          foreach my $lookup ($u->{'_meta'}->{'macaddr'}, 
  94                              'Default') {
  95              my $value = CONFIG->lookup_value($lookup, 'ComputerName');
  96              defined $value
  97                  and return $value;
  98          }
  99          return undef;
 100      });
 101  
 102  # Lookup owner name from database, if possible.
 103  $u->push_value ('UserData', 'FullName', 
 104      sub {
 105          foreach my $lookup ($u->{'_meta'}->{'macaddr'}, 
 106                              $u->{'UserData'}->{'ComputerName'},
 107                              'Default') {
 108              my $value = CONFIG->lookup_value($lookup, 'FullName');
 109              defined $value
 110                  and return $value;
 111          }
 112          return undef;
 113      });
 114  
 115  # Lookup organization name from database, if possible.
 116  $u->push_value ('UserData', 'OrgName', 
 117      sub {
 118          foreach my $lookup ($u->{'_meta'}->{'macaddr'}, 
 119                              $u->{'UserData'}->{'ComputerName'},
 120                              $u->{'UserData'}->{'FullName'},
 121                              'Default') {
 122              my $value = CONFIG->lookup_value($lookup, 'OrgName');
 123              defined $value
 124                  and return $value;
 125          }
 126          return undef;
 127      });
 128  
 129  # Lookup Domain from database, if possible.
 130  $u->push_value ('Identification', 'JoinDomain', sub { return lookup_property('JoinDomain'); });
 131  
 132  # Lookup Workgroup from database, if possible.
 133  $u->push_value ('Identification', 'JoinWorkgroup', sub { return lookup_property('JoinWorkgroup'); });
 134  
 135  # Lookup Admin password from database, if possible.
 136  $u->push_value ('GuiUnattended', 'AdminPassword', sub { return lookup_property('AdminPassword'); });
 137  # Lookup Timezone, if possible.^M
 138  $u->push_value ('GuiUnattended', 'TimeZone', sub { return lookup_property('TimeZone'); });
 139  
 140  
 141  # Lookup OS Directory from database, if possible.
 142  $u->push_value ('_meta', 'OS_media', 
 143      sub { 
 144          my $os_dir = $u->{'_meta'}->{'OS_dir'};
 145          defined $os_dir
 146              or return undef;
 147          my $os_media = lookup_property('OS_media');
 148          defined $os_media
 149              or return undef;
 150          $os_media =~ /^[a-z]:/i
 151              or $os_media = $os_dir . '\\' . $os_media;
 152          opendir OSMEDIA, dos_to_host ($os_media)
 153              or return undef;
 154          closedir OSMEDIA;
 155          return $os_media;
 156      });
 157  
 158  # Lookup product Key from database, if possible.
 159  $u->push_value ('UserData', 'ProductKey', 
 160      sub {
 161          my $media_obj = Unattend::WinMedia->new ($u->{'_meta'}->{'OS_media'});
 162          my $os_name = $media_obj->name ();
 163          defined $os_name
 164              or return undef;
 165          return lookup_property("$os_name ProductKey");
 166      });
 167  
 168  # Lookup product ID from database, if possible.
 169  $u->push_value ('UserData', 'ProductID', 
 170      sub {
 171          my $media_obj = Unattend::WinMedia->new ($u->{'_meta'}->{'OS_media'});
 172          my $os_name = $media_obj->name ();
 173          defined $os_name
 174              or return undef;
 175          return lookup_property("$os_name ProductID");
 176      });
 177  
 178  # Lookup "Top" level scripts from database, if possible.
 179  $u->push_value ('_meta', 'top', sub { lookup_property('top_scripts'); });
 180  
 181  # Lookup "Middle" level scripts from database, if possible.
 182  $u->push_value ('_meta', 'middle', sub { lookup_property('middle_scripts'); });
 183  
 184  # Lookup "Bottom" level scripts from database, if possible.
 185  $u->push_value ('_meta', 'bottom', sub { lookup_property('bottom_scripts'); });
 186  
 187  # Lookup NTP Servers from database, if possible.
 188  $u->push_value ('_meta', 'ntp_servers', sub { lookup_property('ntp_servers'); });
 189  
 190  # Find all relevant drivers for this machine
 191  $u->push_value ('Unattended', 'OemPnPDriversPath', 
 192      sub {
 193          my $os_media = $u->{'_meta'}->{'OS_media'};
 194          defined $os_media
 195              or return undef;
 196          my $media_obj = Unattend::WinMedia->new ($os_media);
 197          defined $media_obj
 198              or return undef;
 199          my $os_name = $media_obj->name ();
 200          my $os_drivers;
 201          foreach my $lookup ($u->{'_meta'}->{'macaddr'}, 
 202                              $u->{'UserData'}->{'ComputerName'},
 203                              "$os_name",
 204                              'Default') {
 205              $os_drivers = CONFIG->lookup_value($lookup, 'DriverPath');
 206              defined $os_drivers
 207                  and last;
 208          }
 209          defined $os_drivers 
 210              or return undef;
 211          $os_drivers =~ /^All$/i
 212              and $os_drivers = $os_media . '\\i386\\$oem$\\$1\\';
 213          $os_drivers =~ /^[a-z]:/i
 214              or $os_drivers = $os_media . '\\i386\\$oem$\\$1\\' . $os_drivers;
 215          opendir OSDRIVERS, dos_to_host ($os_drivers)
 216              or return undef;
 217          closedir OSDRIVERS;
 218          my @pnp_driver_dirs = $media_obj->oem_pnp_dirs (1, $os_drivers);
 219          scalar @pnp_driver_dirs > 0
 220              or return undef;
 221          print "...found some driver directories.\n";
 222          if (! $os_drivers =~ /\\i386\\\$oem\$\\\$1\\/) {
 223              print 'Copying $os_drivers to C:\\ (Still Broken)'; # FIXME
 224          }
 225          my $drivers = join ';', @pnp_driver_dirs;
 226          return $drivers;
 227      });
 228  
 229  # Lookup and read specific Unattended.txt files
 230  my $media_obj = Unattend::WinMedia->new ($u->{'_meta'}->{'OS_media'});
 231  my $os_name = $media_obj->name ();
 232  foreach my $lookup ("$os_name",
 233                      $u->{'UserData'}->{'OrgName'},
 234                      $u->{'UserData'}->{'FullName'},
 235                      $u->{'UserData'}->{'ComputerName'},
 236                      $u->{'_meta'}->{'macaddr'}) {
 237      my $unattended_txt = CONFIG->lookup_value($lookup, 'UnattendedFile');
 238      next unless defined $unattended_txt;
 239      $unattended_txt =~ /^[a-z]:/i
 240          or $unattended_txt = "z:\\site\\" . $unattended_txt;
 241      $unattended_txt = dos_to_host ($unattended_txt);
 242      -e ($unattended_txt)
 243          and $u->read ($unattended_txt);
 244  }
 245  
 246  # Make this file evaluate to "true".
 247  1;


Generated: Tue Mar 17 22:47:18 2015 Cross-referenced by PHPXref 0.7.1