MOON
Server: Apache/2.2.31 (Unix) mod_ssl/2.2.31 OpenSSL/0.9.8e-fips-rhel5 mod_bwlimited/1.4
System: Linux csr818.wilogic.com 2.6.18-419.el5xen #1 SMP Fri Feb 24 22:50:37 UTC 2017 x86_64
User: digitals (531)
PHP: 5.4.45
Disabled: NONE
Upload Files
File: //scripts.20110531.215904.25158/bsdi386compatinstall
#!/usr/bin/perl
# cpanel - bsdi386compatinstall                   Copyright(c) 2010 cPanel, Inc.
#                                                           All rights Reserved.
# copyright@cpanel.net                                         http://cpanel.net
# This code is subject to the cPanel license. Unauthorized copying is prohibited

BEGIN { unshift @INC, '/usr/local/cpanel', '/scripts'; }

use Digest::MD5;
use cPanelBSDPKGS;
use Cpanel::OSSys ();
my($sysname, $nodename, $release, $version, $machine) = Cpanel::OSSys::uname();

if ($sysname !~ /freebsd/i || $machine !~ /64/) { exit(); }

if (-e '/compat/ia32/usr/lib/compat/libc_r.so.4' || -e '/compat/ia32/usr/lib/libc_r.so') {
	exit();
}

my @GOODURLS;
if ($#SYSMIRRORLIST > -1) {
   @GOODURLS = @SYSMIRRORLIST;
} else {
   @GOODURLS = cPanelBSDPKGS::getmirrorlist();
   @SYSMIRRORLIST = @GOODURLS;
}



mkdir("/usr/home/i386-compat-install",0700);
mkdir("/compat/ia32",0755);

my(@PKGS) = ("base","compat4x");

foreach my $pkg (@PKGS) {
   mkdir("/usr/home/i386-compat-install/${pkg}",0700);
   getfile($pkg,"CHECKSUM.MD5");
   open(BASE,"/usr/home/i386-compat-install/${pkg}/CHECKSUM.MD5");
   while(<BASE>) {
      /\S+\s*\(([^\)]+)\)\s*=\s*(\S+)/;
      my $file = $1;
      my $md5 = $2;
      if (!checkdigest($pkg,$file,$md5)) {
         unlink("/usr/home/i386-compat-install/${pkg}/${file}");
         getfile($pkg,$file);
      }
      if (!checkdigest($pkg,$file,$md5)) {
         getfile($pkg,$file);
      }
      if (!checkdigest($pkg,$file,$md5)) {
         die "${file}: md5 check failed!";
      } else {
         print "${file}: md5 check passed!\n";
      }
   }
   close(BASE);

   chdir("/usr/home/i386-compat-install/${pkg}");
   chmod(0700,"install.sh");
   $ENV{'DESTDIR'} = '/compat/ia32';
   open(INS,"|./install.sh");
   print INS "y\n";
   close(INS);

}
print "Fixing symlinks...";
my @links = split(/\n/,`find /compat/ia32/ -type l`);
foreach my $link (@links) {
   my $target = readlink($link);
   if ($target =~ /^\// && $target !~ /^\/compat\/ia32/) {
      $target = "/compat/ia32" . $target;
      unlink($link);
      symlink($target,$link);
      print ".";
   }
}
print "Done\n";
system("/scripts/bsdldconfig");

sub getfile {
   my($pkg,$file) = @_;
   foreach my $pkghost (@GOODURLS) {
      if ((stat("/usr/home/i386-compat-install/${pkg}/${file}"))[7] > 0) {
         last;
      }
      system("fetch","-o","/usr/home/i386-compat-install/${pkg}/${file}","${pkghost}/pub/FreeBSD/releases/i386/${release}/${pkg}/${file}");
      if ((stat("/usr/home/i386-compat-install/${pkg}/${file}"))[7] > 0) {
         last;
      }
   }
}


sub checkdigest {
   my($pkg,$file,$md5) = @_;
   if (! -e "/usr/home/i386-compat-install/${pkg}/${file}") { return(0); }
   my $ctx = Digest::MD5->new;
   open(FILE,"/usr/home/i386-compat-install/${pkg}/${file}");
   $ctx->addfile(\*FILE);
   close(FILE);
   my $digest = $ctx->hexdigest;
   if ($digest eq $md5) {
      return(1);
   } else {
      return(0);
   }
}