Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

792 lines
25 KiB

  1. ##
  2. ## BLCOMMON.PL
  3. ## Sub-routines that are used by many different scripts
  4. ## Created by: Robert E. Blue (a-robebl) 01/29/99
  5. ##
  6. use Cwd;
  7. ### Common scalars
  8. $blcomputername = $ENV{'computername'};
  9. $udpserv = "KEEBLER";
  10. $bom_path = "C:\\nt\\private\\windows\\setup\\bom" unless $bom_path = $ENV{'_BOM_PATH'};
  11. $call_from = uc $0;
  12. $lang = "USA" unless $lang = $ENV{'language'};
  13. $log = "$call_from.log";
  14. $home_dir = cwd();
  15. $bsfile = "$home_dir\\bldswtch.dat"; ### Build Switch Data File.
  16. $crcfile = "\\\\keebler\\burnlab\$\\crc.dat"; ### CRC Data File.
  17. $die_on_error = 0;
  18. $script_start = time;
  19. my $argtxt = "@ARGV";
  20. ### Set cmd window title
  21. unless ( $argtxt =~ /(\/\?|joecomp|bosdump)/s or $call_from =~ /FIVEO.BAT|LOGCHECK.BAT|.PL/i or !$argtxt) {
  22. ### Set system title to an appropriate default
  23. system "title $call_from: $argtxt";
  24. sendudp( $udpserv, "$script_start START: $call_from $argtxt" );
  25. }
  26. ### put here anything all scripts should do when they are complete.
  27. sub end_of_script {
  28. $argtxt .= " $lang" if $call_from =~ /FIVEO.BAT/i;
  29. if ( $_[0] ) {
  30. sendudp( $udpserv, "$script_start COMPLETE: $call_from $argtxt \"$_[0]\"" );
  31. } else {
  32. sendudp( $udpserv, "$script_start COMPLETE: $call_from $argtxt" );
  33. }
  34. exit;
  35. }
  36. sub status_update {
  37. my $extra_info = "$lang $build";
  38. sendudp ( $udpserv, "$script_start STATUS: $call_from $argtxt $extra_info \"$_[0]\"" );
  39. }
  40. #=================================================
  41. # Routines for verifying command line parameters.
  42. #=================================================
  43. ### Check if supported language
  44. $sup_lang{'USA'} = 1;
  45. $sup_lang{'GER'} = 1;
  46. $sup_lang{'JPN'} = 1;
  47. $sup_lang{'KOR'} = 1;
  48. $sup_lang{'CHS'} = 1;
  49. $sup_lang{'CHT'} = 1;
  50. $sup_lang{'CHH'} = 1;
  51. $sup_lang{'ARA'} = 1;
  52. $sup_lang{'HEB'} = 1;
  53. ### Convert 3 letter lang abbrev to ISO 2 letter lang abbrev
  54. $iso_lang{'USA'} = "EN";
  55. $iso_lang{'GER'} = "DE";
  56. $iso_lang{'JPN'} = "JA";
  57. $iso_lang{'KOR'} = "KO";
  58. $iso_lang{'CHS'} = "CN";
  59. $iso_lang{'CHT'} = "TW";
  60. $iso_lang{'CHH'} = "ZH"; ### Just guessing here.
  61. $iso_lang{'ARA'} = "AR";
  62. $iso_lang{'HEB'} = "HE";
  63. $iso_lang{'CHP'} = "AG";
  64. $iso_lang{'THA'} = "TH";
  65. $iso_lang{'EN'} = "USA";
  66. $iso_lang{'DE'} = "GER";
  67. $iso_lang{'JA'} = "JPN";
  68. $iso_lang{'KO'} = "KOR";
  69. $iso_lang{'CN'} = "CHS";
  70. $iso_lang{'TW'} = "CHT";
  71. $iso_lang{'ZH'} = "CHH"; ### Just guessing here.
  72. $iso_lang{'AR'} = "ARA";
  73. $iso_lang{'HE'} = "HEB";
  74. $iso_lang{'AG'} = "CHP";
  75. $iso_lang{'TH'} = "THA";
  76. ### Translate platform name to name used on ntbuilds.
  77. $bld_plat{'X86'} = 'x86';
  78. $bld_plat{'ALPHA'} = 'alpha';
  79. $bld_plat{'NEC98'} = 'nec_98';
  80. ### Check if supported product
  81. $sup_prod{'PRO'} = 1;
  82. $sup_prod{'SRV'} = 1;
  83. $sup_prod{'AS'} = 1;
  84. $sup_prod{'DTC'} = 1;
  85. $sup_prod{'CHK.PRO'} = 1;
  86. $sup_prod{'CHK.SRV'} = 1;
  87. $sup_prod{'CHK.AS'} = 1;
  88. $sup_prod{'CHK.DTC'} = 1;
  89. $sup_prod{'CD2'} = 1;
  90. ### Check if valid build number
  91. sub is_build {
  92. if ( $_[1] =~ /FE/i ) {
  93. return 1 if $_[0] =~ /^([0-9.]{4,}L?[A-Z.]*)$/i;
  94. } else {
  95. return 1 if $_[0] =~ /^([0-9.]{4,}L?[A-Z.]*)$/i;
  96. }
  97. }
  98. ### Check if valid date
  99. sub is_date { return 1 if $_[0] =~ /^(\d+\W+\d+\W+\d+)$/i; }
  100. ### Check if valid burnlab machine
  101. sub is_burner {
  102. if ( $_[0] =~ /^NTBURNLAB([3-7])$/i ) { return "\\\\ntburnlab$1\\D\$"; }
  103. else { return 0; }
  104. }
  105. #==========================
  106. # Net send Burnlab people.
  107. #==========================
  108. if ( $lang =~ /USA|GER/i ) {
  109. ### All Burnlab people who receive USA/misc net sends
  110. @blpeople = (
  111. "keebler", ### a-robebl
  112. "antibob", ### a-piperp
  113. "executor", ### a-randgo
  114. "dwaine", ### a-dwainf
  115. $blcomputername, ### computer script is run on
  116. );
  117. } else {
  118. ### People who care about FE net sends
  119. @blpeople = (
  120. "keebler", ### a-robebl
  121. "antibob", ### a-piperp
  122. $blcomputername, ### computer script is run on
  123. );
  124. }
  125. sub blnotify {
  126. print $_[0];
  127. foreach $blperson ( @blpeople ) {
  128. `net send /DOMAIN:$blperson \"$_[0]\"` if $blperson;
  129. }
  130. &sendudp( $udpserv, $_[0] );
  131. }
  132. ### Define TRUTH
  133. $TRUE = 1;
  134. #=================================================================================
  135. # List of the fallen. (Those who have left the burnlab for one reason or another)
  136. #=================================================================================
  137. #
  138. # Travis Sarbin
  139. # Howard Kwong
  140. # David Lembke
  141. # John Klingbiel
  142. # John Mullins
  143. #
  144. #
  145. #=======================================
  146. # Total the time since start of script.
  147. #=======================================
  148. sub tottime {
  149. my $stoptime = time;
  150. my $totaltime = (($stoptime - $_[0])/60)/60;
  151. $totaltime = sprintf ( "%3.2f", $totaltime );
  152. return $totaltime;
  153. }
  154. #==================================
  155. # Execute a batch of DOS commands.
  156. #==================================
  157. sub execute {
  158. my $endbuild = $_[1];
  159. my $build = $_[2];
  160. my $exitcode = 0;
  161. ###
  162. ### If $build (current build) is newer than $endbuild (build the change took affect),
  163. ### then execute the first set of commands else execute the second set.
  164. ###
  165. ### This was created so we can make changes for US that will not show up in FE builds
  166. ### for a couple of weeks.
  167. ###
  168. ### Separate each line and dump them into an array...
  169. ###
  170. if ( $endbuild and $endbuild >= $build) {
  171. ### Second set of commands.
  172. if ( $_[0] =~ /\n/ ) {
  173. @execstr = split ( /^/, $_[3] );
  174. } else {
  175. $execstr[0] = @_;
  176. }
  177. } else {
  178. ### First set of commonds.
  179. if ( $_[0] =~ /\n/ ) {
  180. @execstr = split ( /^/, $_[0] );
  181. } else {
  182. @execstr = @_;
  183. }
  184. }
  185. ### Traverse the array and execute each line...
  186. foreach $execline ( @execstr ) {
  187. $execline =~ s/^\s*(.*)\n*/$1/; ### Strip any preceeding whitespace...
  188. print "$execline\n"; ### Print what we are about to execute.
  189. $exitcode = system "$execline" unless $debug; ### Run it now!!
  190. $exitcode = $exitcode/256 unless $debug; ### Error codes need to be divided by 256 to get their true value.
  191. ### If the command bombs, send everyone a message.
  192. if ( $exitcode ) {
  193. $execline =~ /(\S+).*/i; ### Get offending command from exec string and dump in $execfail.
  194. $execfail = uc $1;
  195. unless ( $execfail =~ /IF/i ) {
  196. if ( $call_from =~ /fiveo/i ) {
  197. ### If called from fiveo.bat.
  198. &blnotify( "$call_from - $lang: ERROR executing '$execfail' in $fre $wsection! \($exitcode\)" );
  199. } else {
  200. ### If called from any other program.
  201. &blnotify( "$call_from - $lang: ERROR executing '$execfail'! \($exitcode\)" );
  202. }
  203. &sendudp( "$udpserv", "$call_from - $lang: ERROR executing '$execfail' in line: $execline" );
  204. ### Log the error.
  205. system "ECHO $call_from - $lang: ERROR executing $execfail in line: $execline >> $log" if $log;
  206. ### If we have die_on_error set, die on any error.
  207. die "Script exiting due to previous error.\n" if $burnscript{'die_on_error'};
  208. }
  209. }
  210. }
  211. }
  212. #===================================
  213. # Send UDP messages to Big Brother.
  214. #===================================
  215. sub sendudp {
  216. use IO::Socket;
  217. use Fcntl qw(F_GETFL F_SETFL O_NONBLOCK);
  218. $MAXLEN = 1024;
  219. $port = 2222;
  220. $server_host = shift;
  221. $msg = "@_";
  222. $sock = new IO::Socket::INET (
  223. Proto => 'udp',
  224. PeerPort => $port,
  225. PeerAddr => $server_host
  226. );
  227. $sock->send($msg);
  228. }
  229. #=================================================
  230. # Keep track of which drive a build is copied to.
  231. #=================================================
  232. sub bs_drive {
  233. if ( -e $bsfile ) {
  234. open BLDSWITCH, "$bsfile" or die "ERROR: Could not open $bsfile: $!";
  235. } else {
  236. open BLDSWITCH, ">$bsfile" or die "ERROR: Could not open $bsfile: $!";
  237. }
  238. while (<BLDSWITCH>) {
  239. chomp;
  240. ( my $build, my $drive, my $daily, my $date ) = split /\|/;
  241. $bsH{$build}{drive} = $drive;
  242. $bsH{$build}{daily} = $daily;
  243. $bsH{$build}{date} = $date;
  244. }
  245. close BLDSWITCH;
  246. if ( $_[1] ) {
  247. my $build = $_[0];
  248. my $drive = $_[1];
  249. my $daily = $_[2];
  250. chomp ( my $dateday = `date /t` );
  251. chomp ( my $datetime = `time /t` );
  252. my $date = "$dateday$datetime";
  253. $bsH{$build}{drive} = $drive;
  254. $bsH{$build}{daily} = $daily;
  255. $bsH{$build}{date} = $date;
  256. open BLDSWITCH, "> $bsfile";
  257. foreach $bskey ( sort keys %bsH ) {
  258. print BLDSWITCH "$bskey|$bsH{$bskey}{drive}|$bsH{$bskey}{daily}|$bsH{$bskey}{date}\n" ;
  259. }
  260. close BLDSWITCH;
  261. } else {
  262. $_[0] =~ /([0-9.]{4,})/;
  263. my $build = $1;
  264. $build =~ s/^(.*)\.$/$1/;
  265. if ( $bsH{$build}{drive} ) {
  266. return $bsH{$build}{daily}, $bsH{$build}{drive};
  267. } else {
  268. $build =~ s/^([0-9]{4}).*/$1/;
  269. if ( $bsH{$build}{drive} ) {
  270. return $bsH{$build}{daily}, $bsH{$build}{drive};
  271. } else {
  272. print "\n\n\nWARNING: Could not match build number to drive letter.\n\n";
  273. print " This may be cause by bldswtch.dat being empty or\n";
  274. print " you mis-typed the build number in the calling program.\n";
  275. print " Maybe Rob was just smoking crack when he made this.\n\n";
  276. print " Defaulting to D:\n\n";
  277. print "\&BS_DRIVE() was called with invalid build number $build.\n\n";
  278. &blnotify( "WARNING: &BS_DRIVE() called with invalid build number ($build)." );
  279. return "DAILY", "D:";
  280. }
  281. }
  282. }
  283. }
  284. #============================================
  285. # Initialize the common directory structure.
  286. #============================================
  287. sub init_dir_struct {
  288. my $drive = "D:" unless my $drive = $_[0];
  289. print "Creating common $lang directory structure...\n";
  290. mkdir "$drive\\$lang", 1 unless -e "$drive\\$lang";
  291. mkdir "D:\\bldimgs", 1 unless -e "D:\\bldimgs";
  292. mkdir "D:\\bldimgs\\$lang", 1 unless -e "D:\\bldimgs\\$lang";
  293. mkdir "D:\\bldimgs\\$lang\\SKU", 1 unless -e "D:\\bldimgs\\$lang\\SKU";
  294. mkdir "D:\\bldimgs\\$lang\\OTHER", 1 unless -e "D:\\bldimgs\\$lang\\OTHER";
  295. mkdir "D:\\bldimgs\\$lang\\SVCPACK", 1 unless -e "D:\\bldimgs\\$lang\\SVCPACK";
  296. if ( $lang =~ /USA/i ) { mkdir "D:\\bldimgs\\$lang\\IDx", 1 unless -e "D:\\bldimgs\\$lang\\IDx" };
  297. }
  298. #================================
  299. # Check script's log for errors.
  300. #================================
  301. sub check_log {
  302. my $check_log = $_[0];
  303. print "\nChecking $log for ERRORS...\n\n";
  304. open CHECK_LOG, "$check_log";
  305. @log_txt = <CHECK_LOG>;
  306. close CHECK_LOG;
  307. foreach $log_line ( @log_txt ) {
  308. if ( $log_line =~ /(ERROR|WARNING)( |:)/i ) {
  309. $error_txt .= " $log_line";
  310. }
  311. }
  312. open WRITE_LOG, ">$check_log";
  313. print WRITE_LOG "Logfile for $call_from \"$check_log\"\n\n";
  314. if ( $error_txt ) {
  315. print "ERRORS Encountered!\n\n";
  316. print WRITE_LOG "-===== ERRORS Encountered =====-\n\n";
  317. print WRITE_LOG $error_txt;
  318. } else {
  319. print "No ERRORS Encountered!\n\n";
  320. print WRITE_LOG "-===== No ERRORS Encountered! =====-\n\n";
  321. print WRITE_LOG " Burn, baby, burn!!!!\n";
  322. }
  323. print WRITE_LOG "\n\n\n-===== Complete Log =====-\n\n";
  324. foreach $log_line ( @log_txt ) { print WRITE_LOG " $log_line"; }
  325. close WRITE_LOG;
  326. system "start notepad $check_log";
  327. return 1 unless $error_txt;
  328. }
  329. #=========================================
  330. # Copy an image and check CRC's
  331. #=========================================
  332. sub copy_image {
  333. my $img_source = shift @_;
  334. my @img_dest = @_;
  335. my $img_name = $img_source;
  336. $img_name =~ s/.*\\([A-Z.-_]*)$/$1/i;
  337. my $copy_try = 0;
  338. foreach $dest ( @img_dest ) {
  339. ### Create destination directory if it does not yet exist.
  340. execute "if not exist $dest md $dest";
  341. ### Keep trying to copy the images until the CRC's match, fail if they
  342. ### don't after 2 tries.
  343. until ( $copy_success or $copy_try >= 2 ) {
  344. $copy_try++;
  345. print "\ncopy_image: Copying $img_source to $dest\n";
  346. status_update( "Copying $img_source to $dest" );
  347. execute "xcopy /fy $img_source $dest";
  348. ### Get the CRC of the destination file and the one in the CRC
  349. ### database.
  350. my $dest_crc = get_crc( "$dest\\$img_name" );
  351. my ( $mstr_crc ) = crc_info( lc $img_name );
  352. ### Verify the CRC of the destination and the master database match.
  353. if ( $dest_crc =~ /$mstr_crc/i ) {
  354. print "\ncopy_image: CRC's for source and destination match. Image copied successfully.\n";
  355. $copy_success;
  356. } else {
  357. execute "del /q $dest\\$img_name";
  358. blnotify "copy_image: ERROR: CRC for $dest\\$img_name [$dest_crc] does not match [$mstr_crc]\n";
  359. }
  360. }
  361. }
  362. }
  363. sub get_crc {
  364. my $image = $_[0];
  365. print "\nget_crc: CRCing $image\n";
  366. my $crc = `crc $image`;
  367. $crc =~ s/.*AutoCRC signature for file \S+ is (0x\S+).*/$1/si;
  368. if ( $crc =~ /0x(\S{8})/i ) {
  369. print "get_crc: CRC for $image is $crc\n";
  370. return $crc;
  371. } else {
  372. print "ERROR: Could not get CRC for $image\n" unless $crc =~ /0x(\S{8})/i;
  373. }
  374. }
  375. #==============================================
  376. # Build an image, trap any errors encountered.
  377. #==============================================
  378. sub build_image {
  379. ( my $vol_lbl, my $timestamp, my $img_source, my $img_dest, my $bootable ) = @_;
  380. my $errors = 0;
  381. if ( $log ) {
  382. open BI_LOG, "$log";
  383. while (<BI_LOG>) {
  384. if ( /(WARNING|ERROR)( |:)/i ) {
  385. $errors++;
  386. }
  387. }
  388. close BI_LOG;
  389. }
  390. if ( $errors and !$ignore_err ) {
  391. blnotify "Due to ERRORS found in $log, image will not be built";
  392. return;
  393. }
  394. $img_name = $1 if $img_dest =~ /\\(\w+\.img)$/i;
  395. if ( $bootable =~ /boot/i ) {
  396. if ( $makesku ) {
  397. $boot_txt = "-b$drive\\$lang\\etfsboot.com"
  398. } else {
  399. $boot_txt = "-bc:\\newiso\\etfsboot.com"
  400. }
  401. }
  402. print "\n\nBuilding $img_name from $img_source with volume label $vol_lbl and timestamp $timestamp...\n\n";
  403. status_update ( "Building $img_name from $img_source; vol $vol_lbl; timestamp $timestamp;" );
  404. print "c:\\newiso\\cdimg227 $boot_txt -x -ofix -l$vol_lbl -t$timestamp -nt $img_source $img_dest";
  405. $imgtxt = `c:\\newiso\\cdimg227 $boot_txt -x -ofix -l$vol_lbl -t$timestamp -nt $img_source $img_dest` unless $debug;
  406. print $imgtxt;
  407. if ( $imgtxt =~ /(Insufficient disk space for .*)\n/i ) {
  408. blnotify "[$img_name] - $1";
  409. system "ECHO ERROR: $1 >> $log" if $log;
  410. }
  411. elsif ( $imgtxt =~ /(ERROR: .*)\n/i ) {
  412. blnotify "[$img_name] - $1";
  413. system "ECHO $1 >> $log" if $log;
  414. }
  415. else {
  416. system "ECHO Sucessfully built $img_name from $img_source with volume label $vol_lbl and timestamp $date,12:00:00 >> $log" if $log;
  417. crc_info( $img_name, get_crc( $img_dest ), $vol_lbl, "$date,12:00:00", $img_source );
  418. }
  419. }
  420. #==========================================================
  421. # Build an floppy disk image, trap any errors encountered.
  422. #==========================================================
  423. sub build_fimage {
  424. ( my $vol_lbl, my $timestamp, my $img_source, my $img_dest, my $bootable ) = @_;
  425. status_update ( "Creating floppy image $img_name from $img_source vol $vol_lbl timestamp $timestamp" );
  426. my $errors = 0;
  427. if ( $log ) {
  428. open BI_LOG, "$log";
  429. while (<BI_LOG>) {
  430. if ( /(WARNING|ERROR)( |:)/i ) {
  431. $errors++;
  432. }
  433. }
  434. close BI_LOG;
  435. }
  436. if ( $errors ) {
  437. blnotify "Due to ERRORS found in $log, image will not be built";
  438. return;
  439. }
  440. $img_name = $1 if $img_dest =~ /\\(\w+\.img)$/i;
  441. $boot_txt = "-bc:\\newiso\\etfsboot.com" if $bootable =~ /boot/i;
  442. print "\n\nBuilding $img_name from $img_source with volume label $vol_lbl and timestamp $timestamp...\n\n";
  443. print "C:\\idw\\fcopy $boot_txt -l$vol_lbl -t$timestamp -s$img_source $img_dest";
  444. $imgtxt = `c:\\idw\\fcopy $boot_txt -3 -l$vol_lbl -t$timestamp -s$img_source $img_dest` unless $debug;
  445. print $imgtxt;
  446. if ( $imgtxt =~ /(Insufficient disk space for .*)\n/i ) {
  447. blnotify "[$img_name] - $1";
  448. system "ECHO ERROR: $1 >> $log" if $log;
  449. }
  450. elsif ( $imgtxt =~ /(ERROR: .*)\n/i ) {
  451. blnotify "[$img_name] - $1";
  452. system "ECHO $1 >> $log" if $log;
  453. }
  454. else {
  455. system "ECHO Sucessfully built $img_name from $img_source with volume label $vol_lbl and timestamp $date,12:00:00 >> $log" if $log;
  456. }
  457. }
  458. #===============================================================
  459. # Find the first available server from a list of servers passed
  460. #===============================================================
  461. sub find_srv {
  462. @servers = @_;
  463. foreach $server ( @servers ) {
  464. print "find_srv: $server is ";
  465. if ( -e $server ) {
  466. print "Available. We'll use this one.\n";
  467. return $server;
  468. } else {
  469. print "Unavailable. Let's try the next one.\n";
  470. }
  471. }
  472. print "WARNING: No available servers found in list specified!\n";
  473. return 0;
  474. }
  475. #=======================================
  476. # Find the first available build server
  477. #=======================================
  478. sub find_bldsrv {
  479. $bldplat = $_[0];
  480. if ( $bldplat =~ /alpha/i ) { ### If looking for alpha shares
  481. @bldsrv_list = ( "\\\\ntbldslab2\\$lang.$build.alpha",
  482. "\\\\ntbuilds\\release\\$lang\\$build\\alpha",
  483. "\\\\intblds3\\$lang.$build.alpha",
  484. "\\\\ntblds6\\$lang.$build.alpha" );
  485. } else { ### If we don't specify platform then it's probably x86 or nec98.
  486. @bldsrv_list = ( "\\\\ntbldslab1\\$lang.$build.$bldplat",
  487. "\\\\ntbuilds\\release\\$lang\\$build\\$bldplat",
  488. "\\\\intblds3\\$lang.$build.$bldplat",
  489. "\\\\2kbldx4\\$lang.$build.$bldplat"
  490. );
  491. }
  492. return find_srv( @bldsrv_list );
  493. }
  494. #===============================================================================
  495. # Subroutine: ccopy
  496. #
  497. # Serves two functions. When in normal SKU creating mode it will copy files
  498. # and compress/decompress them if instructed. When in sku_check mode it will
  499. # compare the source and destination files compressing/decompressing as
  500. # necessary.
  501. #===============================================================================
  502. ## For ccopy()
  503. $COMPRESS = 1;
  504. $UNCOMPRESS = 2;
  505. sub ccopy {
  506. my $src_dir = $_[0]; ### Source
  507. my $dst_dir = $_[1]; ### Destination
  508. my $comp = $_[2]; ### Are we compressing/uncompressing?
  509. ### Split source into directory and filename
  510. $src_dir =~ s/(\S+)\\([0-9A-Z._\-\!]+)$/$1/i;
  511. my $src_file = $2;
  512. ### Split destination into directory and filename
  513. if ( -d $dst_dir ) {
  514. $dst_file = $src_file;
  515. } else {
  516. $dst_dir =~ s/(\S+)\\([0-9A-Z._\-\!]+)$/$1/i;
  517. $dst_file = $2;
  518. }
  519. ### Make temp dir to dump files that are to be compressed.
  520. my $temp_dir = "$ENV{'TEMP'}\\bl-temp";
  521. execute "mkdir $temp_dir" unless -e "$temp_dir";
  522. print "ccomp: Copying $src_dir\\$src_file to $dst_dir\\\n" unless $sku_check;
  523. if ( $comp == $COMPRESS ) {
  524. if ( !$sku_check ) {
  525. ### If the source file is to be compressed to the destination.
  526. execute "mcopy $log \"$src_dir\\$src_file\" \"$temp_dir\\$src_file\"";
  527. &dcomp( "$temp_dir\\$src_file", "$dst_dir" );
  528. }
  529. ### If the source file is to be uncompressed to the destination.
  530. ###
  531. ### Find the compressed filename since we only pass uncompressed filenames to &copycomp().
  532. $cfile = $src_file;
  533. $cfile =~ s/(.*)\S{1}/$1\_/i;
  534. execute "mcopy $log \"$dst_dir\\$cfile\" \"$temp_dir\\$cfile\"";
  535. execute "expand -r $temp_dir\\$cfile $temp_dir";
  536. ### If the files don't match, complain loudly.
  537. match( "$temp_dir\\$src_file", "$src_dir\\$src_file" );
  538. } elsif ( $comp == $UNCOMPRESS ) {
  539. if ( !$sku_check ) {
  540. ### If the source file is to be uncompressed to the destination.
  541. ###
  542. ### Find the compressed filename since we only pass uncompressed filename to &copycomp().
  543. my $cfile = $src_file;
  544. $cfile =~ s/(.*)\S{1}/$1\_/i;
  545. execute "mcopy $log \"$src_dir\\$cfile\" \"$temp_dir\\$cfile\"";
  546. execute "expand -r $temp_dir\\$cfile $temp_dir";
  547. execute "mcopy $log $temp_dir\\$src_file $dst_dir\\$dst_file";
  548. }
  549. ### If the source file is to be uncompressed to the destination.
  550. ###
  551. ### Figure out the compressed filename since we only pass
  552. ### uncompressed filenames to copycomp().
  553. my $c_src_file = $src_file;
  554. $c_src_file =~ s/(.*)\S{1}/$1\_/i;
  555. my $c_dst_file = $dst_file;
  556. $c_dst_file =~ s/(.*)\S{1}/$1\_/i;
  557. mkdir "$temp_dir\\file1", 1 unless -e "$temp_dir\\file1";
  558. mkdir "$temp_dir\\file2", 1 unless -e "$temp_dir\\file2";
  559. execute "mcopy $log \"$src_dir\\$c_src_file\" \"$temp_dir\\file1\\$c_src_file\"";
  560. execute "expand -r $temp_dir\\file1\\$c_src_file $temp_dir\\file1";
  561. execute "mcopy $log \"$dst_dir\\$dst_file\" \"$temp_dir\\file2\\$dst_file\"";
  562. ### If the files don't match, complain loudly.
  563. #match( "$temp_dir\\file1\\$src_file", "$temp_dir\\file2\\$dst_file" );
  564. execute "del /q $temp_dir\\file1\\$src_file";
  565. execute "del /q $temp_dir\\file2\\$dst_file";
  566. } else {
  567. ### Looks like were doing just a plain old mcopy.
  568. execute "mcopy $log \"$src_dir\\$src_file\" \"$dst_dir\\$dst_file\"";
  569. }
  570. }
  571. #=================================================
  572. # Keep track of CRC info
  573. #=================================================
  574. sub crc_info {
  575. if ( -e $crcfile ) {
  576. open CRCDAT, "$crcfile" or die "ERROR: Could not open $crcfile: $!";
  577. } else {
  578. open CRCDAT, ">$crcfile" or die "ERROR: Could not open $crcfile: $!";
  579. }
  580. while (<CRCDAT>) {
  581. chomp;
  582. ( my $img_name, my $crc_value, my $vol_label, my $timestamp, my $img_source ) = split /\|/;
  583. $img_name = lc $img_name;
  584. $crcH{$img_name}{'crc'} = $crc_value;
  585. $crcH{$img_name}{'vol'} = $vol_label;
  586. $crcH{$img_name}{'timestamp'} = $timestamp;
  587. $crcH{$img_name}{'source'} = $img_source;
  588. }
  589. close CRCDAT;
  590. if ( $_[1] ) {
  591. my $img_name = lc $_[0];
  592. my $crc_value = $_[1];
  593. my $vol_label = $_[2];
  594. my $timestamp = $_[3];
  595. my $img_source = $_[4];
  596. $crcH{$img_name}{'crc'} = $crc_value;
  597. $crcH{$img_name}{'vol'} = $vol_label;
  598. $crcH{$img_name}{'timestamp'} = $timestamp;
  599. $crcH{$img_name}{'source'} = $img_source;
  600. open CRCDAT, "> $crcfile";
  601. foreach $crckey ( sort keys %crcH ) {
  602. print CRCDAT "$img_name|$crcH{$img_name}{'crc'}|$crcH{$img_name}{'vol'}|$crcH{$img_name}{'timestamp'}|$crcH{$img_name}{'source'}\n";
  603. }
  604. close CRCDAT;
  605. } else {
  606. my $img_name = lc $_[0];
  607. if ( $crcH{$img_name}{'crc'} ) {
  608. return $crcH{$img_name}{'crc'}, $crcH{$img_name}{'vol'}, $crcH{$img_name}{'timestamp'}, $crcH{$img_name}{'source'};
  609. } else {
  610. print "\n\n\nERROR: Could not match image name to a CRC value.\n\n";
  611. print " This may be cause by crc.dat being empty or you mis-typed\n";
  612. print " the image name when running this script.\n";
  613. print "\&CRC_INFO() was called with invalid image name $img_name.\n\n";
  614. &blnotify( "ERROR: &CRC_INFO() called with invalid image name ($img_name)." );
  615. die "ERROR: &CRC_INFO() called with invalid image name ($img_name).";
  616. return 0;
  617. }
  618. }
  619. }