Home | History | Annotate | Download | only in scripts
      1 #! /usr/perl5/bin/perl
      2 #
      3 # CDDL HEADER START
      4 #
      5 # The contents of this file are subject to the terms of the
      6 # Common Development and Distribution License (the "License").
      7 # You may not use this file except in compliance with the License.
      8 #
      9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
     10 # or http://www.opensolaris.org/os/licensing.
     11 # See the License for the specific language governing permissions
     12 # and limitations under the License.
     13 #
     14 # When distributing Covered Code, include this CDDL HEADER in each
     15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
     16 # If applicable, add the following below this CDDL HEADER, with the
     17 # fields enclosed by brackets "[]" replaced with your own identifying
     18 # information: Portions Copyright [yyyy] [name of copyright owner]
     19 #
     20 # CDDL HEADER END
     21 #
     22 
     23 #
     24 # Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
     25 # Use is subject to license terms.
     26 #
     27 # ident	"%Z%%M%	%I%	%E% SMI"
     28 #
     29 
     30 #
     31 # Generate README.opensolaris from a template for inclusion in a
     32 # delivery wad.
     33 # Usage: mkreadme_osol README.opensolaris < template
     34 #
     35 
     36 use strict;
     37 use warnings;
     38 
     39 #
     40 # Timeout and retry settings for wget.  Allow one retry for the
     41 # occasional glitch, but don't wait longer than 5 minutes (so as not
     42 # to hold up the build).
     43 #
     44 my $timeout = 150;
     45 my $tries = 2;
     46 
     47 #
     48 # Markers in the web pages that we download.
     49 #
     50 my $begin_data = qr/<!-- begin_data --><pre>/;
     51 my $end_data = qr/<\/pre><!-- end_data -->/;
     52 
     53 my $readme_fn = shift || die "missing README filepath\n";
     54 open(README_OUT, ">$readme_fn") || die "couldn't open $readme_fn\n";
     55 my @lines = <STDIN>;
     56 
     57 my %content;
     58 
     59 if (! $ENV{"HTTP_PROXY"}) {
     60 	if ($ENV{"http_proxy"}) {
     61 		$ENV{"HTTP_PROXY"} = $ENV{"http_proxy"};
     62 	} else {
     63 		$ENV{"HTTP_PROXY"} = "http://webcache.sfbay:8080";
     64 	}
     65 }
     66 if (! $ENV{"http_proxy"}) {
     67 	$ENV{"http_proxy"} = $ENV{"HTTP_PROXY"};
     68 }
     69 
     70 foreach (@lines) {
     71 	chomp;
     72 	if (/^<!-- #include (.+) -->$/) {
     73 		my $url = $1;
     74 		print "Getting $url\n";
     75 		$content{$url} =
     76 		    `/usr/sfw/bin/wget -q -O - -T $timeout -t $tries $url`;
     77 		if (! $content{$url}) {
     78 			die "$url: invalid or empty URI.\n";
     79 		}
     80 		$content{$url} =~ s/\r//g;
     81 		my @c = split /\n/, $content{$url};
     82 		while ((my $l = shift @c) !~ /$begin_data/) {};
     83 		while ((pop @c) !~ /$end_data/) {};
     84 		$content{$url} = join "\n", @c;
     85 	}
     86 }
     87 
     88 foreach (@lines) {
     89 	if (/^<!-- #include (.+) -->$/ && exists($content{$1})) {
     90 		print README_OUT $content{$1};
     91 	} else {
     92 		print README_OUT "$_\n";
     93 	}
     94 }
     95 
     96 print README_OUT "\n\n";
     97 close(README_OUT);
     98