\n"; echo "
  • Searching for the xCAT Web Interface download site...
  • \n"; $site = findSite(); echo "
  • Selected site ${site['dir']}. Searching for the $rpmname RPM...
  • \n"; $pkg = findPkg($site['dir'], $rpmname); if (!$pkg) { echo "

    Can not find $rpmname in ${site['dir']}.

    \n"; return; } echo "
  • Latest RPM version available is $pkg.
  • \n"; if (isInstalled($pkg)) { echo "
  • $pkg (or higher) is already installed.
  • \n"; return; } echo "
  • Downloading $pkg ...
  • \n"; if (!downloadPkg($site['download'], $pkg, $tmpdir)) { echo "

    Error downloading $pkg from ${site['download']}.

    \n"; return; } echo "
  • Download complete. Installing $pkg ...
  • \n"; $rc = installPkg("$tmpdir/$pkg"); if ($rc) { echo "

    Installation of $pkg failed with rc=$rc.

    \n"; } echo "
  • Installation of $pkg completed successfully.
  • \n"; echo "\n"; //dumpGlobals(); //runcmd('/WINDOWS/system32/ipconfig', 1); } // Install the specified rpm function installPkg($pkgname) { //------------------------------------ $aixrpmopt = isAIX() ? '--ignoreos' : ''; $rc = runcmd("/bin/rpm -U $aixrpmopt $pkgname", 1); return $rc; } // Download the specified rpm from the specified url and put it in the specified dir function downloadPkg($url, $rpmname, $tmpdir) { //------------------------------------ //trace("copy($url/$rpmname, $tmpdir/$rpmname)"); $result = copy("$url/$rpmname", "$tmpdir/$rpmname"); return $result; } // At the chosen site, find the latest version of xcat.web function findPkg($url, $rpmname) { //------------------------------------ //trace("file($url)"); $html = file($url); if (!$html) { return NULL; } //foreach ($html as $line) { if (preg_match('/xcat.web/',$line)) { trace($line); } } $matches = preg_grep('/href=.*' . $rpmname . '-.*?\.rpm/i', $html); if (!count($matches)) { return NULL; } foreach ($matches as &$line) { $pattern = '/' . $rpmname . '-.*?\.rpm/i'; //trace($pattern); //$line = preg_replace($pattern, '$1', $line); preg_match($pattern, $line, $m); $line = $m[0]; //trace($line); } usort($matches, 'byversion'); //foreach ($matches as $l) { trace($l); } return $matches[0]; } # Parse out the version and release numbers of the 2 rpm file names and sort in descending order # This sort function should be used like: usort($rpms, 'byversion'); # Makes the following assumptions: # - the version and release are single digits separated by dots (e.g. 1.2.3) - so we can compare it as a string # - the release has at most 1 dot in it - so we can compare it as a float function byversion($a, $b) { //------------------------------------ $pat = '/-([0-9.]+)-([0-9.]+)\.\D/'; preg_match($pat, $a, $a_matches); preg_match($pat, $b, $b_matches); $result = strcmp($a_matches[1], $b_matches[1]); if ($result) { return $result * -1; } // they were not equal, so return result if ($a_matches[2] == $b_matches[2]) { return 0; } return ($a_matches[2] < $b_matches[2]) ? 1 : -1; } // Choose whether to use the PPD lab server, the general internal IBM server, or the external server. function findSite() { //------------------------------------ $internalSitePok = 'rs6000.pok.ibm.com'; $internalDir = '/afs/apd/u/bp/xcat/'; $internalURLPok = "http://$internalSitePok$internalDir"; $internalURLDirPok = "http://$internalSitePok$internalDir"; $internalSite = 'www.pok.ibm.com'; $internalURL = "http://$internalSite$internalDir"; $internalURLDir = "http://$internalSite$internalDir"; $externalURL = "ftp://ftp.software.ibm.com/eserver/pseries/cluster/csm/fixes"; //todo: change these $externalURLDir = "http://www14.software.ibm.com/webapp/set2/sas/f/csm/utilities/xCSMfixhome.html"; # 1st try rs6000.pok.ibm.com if we are inside the BSO firewall $hostname = resolveHost($_SERVER["SERVER_NAME"]); //$hostname = resolveHost('9.56.216.79'); //trace("Local hostname: $hostname"); if (preg_match('/ppd\.pok\.ibm\.com$/', $hostname)) { return array ('dir'=>$internalURLDirPok, 'download'=>$internalURLPok); } // Try pinging the IBM internal site $cntflag = isWindows() ? '-n' : '-c'; $rc = runcmd("/bin/ping -w 4 $cntflag 1 $internalSite", 2, $out); //trace("rc=$rc"); if ($rc == 0) { return array ('dir'=>$internalURLDir, 'download'=>$internalURL); } // Fall back to external site return array ('dir'=>$externalURLDir, 'download'=>$externalURL); } ?>