Code Search for Developers
 
 
  

coe_retrofit.in from LinuxCOE at Krugle


Show coe_retrofit.in syntax highlighted

#!/usr/bin/perl
##############################################################################################
# File:         coe_retrofit
# Description:  Create a little perl 'retrofit' script
# Author:       Lee Mayes   ( email leem@hp.com )
# Created:      31 Jan 2001
# Language:     perl
# Package:      LinuxCOE
##############################################################################################
# © Copyright 2000-2007 Hewlett-Packard Development Company, L.P
#
# This program is free software; you can redistribute it and/or modify it under the terms of 
# the GNU General Public License as published by the Free Software Foundation; either version 
# 2 of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
# without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with this program; 
# if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
##############################################################################################
# Basic process flow
# Step 1 - distro
# Step 2 - value add bundles
# Step 3 - Just Do It! 
##############################################################################################
use strict;
use CGI;
use lib qw (@prefix@/lib @prefix@/includes);
use LinuxCOE;
use sysdes_paths;
my $debug = 0;
my $nonav = 0;

my $q = new CGI ();
my $db = new LinuxCOE;
my $COE_VER = $db->def('COE_VER');
$db->debug($debug);
$db->nonav($nonav);
my $cgi = '/@PACKAGE_NAME@-cgi-bin/coe_retrofit';
my $defs = $q->param('defs');
if ( $defs ) {
  $db->LoadDefs($defs);
  $cgi .= "?defs=$defs";
}
$db->InitDB;
my $arch = $db->def('ARCH');
my $default = $db->def('DIST');
$default .= " - ". $db->def('ARCH');

# Switch to https?

my $sec_level = $db->def('SECURITY_LEVEL');
my $url = $q->self_url;
if (( $url =~ /http:/ ) && ( $sec_level eq 'SECURE' )) {
  my $host = `/bin/hostname`;
  chomp $host;
  my $securehost = $db->def('SSLHOST') || (gethostbyname($host))[0];
  $cgi = "https://${securehost}$cgi";
  print $q->redirect($cgi);
}

# Disable interactive HTML if requested || SECURITY_LEVEL = SECURE

if ( $sec_level eq 'SECURE' ) {
  $db->def('FINAL_INTERACTIVE',0);
  $db->def('FINAL_URL_METHOD','https://');
  my $path = $db->def('FINAL_ABS_PATH');
  if ( $path =~ /\/$/ ) { chop($path) }
}

my $tdtag = $db->tdtag;
my $thtag = $db->thtag;
my $tdfont = $db->tdfont;
my $thfont = $db->thfont;

print $q->header;

# Here's the variables we'll keep track of screen to screen <HIDDEN>

my @vars = qw(defs os waystation bundles);

# This is what you see vs. the real variable name...
my %varname = (
  'os' => 'Supported Distros',
  'waystation' => 'COE Waystation',
);

my %labels;
foreach my $var (@vars) {

    $labels{$var} = $varname{$var} || $var;
}


####### MAIN ########
if    (! $q->param('action') )     { &Step1 }
elsif ($q->param('action') eq '2') { &Step2 }
elsif ($q->param('action') eq '3') { &Step3 }
else {  &end_it_now("Say what???") }
####### End of MAIN ########

sub Step3 {

  my $temp = &reqd('os');
  my ($os,$arch) = split(' - ',$temp);
  my ($distro,$version) = split(' ',$os);
  my $ftphost = `/bin/hostname`;
  chomp($ftphost);
  $ftphost = $db->def('HOSTNAME') || $ftphost;
  $db->ShowNav("LinuxCOE $COE_VER retrofit script created"); 
  my @coe_bundles = $q->param('coe_bundles');        
  my $retro = "retrofit$$";
  my ($waystation,@rest) = split(' ',$q->param('waystation'));
  my $ftp_dir = $db->def('FINAL_ABS_PATH');
  print STDERR "Retrofit: Opening $ftp_dir/$retro for writing!\n";
  unless ( open(RETRO,">$ftp_dir/$retro") ) {
    &end_it_now("Error opening $ftp_dir/$retro : $!\n");
  }
  my $skel; 
  my $RPM=1;
  if ( $os =~ /SuSE/ ) {
    $skel = $db->find_file("data/suse_retro_skel");
  } elsif (( $os =~ /Debian/ ) || ( $os =~ /buntu/ )) {
    $skel = $db->find_file("data/deb_retro_skel");
    $RPM=0;
  } else {
    $skel = $db->find_file("data/retro_skel");
  }

# Open the virgin skel file we'll populate with requested software selections

  print STDERR "retrofit: Opening $skel for input template!\n" if $debug;
  open(IN,"$skel") || &end_it_now("Error opening $skel : $!\n");

# Dump the header

  while(<IN>) {
     # Stick in top of file
     s/RETROFIT/$retro/;
     last if /^# LINUXCOE_PERL_HERE/;
     print RETRO;
  }

# APT, YUM, BOTH?

  my @methods = $db->sw_methods($distro,$version,$arch);
  my $APT=0;                                      # Use APT in post processing
  my $YUM=0;                                      # Use YUM in post processing
  if ( grep(/APT/,@methods) ) { $APT=1 }
  if ( grep(/YUM/,@methods) ) { $YUM=1 }
  print STDERR "\$APT=$APT, \$YUM=$YUM\n" if $debug;

# Ok, here's where we'll build dirs for source depot config breadcrumbs/patching

  my $patch_me = $q->param('patch_me');
  my $patch_method = $q->param('patch_method');
  my $patch_freq = $q->param('patch_freq');

# What method do we use for SysDes patching?

  print RETRO "# Install COE bundles\n";
  print RETRO qq[system "/bin/mkdir -p /etc/opt/LinuxCOE/apt /etc/opt/LinuxCOE/yum";\n];
  print RETRO qq[system "/bin/mkdir -p /etc/opt/LinuxCOE/apt.sources /etc/opt/LinuxCOE/yum.sources";\n];
  print RETRO qq[system "/bin/mkdir -p /etc/opt/LinuxCOE/sw";\n];
  print RETRO qq[system "echo $patch_method >/etc/opt/LinuxCOE/patch_method";\n];
  print RETRO qq[\$YUM=$YUM;\n] if ($YUM);

# Do they want patches @ install time?  If so, touch PATCH_ME

  if ( $patch_me ) {
    print RETRO "\n# Customer request patch to current, set patch_me flag\n";
    print RETRO qq[ open(PATCH,">/etc/opt/LinuxCOE/sw/PATCH_ME");\n];
    print RETRO qq[close(PATCH);\n];
  }

# Do they want continued patching?

  if (( $patch_freq ) && ( $patch_freq ne 'never' )) {
    print RETRO qq[open(OUT,">/etc/cron.${patch_freq}/apt_patch");
    print OUT qq{#!/bin/bash
/bin/touch /etc/opt/LinuxCOE/apt/PATCH_ME
/etc/rc.d/init.d/LinuxCOE-Bundles start
};
system "/bin/chmod +x /etc/cron.${patch_freq}/apt_patch";\n ];
  }

# Slurp on thru until BASE1-3 time...

  while(<IN>) {
     # Stick in top of file
     s/RETROFIT/$retro/;
     last if /^# REAL_DATA_HERE/;
     print RETRO;
  }
  print RETRO qq['WaYsTaTiOn' => "$waystation",\n];
  my $method = $db->def('METHOD');

# Here's where we populate the 'forced' stuff (BASE-1/2/3)

  my %extra_rpms = $db->make_Base($method,$waystation,$distro,$version,$arch);
  foreach my $key (sort(keys(%extra_rpms))) {
    next unless ( $extra_rpms{$key} );
    print RETRO qq["$key" => "$extra_rpms{$key}",\n];
  }
  while(<IN>) {
    last if /^# APT_DEPOTS_HERE/;
    print RETRO;
  }

# Populate /etc/opt/LinuxCOE/apt.sources OR yum.sources with what we'll need
# OK, change, we'll use apt.sources to prime /etc/sysconfig/rhn/sources, so build the 
#   apt breadcrumb trail for APT's sources.list even if we're using YUM

# Let's drop a little file with the tuple we were installed with

  print RETRO qq[open(OUT,">/etc/opt/LinuxCOE/INSTALLED");\n];
  print RETRO "print OUT qq[$distro $version $arch];\n";
  print RETRO "close(OUT);\n";

# First do the base (OS and Patch Trees)

  my $t = $method;
  if (($t eq 'CDROM' ) || ($t eq 'NFS' )) {
     $t = $db->def('METHOD') || "HTTP";
  }
  $t = lc($t) . '://';
  my $infile = $db->find_file("depots/apt-$distro-$version-$arch");
  unless ($infile) { $infile = $db->find_file("depots/apt-$distro-$version") }
  unless ($infile) { $infile = $db->find_file("depots/apt-$distro") }
  if (open(SOURCES,"$infile")) {
    print RETRO qq[open(OUT,">/etc/opt/LinuxCOE/apt.sources/COE_BASE");\n];
    print RETRO "print OUT qq[";
    my $lines;
    while($lines = <SOURCES>) {
      $lines =~ s/\@METHOD\@/$t/g;
      $lines =~ s/\@WAYSTATION\@/$waystation/g;
      $lines =~ s/\@ARCH\@/$arch/g;
      $lines =~ s/\@DISTRO\@/$distro/g;
      $lines =~ s/\@VERSION\@/$version/g;
      print RETRO "$lines";
    }
    close(SOURCES);
    print RETRO "];\nclose(OUT);\n";
  }
  if ( $YUM ) {
    my $infile = $db->find_file("depots/yum-$distro-$version-$arch");
    unless ($infile) { $infile = $db->find_file("depots/yum-$distro-$version") }
    unless ($infile) { $infile = $db->find_file("depots/yum-$distro") }
    if ( open(SOURCES,"$infile") ) {
      print RETRO qq[open(OUT,">/etc/opt/LinuxCOE/yum.sources/COE_BASE");\n];
      print RETRO "print OUT qq[";
      my $lines;
      while($lines = <SOURCES>) {
        $lines =~ s/\@METHOD\@/$t/g;
        $lines =~ s/\@WAYSTATION\@/$waystation/g;
        $lines =~ s/\@ARCH\@/$arch/g;
        $lines =~ s/\@DISTRO\@/$distro/g;
        $lines =~ s/\@VERSION\@/$version/g;
        print RETRO "$lines";
      }
      close(SOURCES);
      print RETRO "];\nclose(OUT);\n";
    }
  }

# Then do additional 'ADDON' depots

  my @NAMES = split(' ',$db->def('ADDONS'));
  foreach my $addon (@NAMES) {
    my ($config,$helpurl,$rpmapt,$debapt,$rpmyum,@needs) = $db->parse_addon_config($addon,$distro,$version,$arch);
    my ($d,$f,$count) = $db->parse_coe_bundles($arch,$distro,$version,$config);
    print STDERR "Addon $addon has $count entries for $distro $version $arch.\n" if $debug;
    next unless ($count);
    if ( $RPM ) {
      $rpmapt =~ s/\@METHOD\@/$t/g;
      $rpmapt =~ s/\@WAYSTATION\@/$waystation/g;
      $rpmapt =~ s/\@ARCH\@/$arch/g;
      $rpmapt =~ s/\@DISTRO\@/$distro/g;
      $rpmapt =~ s/\@VERSION\@/$version/g;
      print RETRO qq[open(OUT,">/etc/opt/LinuxCOE/apt.sources/$addon");
print OUT "$rpmapt";
close(OUT);
];
    }
    unless ( $RPM ) {
      $debapt =~ s/\@METHOD\@/$t/g;
      $debapt =~ s/\@WAYSTATION\@/$waystation/g;
      $debapt =~ s/\@ARCH\@/$arch/g;
      $debapt =~ s/\@DISTRO\@/$distro/g;
      $debapt =~ s/\@VERSION\@/$version/g;
      chomp($debapt);
      my @lines = split("\n",$debapt);
      my $temp = $debapt;
      undef($debapt);
      foreach my $line (@lines) {
        if ( $line =~ /^KEY: /) {
          my @data = split(' ',$line);
          print RETRO qq[system "wget $data[1] -O - | apt-key add -";\n];
        } else {
          $debapt .= "$line\n";
        }
      }
      print RETRO qq[open(OUT,">/etc/opt/LinuxCOE/apt.sources/$addon");
print OUT "$debapt\\n";
close(OUT);
];
    }
    if ( $YUM ) {
      $rpmyum =~ s/\@METHOD\@/$t/g;
      $rpmyum =~ s/\@WAYSTATION\@/$waystation/g;
      $rpmyum =~ s/\@ARCH\@/$arch/g;
      $rpmyum =~ s/\@DISTRO\@/$distro/g;
      $rpmyum =~ s/\@VERSION\@/$version/g;
      print RETRO qq[open(OUT,">/etc/opt/LinuxCOE/yum.sources/$addon");
print OUT "$rpmyum";
close(OUT);
];
    }
  }

# APT/YUM/RHN/YOU breadcrumbs done, proced to bundle selections

  while(<IN>) { 
    last if /^# COE_BUNDLES_HERE/;
    print RETRO;
  }
  my ($d,$f) = $db->parse_coe_bundles($arch, $distro, $version, 'ALL');
  foreach my $bundle (@coe_bundles) {
    my @files = split(' ',${$f}{$bundle});
    my $archin = shift(@files);
    my $rpms = join(' ',@files);
    print RETRO qq["$bundle" => "$rpms",\n];
  }

  while(<IN>) { print RETRO }
  close(RETRO);
  close(IN);
  my $final_method = $db->def('FINAL_URL_METHOD');
  my $final_path = $db->def('FINAL_URL_PATH');
  print $q->h4("LinuxCOE $COE_VER retrofit script created");        
  print "<P>Download <b><a href=${final_method}${ftphost}${final_path}/$retro>this script</a></b> to your existing $distro $version linux installation.</P>\n";
  print "<P>Hint: 'Right Click -> Save As' to store, Left click to view.</P>\n";
  print "<P>Then as root issue the following command:</p>";
  print "<UL><pre>perl $retro\n</pre>\n</UL>";
  print "<P>This script will attempt to install the following LinuxCOE bundles:\n<UL>\n";
  foreach my $bundle (@coe_bundles) { print " <LI>$bundle\n" }
  print "</UL></P>\n";
  print "Please see the script for additional help if needed.\n";

  $db->ShowFooter;
  $db->CleanUp($ftp_dir);
  exit;

} # End of Step3

sub Step2 {

# Pick a profile and install method suitable for your OS choice in Step1
#  If you entered a hostname/IP, I prompt for N/W info here too

  $db->ShowNav("Retrofit LinuxCOE $COE_VER on an existing Linux installation - Step 2");
  &do_ov;
  print $q->h4("Retrofit LinuxCOE $COE_VER on an existing Linux installation - Step 2"); 
  $q->delete('action');
  print $q->start_form('POST','/@PACKAGE_NAME@-cgi-bin/coe_retrofit');
  print $q->hidden(-name=>'action', -default=>'3'),"\n";       
  &do_hidden;
  my $temp = &reqd('os');
  my ($os,$arch) = split(' - ',$temp);
  if ( $os eq 'VMWare' ) {
    my $msg = "Sorry, $os is not currently supported by the LinuxCOE retrofit process.<P>";
    $msg .= "Please check back soon!";
    &end_it_now("$msg")
  }
  my $method = 'HTTP';
  my ($distro,$version) = split(' ',$os);


  my @waystations = $db->show_os($distro,$version,$arch,$method);
   print qq[
<TABLE>
<TR>
 <TH><FONT $tdfont>Select a LinuxCOE waystation:</FONT></TH>
 <TD $tdtag><FONT $tdfont><SELECT NAME="waystation">];
  unless ($db->def('WAYSTATION') ) { print qq[<OPTION VALUE="" SELECTED>Required] }
  foreach my $waystation (@waystations) {
    my ($way,@loc) = split(' ',$waystation);
    if ( $way eq $db->def('WAYSTATION') ) {
      print "<OPTION VALUE=\"$way\" SELECTED>$way";
    } else {
      print "<OPTION VALUE=\"$way\" >$way";
    }
    if ( @loc ) { print " - @loc" }
  }
  print "</SELECT></TD>\n</TR>\n";
  print "</TABLE>\n";
  my @NAMES = split(' ',$db->def('ADDONS'));
  foreach my $NAME (@NAMES) {
    $db->Display_COE_Bundles($os,$arch,undef,$NAME);
  }
  $db->Show_Patch($distro,$version,0,'',$arch);
  print $q->submit(-value=>'Continue');    
  print $q->end_form;
  print $q->end_html;
  $db->ShowFooter;
  exit;
 
} # End of Step2

sub reqd {

# Ralph if unset required field

  my $var = shift;
  my $val = $db->clean_var($q->param($var));
  if ( $val ) { return($val) }
  else {
    &end_it_now("$labels{$var} is a Required field!<BR>Go back and set it!\n");
  }

}

sub Step1 {

# Just dump the first form

  $db->ShowNav("Retrofit LinuxCOE $COE_VER on an existing Linux installation - Step 1");
  &do_ov;
  print $q->h4("Retrofit LinuxCOE $COE_VER on an existing Linux installation - Step 1"); 
  print "What Linux distribution/architecture do you have? <P>\n";
  print $q->start_form(-action=>'/@PACKAGE_NAME@-cgi-bin/coe_retrofit');
  &do_hidden;
  print $q->hidden(-name=>'action', -default=>'2'),"\n";       
  my @choices = $db->show_os;
  print qq[

<TABLE BORDER=0>
<TR>
 <TD $tdtag><FONT $tdfont>$labels{'os'}:</FONT></TD>
 <TD $tdtag><FONT $tdfont><SELECT NAME="os">
];
  foreach my $os (@choices) { 
    if ( $os eq $default ) {
      print "<OPTION SELECTED>$os";
    } else {
      print "<OPTION>$os";
  }
  }
  print qq[</SELECT></FONT></TD>
</TR>
</TABLE>
];

  print $q->submit(-value=>'Continue');    
  print $q->end_form;
  print $q->end_html;
  $db->ShowFooter;
  exit;

} # End of Step1

sub end_it_now {

# Exit with extreme predjudice

  my $errmsg = shift(@_);
  $db->ShowNav("LinuxCOE System Designer Error");
  print $q->h4("$errmsg");
  print "<hr>If this error message looks bogus, contact <a href=\"mailto:leem\@atl.hp.com\">leem\@atl.hp.com</a>\n";
  print $q->end_html;
  $db->ShowFooter;
  exit;

}     

sub do_hidden {

# populate the form with hidden variables if set

  foreach my $var (@vars) {
    if ( $q->param($var) ) {
      print $q->hidden(-name=>"$var", -default=>$q->param($var)),"\n";  
    }
  }

}

sub do_ov {

  return;
  print qq[
<DIV ID="overDiv" STYLE="position:absolute; visibility:hide; z-index:2;"></DIV>
<SCRIPT LANGUAGE="JavaScript" SRC="/overlib.js"></SCRIPT>
];

}




See more files for this project here

LinuxCOE

The Linux Common Operating Environment (LinuxCOE) facilitates provisioning and lifecycle support of many popular Linux distributions, versions and architectures.

Project homepage: http://sourceforge.net/projects/linuxcoe
Programming language(s): JavaScript,Perl,Shell Script
License: gpl2

  Makefile.am
  Makefile.in
  README
  coe_bootimage.in
  coe_info.in
  coe_profiles.in
  coe_retrofit.in
  nph-coe_image.in
  nph-debian_image.in
  nph-mandriva_image.in
  nph-suse_image.in