Linux compatibility VMWARE GSX 2.5

easlyneanar lorennan easlyneanar at hotmail.com
Mon Aug 18 15:48:59 PDT 2003


   I'm trying to install Vmare GSX 2.5 under FreeBSD 4.8 with the linux
   compatibility

   @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

   This is the output of the vmware-installer.pl original (see
   vmware-installer.pl in attach)

   @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

   Output after running here:

   Where would you like to install the VMware Management UI
   [/home/vmware/mui] :
   Starting to untar the image to /home/vmware/mui
   Finished untar.
   Configuring httpd.conf to run Apache as:
         User: 'www' and Group: 'www'
    The installer is not able to find the directory where the 'init'
   scripts reside.
    The directory should contain init.d/, and from rc0.d/ to rc6.d/
    These directories are not in any of the standard locations:
    '/sbin/init.d', '/etc/rc.d/init.d', '/etc/init.d'
    As a result, the VMware Management UI Web Server will not
   automatically
    restart when this machine is rebooted.  You can start the VMware
   Management UI
    Web Server after a reboot with this command (as root):
            /home/vmware/mui/apache/bin/apachectl start
   [Press 'Enter' to continue.] :

   Using Existing SSL Certificate.
   Couldn't find necessary components on your system. It appears that you
   are missing the following library: libdb.so.3
   New versions of Red Hat Linux (8.0+) are known to ship without these
   libraries. If you are running Red Hat 8.0 or greater, please install
   this rpm: compat-db-3.3-<###> rpm (where <###> is a  version number
   particular to your version of the distribution) from your installation
   CD
   If you are running a distribution other than Red Hat, please contact
   your vendor for a suitable library. Once the  package has been
   installed, you may start the VMware Management UI with the following
   command:
   /home/vmware/mui/apache/bin/apachectl start
   UnForgiven# /home/vmware/mui/apache/bin/httpd: signal 13

   @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

   This is the output of the modified file of vmware-installer.pl (see
   vmware-install.pl.modified in attach)

   @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

   I add the libdb.so.3 to the /usr/compat/linux/lib/
   and I did brandelf -t Linux /usr/compat/linux/lib/libdb.so.3

   I modified too some variable to put /usr/compat/linux/lib instead of
   the /lib link.
   I removed the Eula asking if you accept their policy (to save time)

   Here is the Output:

   UnForgiven# ./vmware-install.pl.modified

   Welcome to the VMware Management UI installer for Linux.  This install
   program will extract an Apache web server, Perl extension modules, and
   the VMware Perl API to your machine.
   The directory /home/vmware/mui  contains a previous
   installation of VMware Management UI.
   Stopping any running VMware Management UI processes.
   Stopping apache.
   Removing the old installation....
   #failed to open /var/lib/rpm/packages.rpm: No such file or directory
   #rpmQuery: rpmdbOpen() failed
   #<easly> think that this error is not important it's seem to be when
   it's trying to remove the #<easly>old install.
   Where would you like to install the VMware Management UI
   [/home/vmware/mui] :
   Starting to untar the image to /home/vmware/mui
   Finished untar.
   Configuring httpd.conf to run Apache as:
         User: 'www' and Group: 'www'
    The installer is not able to find the directory where the 'init'
   scripts reside.
    The directory should contain init.d/, and from rc0.d/ to rc6.d/
    These directories are not in any of the standard locations:
    '/sbin/init.d', '/etc/rc.d/init.d', '/etc/init.d'
   , 'This have been changed by /usr/local/etc/rc.d' As a result, the
   VMware Management UI Web Server will not automatically
    restart when this machine is rebooted.  You can start the VMware
   Management UI
    Web Server after a reboot with this command (as root):
            /home/vmware/mui/apache/bin/apachectl start
   [Press 'Enter' to continue.] :
   Using Existing SSL Certificate.
   /home/vmware/mui/apache/bin/httpd: error while loading shared
   libraries: /lib/libdb.so.3: ELF file OS ABI invalid
   /home/vmware/mui/apache/bin/httpd: exit status 127
   Starting web server.
   /home/vmware/mui/apache/bin/httpd: error while loading shared
   libraries: /lib/libdb.so.3: ELF file OS ABI invalid
   /home/vmware/mui/apache/bin/apachectl start: httpd could not be
   started
   WARNING:  Can't start the apache web server.
   The VMware Management UI has been successfully installed.
   To use the VMware Management UI setup tools, point your browser to:
       [1]http://xxx.syrs.com:8856/login
   To un-install the VMware Management UI, please run:
       /home/vmware/mui/bin/vmware-uninstall-mui.pl

   In this way i' been unable to run the apache server and run vmware GSX

   If anyone  have idea on how to make it working or if any of you had
   sucessfully installed vmware GSX under FreeBSD let me know what you
   did :)

   P.S.: I'll try to dl an other source of the libdb.so.3 maybe this one
   is corrupted and i'll try without do the brandelf -t Linux.
     _________________________________________________________________

   Protect your PC - [2]Click here for McAfee.com VirusScan Online

References

   1. http://xxx.syrs.com:8856/login
   2. http://g.msn.com/8HMUEN/2755??PS=
-------------- next part --------------
#!/usr/bin/perl -w
# If your copy of perl is not in /usr/bin, please adjust the line above.
#
# Copyright 1998 VMware, Inc.  All rights reserved. -- VMware Confidential
#
# Host configurator for VMware Management UI


use strict;

# Constants
my $TARFILE = "./vmware-m-ui.tar";
my $CONSOLEDIR = "./console-distrib";
my $MEGSIZE = "6";
my $KSIZE   = 6000;
my $VMDISTRIB = "vmware-mui-distrib";
my $INSTALLER = "vmware-install.pl";
my $UPDATER = "vmware-update-mui.pl";
my $UNINSTALLER = "vmware-uninstall-mui.pl";
my $PRODUCTNAME  = "VMware Management UI";
my $WELCOME = "\
Welcome to the $PRODUCTNAME installer for Linux.  This install
program will extract an Apache web server, Perl extension modules, and
the VMware Perl API to your machine.

";

my $UPWELCOME = "\
Welcome to the $PRODUCTNAME update installer for Linux.
This install program will update the $PRODUCTNAME Apache
web server on your machine to include the latest security fixes.
";

my $UNWELCOME = "\
Welcome to the $PRODUCTNAME uninstaller for Linux.  This uninstall
program will remove the $PRODUCTNAME Apache web server, Perl
extension modules, and the VMware Perl API from your machine.

";

# Globals
my $gSecureScript = "security-config.pl";
my $gRegistryDir  = "/etc/vmware-mui";
my $gRegistryFile = "$gRegistryDir/config";
my $gServerInstDir = "/usr/compat/linux/lib/vmware-mui";
my $gHostname = "localhost";
my $gPort = 8856;
my $gInstDir = "/home/vmware/mui";
my $gCertLoc = "/etc/vmware-mui/ssl";
my $gCertUniqIdent = "(564d7761726520496e632e)";
my $gConfig = "/etc/vmware/preferences";
my $gStartDir;
my $gProgName;
my $gPortOption;
my $gSSLByDefault;
my $gTmpDir = "/tmp/mui-inst.$$";
my @gModFiles = (
  "apache/conf/httpd.conf",
  "apache/conf/access.conf",
  "apache/conf/setup.pl",
  "apache/bin/apachectl",
  "apache/bin/apxs",
  "lib/perl5/site_perl/5.005/VMware/Management/Overview.pm",
  "lib/perl5/site_perl/5.005/VMware/HConfig/Constant.pm",
  "apache/htdocs/vmware/config/config.ph",
);
my @gKillFiles = (
  "EULA.txt",
  "VMware",
  "apache",
  "bin",
  "include",
  "lib",
  "man",
  "ssl",
);
my %gRCLinks = (
  "rc3.d/S91httpd.vmware", "httpd.vmware",
  "rc4.d/S91httpd.vmware", "httpd.vmware",
  "rc5.d/S91httpd.vmware", "httpd.vmware",
  "rc3.d/K08httpd.vmware", "httpd.vmware",
  "rc4.d/K08httpd.vmware", "httpd.vmware",
  "rc5.d/K08httpd.vmware", "httpd.vmware",
);

my %gConfData = (
  "mui.fullpath", $gInstDir,
  "mui.initd.fullpath", "",
  "security.fullpath","/usr/bin/$gSecureScript",
);

my $debug   = 0;
my $noExecDebug   = 0;

#  Pass in a default answer - ask() will prompt the user for input and 
return
#  with user typed input or the default if they just hit <enter>.

sub ask {
  my ($default) = @_;
  my $newDefault;

  nprint ("[$default] : ");
  chop($newDefault = <STDIN>);
  nprint ("\n");
  lprint ("Answer of $newDefault\n");

  return $default if ($newDefault eq "");
  return $newDefault;
}

#  Handle calls to system()
sub SYSTEM {
  my ($x) = @_;

  if ($noExecDebug) {
    print STDERR "Test: $x\n";
    return(0);
  } else {
    print STDERR "SYSTEM: $x\n" if $debug;
    return ((system ($x) >> 8));
  }
}

#  Normal Print
sub nprint {
  my ($msg) = @_;
#  print LOG "$msg";
  print STDOUT "$msg";
  return(0);
}

#  Logging Print
sub lprint {
  my ($msg) = @_;
#  print LOG "**DEBUG**: $msg";
}


#  Error Print
sub eprint {
  my ($msg) = @_;
  $msg .= "\n" if (substr($msg, -1) ne "\n");
  print STDERR "$msg";
  print STDERR "\nExecution aborted.\n\n";

  exit(1);
}

# Usage Messages
sub instUsage {
  nprint("$INSTALLER: Installs the $PRODUCTNAME\n");
  nprint("Usage: $INSTALLER\n");
  exit(1);
}
sub updateUsage {
  nprint("$UPDATER: Updates the $PRODUCTNAME\n");
  nprint("Usage: $UPDATER\n");
  exit(1);
}
sub uninstUsage {
  nprint("$UNINSTALLER: Uninstalls the $PRODUCTNAME\n");
  nprint("Usage: $UNINSTALLER\n");
  exit(1);
}

# Intro text
sub showWelcome {
  nprint "$WELCOME\n";
}

# Update text
sub showUpWelcome {
  nprint "$UPWELCOME\n";
}

# Uninstall text
sub showUnWelcome {
  nprint "$UNWELCOME\n";
}

# Name of the machine we're on
sub initializeGlobals {
  chop($gHostname = `hostname`);
  if (checkServer() && $gHostname =~ m/localhost.localdomain/ ) {
     #We might be running from the esx cdrom.  This means
     #hostname has not yet been setup properly.  Grab
     #correct value from /etc/sysconfig/network .
     #Still potentially wrong if console has dhcp address.
     my $hostLine = `grep "HOSTNAME" /etc/sysconfig/network`;
     if ($hostLine =~ m/^HOSTNAME\s*=\s*(\S+)\s*$/) {
        $gHostname = $1;
     }
  }
  #esx uses the stardard http & htttps ports (80, 443)
  $gPortOption = checkServer() ? "-DSTANDARD_PORTS -DESX" : "-DGSX";

  #esx will default to using https, unless told to use http
  #gsx will default to using http, unless told to https
  $gSSLByDefault = checkServer() ? "-DSSL_ONLY" : "";
}

# Tell if the user is the super user
sub is_root {
  return ($> == 0);
}

# EULA text
#sub showEULA {
  # Show only for WGS.  SS presents the EULA at a different time.
#  if( !checkServer() ) {
#   nprint("You must read and accept the End User License Agreement to 
continue.\n");
  #  ask ("Press 'Enter' to display it.");

#    my $yn = "";
#    # Deal with people who have PAGER with commands tacked on.
#    my $PAGER;
#    my @PAGER;
#
#    if (defined $ENV{'PAGER'}) {
#      @PAGER = split(' ', $ENV{'PAGER'});
#    }
#
#    if (defined $PAGER[0]) {
#      $PAGER = $PAGER[0];
#    } else {
#      $PAGER = "more";
#    }
#    if (not -e "./EULA.txt") {
#      nprint("Can't file the file: ./EULA.txt\n");
#      eprint("Please run the installer from the \"$VMDISTRIB\" 
directory.\n");
#    }
#    SYSTEM("$PAGER ./EULA.txt");

#REDO1:
#    nprint("Do you accept? (yes/no) ");
#    $yn = ask($yn);
#    return if ($yn =~ /^yes/i);
#    goto REDO1 if ($yn !~ /^no/i);
#    eprint("Please try again when you are ready to accept.\n\n");
#  }
#}

# Where do we install?
sub getInstallDir {
  if( !checkServer() )  {
    nprint("\nWhere would you like to install the $PRODUCTNAME\n");
    $gInstDir = ask($gConfData{"mui.fullpath"});
  } else {
    # User doesn't get a choice for ESX
    $gInstDir = $gServerInstDir;
  }

# mkdir -p will return 0 in cases when there was actually a problem
SYSTEM("mkdir -p $gInstDir");

if (! -d $gInstDir) {
   eprint("The installer is not able to create the directory you 
specified:\n    $gInstDir\nPlease check file permissions and available\ndisk 
space and then re-run the installer.\n");
}
if (! -w $gInstDir) {
   eprint("The installer is not able to write to the directory you 
specified:\n    $gInstDir\nPlease check file permissions and then re-run the 
installer.\n");
}
updateConfig("mui.fullpath", $gInstDir);
}


# Read the config vars to our internal array
sub readConfig {
  if (open(INSTALLDB, $gRegistryFile)) {
    # Populate our array with everthing from the conf file.
    while (<INSTALLDB>) {
      m/^\s*(\S*)\s*=\s*(\S*)/;
      $gConfData{$1} = $2;
      nprint("---------> Setting $1 = $2\n") if $debug;
    }
    close(INSTALLDB);
    return(1);
  }
  return(0);
}

sub updateConfig {
  my ($name, $val) = @_;
  my $key;

  # Read any existing conf file
  readConfig();

  # If we can't find the registry dir, assume we're installing for the first
  # time.
  if (not -e $gRegistryDir) {
    SYSTEM("mkdir -p $gRegistryDir");
  }

  # Set the variable we've been called to set
  $gConfData{$name} = $val;

  # Write out a new conf file
  if (not open(INSTALLDB, ">$gRegistryFile")) {
    eprint("Unable to open the file for writing: $gRegistryFile\n");
  }
  foreach $key (keys %gConfData) {
    print INSTALLDB "$key = $gConfData{$key}\n";
    nprint("Writing $1 = $2\n") if $debug;
  }
  close(INSTALLDB);
}

# Checks to see if the Scalable Server is installed
# caches result after first lookup
BEGIN {
   my $isServer = undef;
   sub checkServer {
     return $isServer if (defined($isServer));

  if (`which rpm 2> /dev/null` eq "" ) {
       return($isServer = 0);
  }

  if (`rpm -qa | grep VMware-esx 2> /dev/null`) {
       return($isServer = 1);
  }

     return($isServer = 0);
   }
}


# See if we have enough room to install
sub checkDiskSpace {
  my @ret;
  my ($r, $diff);

  #
  # Set $LANGUAGE to C (standard Posix) when we execute df, because
  # we're relying on df's output being in English (this was bug 17040)
  # LANGUAGE is a GNU extension that is checked before other locale
  # environment variables.  Aside from that, the standard is to check
  # LC_ALL first --hpreg
  #
  $r = `(cd $gInstDir; export LANGUAGE=C; export LC_ALL=C; df .|grep -v 
^Filesystem)`;
  @ret = split(/[ \t\n]+/,$r);
  if ($ret[3] < $KSIZE) {
    $diff = $KSIZE - $ret[3];
    nprint ("--->  Not enough free space in $gInstDir <---\n");
    nprint ("You need roughly another $diff k bytes to install the 
$PRODUCTNAME image\n");
    eprint ("Please free up some disk space or install into a location with 
more free space.\n");
  }
}

# Stop the running services, if we can.
sub stopServices {
  nprint("Stopping any running $PRODUCTNAME processes.\n");
  if (-e "$gConfData{'mui.fullpath'}/apache/bin") {
    nprint("Stopping apache.\n");
    SYSTEM("cd $gConfData{'mui.fullpath'}/apache/bin && ./apachectl stop > 
/dev/null 2>&1");
  } else {
    # We can't find our apache directory - go on a bloody rampage and kill 
all
    # httpds running.
    nprint("Stopping all running httpd processes.\n");
    SYSTEM("killall -TERM httpd > /dev/null 2>&1");
    sleep (3);
    SYSTEM("killall -KILL httpd > /dev/null 2>&1");
  }
  SYSTEM("killall -TERM vmware-serverd > /dev/null 2>&1");
  sleep (3);
  SYSTEM("killall -KILL vmware-serverd > /dev/null 2>&1");
}

# Untar the image to the install area
sub unTarImage {
  my $tar;

  if (not -e $TARFILE) {
    nprint("Can't find the tar file: $TARFILE\n");
    eprint("Please run the installer from the \"$VMDISTRIB\" directory.\n");
  }

  # Find/use 'unzip'.
  chop($tar = `which tar`);
  if (!defined $tar) {
    eprint("Can't find the 'tar' utility on your machine.\n");
  }

  $tar .= " -C $gInstDir -xopf ";

  nprint("Starting to untar the image to $gInstDir\n");

  if (SYSTEM("$tar $TARFILE")) {
    nprint("\n'$tar' FAILS while trying to untar $TARFILE\n");
    eprint("Unable to continue...\n");
  }
  nprint("Finished untar.\n");
}

# Copy over the vmware-console images.
sub installConsolePackages {
  my $instDir = "$gInstDir/apache/htdocs/vmware/bin";

  if (not -e $CONSOLEDIR) {
    nprint("Can't find the directory: $CONSOLEDIR\n");
    eprint("Please run the installer from the \"$VMDISTRIB\" directory.\n");
  }

  SYSTEM("mkdir -p $instDir");
  SYSTEM("cp -p $CONSOLEDIR/* $instDir");
}

# Change our meta string to the install location
sub updateFiles {
  my $i;

  if (SYSTEM("mkdir -p $gTmpDir")) {
    eprint("Can't make temp directory: $gTmpDir\n");
  }

  foreach $i (@gModFiles) {
    my $file = "$gInstDir/$i";
    my $dir  = "$gTmpDir/$i";
    $dir =~ s#^(.*)/.*$#$1#;

    if (SYSTEM("mkdir -p $dir")) {
      eprint(" Can't make directory: $dir\n");
    }

    if (SYSTEM("sed -e s'#\@\@PREFIX\@\@#$gInstDir#g' " .
               "-e s'#\@\@HOSTNAME\@\@#$gHostname#g' " .
               "-e s'#\@\@PORT_OPTION\@\@#$gPortOption#g' " .
               "-e s'#\@\@DEFAULT_SSL\@\@#$gSSLByDefault#g' " .
               "$file > $gTmpDir/$i")) {
      SYSTEM("rm -rf $gTmpDir");
      eprint(" sed dies writing to $gTmpDir/$i \n");
    }

    if (SYSTEM("cp $gTmpDir/$i $file")) {
      SYSTEM("rm -rf $gTmpDir");
      eprint(" cp dies from $gTmpDir/$i to $file \n");
    }
  }
  SYSTEM("rm -rf $gTmpDir");

  # Install the uninstaller
  if (! -e $INSTALLER) {
    nprint("Can't find the installer/uninstaller file: $INSTALLER\n");
    eprint("Please run the installer from the \"$VMDISTRIB\" directory.\n");
  }
  SYSTEM("cp -p $INSTALLER $gInstDir/bin/$UNINSTALLER");
}

# Find the www/apache/web user & group
sub findNobody {
  my $pw    = "/etc/passwd";
  my $gf    = "/etc/group";
  my @ulist = ("nobody", "wwwrun", "nouser", "www-data", "www");
  my @glist = ("nobody", "nogroup", "www");
  my $user  = undef;
  my $group = undef;
  my $i;

  # Deal with USER
  foreach $i (@ulist) {
    $user = $i if (not SYSTEM("grep ^$i: $pw > /dev/null 2>&1"));
  }

  if (not defined $user) {
    nprint("The installer can't find a username that will run the web 
server.\n");
    nprint("Please enter one now.  Make sure to add this user to '$pw'.\n");
    nprint("Be aware the the $PRODUCTNAME web server won't start 
correctly\n");
    nprint("until you add this user to '$pw'.\n");
    $user = ask("nobody");
  }

  # Deal with GROUP
  foreach $i (@glist) {
    $group = $i if (not SYSTEM("grep ^$i: $gf > /dev/null 2>&1"));
  }

  if (not defined $group) {
    nprint("The installer can't find a group that will run the web 
server.\n");
    nprint("Please enter one now.  Make sure to add this group to $gf\n");
    nprint("Be aware the the $PRODUCTNAME web server won't start 
correctly\n");
    nprint("until you add this group to '$gf'.\n");
    $group = ask("nobody");
  }

  nprint "Configuring httpd.conf to run Apache as:\n";
  nprint "      User: '$user' and Group: '$group'\n\n";

  #
  #  Section to update our httpd.conf file
  #
  my $temp  = "$gTmpDir/httpd.conf";
  my $conf  = "$gInstDir/apache/conf/httpd.conf";

  # Update our httpd.conf with the results
  if (SYSTEM("mkdir -p $gTmpDir")) {
    eprint("Can't make temp directory: $gTmpDir\n");
  }

  if (SYSTEM("sed -e s'/^User.*\$/User $user/' $conf > $temp")) {
    SYSTEM("rm -rf $gTmpDir");
    eprint("Can't sed $conf into $temp\n");
  }
  if (SYSTEM("sed -e s'/^Group.*\$/Group $group/' $temp > $conf")) {
    SYSTEM("rm -rf $gTmpDir");
    eprint("Can't sed $temp into $conf\n");
  }
  SYSTEM("rm -rf $gTmpDir");
}


# Find an init dir update with our apache startup info.
sub updateInitdir {
  my $dir;
  my $initDir = "";
  my $initDirRoot = "";

  foreach $dir ("/usr/local/etc/rc.d", "/etc", "/sbin") {
    if ( -d "$dir/rc.d") {
      $initDirRoot = $dir;
      $initDir     = "$dir/rc.d";

      # Handle the SuSE 7.1 and beyond layout
      if (-d "$initDir/rc0.d"){
        $initDirRoot = $initDir;
      }
      last;
    }
  }

  if (not ( -d $initDir )) {
    nprint(" The installer is not able to find the directory where the 
'init' scripts reside.\n");
    nprint(" The directory should contain init.d/, and from rc0.d/ to rc6.d/ 
\n");
    nprint(" These directories are not in any of the standard 
locations:\n");
    nprint(" '/sbin/init.d', '/etc/rc.d/init.d', '/etc/init.d'\n, 'This have 
been changed by /usr/local/etc/rc.d'");
    nprint(" As a result, the $PRODUCTNAME Web Server will not 
automatically\n");
    nprint(" restart when this machine is rebooted.  You can start the 
$PRODUCTNAME\n");
    nprint(" Web Server after a reboot with this command (as root):\n");
    nprint("         $gInstDir/apache/bin/apachectl start\n\n");
    ask ("Press 'Enter' to continue.");
    return;
  }

  if (SYSTEM("mkdir -p $gTmpDir")) {
    eprint("Can't make temp directory: $gTmpDir\n");
  }


  if (SYSTEM("sed -e s'#\@\@PREFIX\@\@#$gInstDir#g' " .
             "-e s'#\@\@INITDIR\@\@#$initDir#g' " .
             "-e s'#\@\@PORT_OPTION\@\@#$gPortOption#g' " .
             "-e s'#\@\@DEFAULT_SSL\@\@#$gSSLByDefault#g' " .
             "$gInstDir/lib/httpd.vmware > $gTmpDir/httpd.vmware")) {
    SYSTEM("rm -rf $gTmpDir");
    eprint(" sed dies writing to $gTmpDir/httpd.vmware \n");
  }

  if (SYSTEM("cp $gTmpDir/httpd.vmware $initDir/httpd.vmware")) {
    SYSTEM("rm -rf $gTmpDir");
    eprint(" cp dies from $gTmpDir/httpd.vmware to $initDir/httpd.vmware 
\n");
  }

  my $i;
  foreach $i (keys %gRCLinks ) {
    my $j = $gRCLinks{$i};
    if (SYSTEM("ln -sf $initDir/$j $initDirRoot/$i")) {
      nprint(" Link fails:\n  ln -sf $initDir/$j $initDirRoot/$i\n\n");
    }
  }
  SYSTEM("rm -rf $gTmpDir");
  if (SYSTEM("chmod 755 $initDir/httpd.vmware")) {
    nprint(" chmod fails:\n  chmod 755 $initDir/httpd.vmware\n\n");
  }
updateConfig("mui.initd.fullpath", $initDir);
}

# Change permissions on the installed files so 'nobody' can deal with them.
sub updatePermissions {
  if (SYSTEM("chmod 755 $gInstDir")) {
    nprint(" chown fails:\n  chmod 755 $gInstDir\n\n");
  }

  # Not a good idea, but it'll be removed before FCS.
  if (SYSTEM("chown root $gInstDir/apache/htdocs/vmware/config/hstatus.pl")) 
{
    nprint(" chown fails:\n  chown root 
$gInstDir/apache/htdocs/vmware/config/hstatus.pl\n\n");
  }
  if (SYSTEM("chmod 4555 $gInstDir/apache/htdocs/vmware/config/hstatus.pl")) 
{
    nprint(" chmod fails:\n  chmod 4555 
$gInstDir/apache/htdocs/vmware/config/hstatus.pl\n\n");
  }
  if( checkServer() ) {
    if (SYSTEM("chmod 755 $gInstDir")) {
      nprint(" chmod fails:\n  chmod 755 $gInstDir\n\n");
    }
    if (SYSTEM("chmod 755 /etc/rc.d/init.d/httpd.vmware")) {
      nprint(" chmod fails:\n  chmod 755 
/etc/rd.d/init.d/httpd.vmware\n\n");
    }
  }
}

# Find an existing MUI installation to update ($UPDATER only)
sub findExistingInstall() {
  my $instDir;
  my $key;

  if (-e "$gRegistryDir") {
    # Populate our array with the data from the conf file.
    readConfig();
    $gInstDir = $gConfData{'mui.fullpath'};
  } elsif (checkServer()) {
    $gInstDir = $gServerInstDir;
  }

  # Query if we can't figure out where their old install is.
  if (not -e $gInstDir) {
    nprint("The installer can't find an existing installation of the 
$PRODUCTNAME.\n");
    if( !checkServer() )  {
      nprint("Please enter the directory where the $PRODUCTNAME is installed 
");
      $gInstDir = ask("");

      if (! -d $gInstDir) {
        eprint("The installer cannot find the directory you specified:\n" .
               "   $gInstDir\n" .
               "Please check the directory name and then re-run the 
installer.\n");
      }

      if (! -w $gInstDir) {
        eprint("The installer is not able to write to the directory you 
specified:\n" .
               "   $gInstDir\n" .
               "Please check file permissions and then re-run the 
installer.\n");
      }
      updateConfig("mui.fullpath", $gInstDir);
    } else {
      # Only one valid directory for server
      eprint("Cannot update the $PRODUCTNAME.\n");
    }
  }
}

# See if we've installed already and nuke it if found.
sub removeExistingInstall($) {
  my ($upgrade) = @_;
  my $instDir;
  my $key;

  if (-e "$gRegistryDir") {
    # Populate our array with the data from the conf file.
    readConfig();
    $gInstDir = $gConfData{'mui.fullpath'};

    # Warn them if we can't figure out where thier old install is.
    if (not -e $gInstDir) {
      nprint("You seem to have a previous installation of $PRODUCTNAME\n");
      nprint("but the installer can't find where it is.  You might want 
to\n");
      nprint("remove your old installation by hand.\n");
      return;
    }

    nprint("The directory $gInstDir  contains a previous\n");
    nprint("installation of $PRODUCTNAME.\n");

    stopServices();
    if (!$upgrade) {
      uninstallConfig();
    }
    uninstallAllFiles();
    return(1);
  }
    stopServices();
    return(0);
}

# Remove our files at a very high level
sub uninstallAllFiles {
  my $key;


  return(0) if (not readConfig());

  nprint("Removing the old installation....\n");
  # Remove our init.d symlinks and files
  foreach $key (keys %gRCLinks ) {
    SYSTEM("rm -f $gConfData{'mui.initd.fullpath'}/../$key");
    SYSTEM("rm -f $gConfData{'mui.initd.fullpath'}/$key");
    SYSTEM("rm -f $gConfData{'mui.initd.fullpath'}/$gRCLinks{$key}");
  }

  # Remove our MUI directories and files
  foreach $key (@gKillFiles) {
    SYSTEM("rm -rf $gConfData{'mui.fullpath'}/$key");
  }
  SYSTEM("rmdir $gConfData{'mui.fullpath'} > /dev/null 2>&1");

  # Remove secuity-config.pl
  SYSTEM("rm -f $gConfData{'security.fullpath'}");

  return(1);
}

sub uninstallConfig {
  if (!certSafeToDelete()) {
     nprint("The SSL certificate in $gRegistryDir doesn't appear to have 
been\n" .
            "generated by the $PRODUCTNAME.  Not deleting files in 
$gRegistryDir\n" .
            "as a precaution.\n");
  } else {
     SYSTEM("rm -rf $gRegistryDir");
  }
}

# Start our Apache server
sub startHttpd {
  my $libpath = $ENV{'LD_LIBRARY_PATH'};
  $libpath .= ":$gInstDir/lib";

  nprint("Starting web server.\n");
  if (SYSTEM("$gInstDir/apache/bin/apachectl start")) {
     nprint("WARNING:  Can't start the apache web server.\n");
  }
}

# Finito
sub showInstallDone {

  nprint ("\nThe $PRODUCTNAME has been successfully installed.\n");
  nprint ("To use the $PRODUCTNAME setup tools, point your browser to:\n");


  if( checkServer() ) {
    nprint ("    http://$gHostname/vmware/config\n\n");
  } else {
    nprint ("    http://$gHostname:$gPort/login\n\n");
  }
  nprint ("\nTo un-install the $PRODUCTNAME, please run:\n");
  nprint ("    $gInstDir/bin/$UNINSTALLER\n\n");
}

sub showUpdateDone {
  nprint ("\nThe $PRODUCTNAME has been successfully updated.\n");
}

sub showUninstallDone {
  nprint ("\nThe $PRODUCTNAME has been successfully uninstalled.\n");
}

sub showNoUninstallDone {
  nprint ("\nThe $PRODUCTNAME was not found on this system.\n");
  nprint ("No action taken.\n");
}


#
# check to see if the certificate files exist (and
# that they appear to be a valid certificate).
#
sub certificateExists() {
   return ((-e "$gCertLoc/mui.crt") &&
           (-e "$gCertLoc/mui.key") &&
           !(SYSTEM("$gInstDir/bin/openssl x509 -in $gCertLoc/mui.crt " .
                    " -noout -subject > /dev/null 2>&1")));
}

#
# check to see if this is a certificate that was generated
# by this script (or the mui).  If so, then it is safe to delete
# it. (don't want to accidently blow away an expensive certificate).
#
sub certSafeToDelete() {
   local *F;
   if (not open(F, "$gInstDir/bin/openssl x509 -in $gCertLoc/mui.crt " .
                         " -noout -subject" . '|')) {
      return 1;
   }

   while (<F>) {
     if (m/$gCertUniqIdent/) {
        return 1;
     }
   }
   close (F);

   #Certificate didn't have our uniq identifier, so don't delete it.
   return 0;
}

sub createSSLCertificates(){
   my $certCnf = "$gTmpDir/certificate.cnf";
   my $curTime = time();

   if (certificateExists()) {
      nprint("Using Existing SSL Certificate.\n");
      return;
   }

   if (SYSTEM("mkdir -p $gTmpDir")) {
     eprint("Can't make temp directory: $gTmpDir\n" .
             "Unable to create SSL certificate. " .
             "You must run 'security-config.pl -n' by hand\n");
   }

   if (not open(CONF, '>' . $certCnf)) {
      eprint("Couldn't open $certCnf.\n" .
             "Unable to create SSL certificate. " .
             "You must run 'security-config.pl -n' by hand\n");
   }
   print CONF <<EOF;
# Conf file that the management-ui will use to generate SSL certificates.

[ req ]
default_bits		= 1024
default_keyfile 	= mui.key
distinguished_name	= req_distinguished_name

#Don't encrypt the key
encrypt_key             = no
prompt                  = no

string_mask = nombstr

[ req_distinguished_name ]
countryName= US
stateOrProvinceName     = California

localityName            = Palo Alto

0.organizationName      = VMware, Inc.

organizationalUnitName  = VMware Management Interface

commonName              = $gHostname

unstructuredName        = ($curTime),$gCertUniqIdent

emailAddress            = ssl-certificates\@vmware.com
EOF
   close(CONF);

   nprint("Generating SSL Server Certificate\n");
   SYSTEM("mkdir -p $gCertLoc");
   my $curMask = umask(0077);
   SYSTEM("$gInstDir/bin/openssl req -new -x509 -keyout $gCertLoc/mui.key 
-out " .
          "$gCertLoc/mui.crt -config $certCnf -days 5000 > /dev/null 2>&1");
   umask($curMask);

   SYSTEM("rm -rf $gTmpDir");

   #make key readable only by root (important)
   SYSTEM("chmod 400 $gCertLoc/mui.key");

   #let anyone read the certificate
   SYSTEM("chmod 444 $gCertLoc/mui.crt");
}

# XXX: Basically a hack for RH 8.0 since it doesnt have a package that
# is needed for httpd (libdb.so.3) installed by default.
sub checkVersions {
  # If it doesnt work, we will ignore the error and hope for the best
  # since we dont want to muck any working system with ldd not available
  if (open(LDDIN, "ldd $gInstDir/apache/bin/httpd |")) {
    while (<LDDIN>) {
      if (/libdb\.so\.3\s*=>\s*not found/) {
        # Uhoh
        nprint("\n");
        nprint("Couldn't " . 'find necessary components on your system. ');
        nprint('It appears that you are missing the following library: '
               . 'libdb.so.3' . "\n\n");
        nprint('New versions of Red Hat Linux (8.0+) are known to ship 
without these'
               . ' libraries. If you are running Red Hat 8.0 or greater, 
please'
               . ' install this rpm: ' . 'compat-db-3.3-<###> rpm (where 
<###> is a '
               . ' version number particular to your version of the 
distribution)'
               . ' from your installation CD' . "\n\n");
        nprint('If you are running a distribution other than Red Hat, 
please'
               . ' contact your vendor for a suitable library. Once the '
               . ' package has been installed, you may start the '
              . $PRODUCTNAME . ' with the following command:' . "\n");
        nprint("$gInstDir/apache/bin/apachectl start\n");
        exit(-1);
      }
    }
    close(LDDIN);
  }
}

# Main
sub main {

  if (not is_root()) {
    eprint("Please re-run this script as the super user.\n\n");
  }

  # Where/who are we?
  if ($0 =~ m#/#) {
    $0 =~ m#^(.*)/(.*)$#;
    ($gStartDir, $gProgName) = ($1, $2);
  } else {
    ($gStartDir, $gProgName) = (undef, $0);
  }

  if ($gProgName eq $INSTALLER) {
    if ($#ARGV > -1) {
      instUsage();
    }
    showWelcome();
#    showEULA();
    removeExistingInstall(1);
    initializeGlobals();
    getInstallDir();
    checkDiskSpace();
    unTarImage();
    updateFiles();
    findNobody();
    updateInitdir();
    updatePermissions();
    createSSLCertificates();
    installConsolePackages();
    checkVersions();
    startHttpd();

    showInstallDone();
    exit(0);
  }

  if ($gProgName eq $UPDATER) {
    if ($#ARGV > -1) {
      updateUsage();
    }
    showUpWelcome();
    findExistingInstall();
    stopServices();
    unTarImage();
    startHttpd();

    showUpdateDone();
    exit(0);
  }

  if ($gProgName eq $UNINSTALLER) {
    if ($#ARGV > -1) {
      uninstUsage();
    }

    showUnWelcome();

    if (removeExistingInstall(0)) {
      showUninstallDone();
    } else {
      showNoUninstallDone();
    }
    exit(0);
  }

  eprint("This script must be named $INSTALLER or $UNINSTALLER.\n\n");
  exit(0);
}

main();





More information about the freebsd-questions mailing list