From 6bfd09b99e0f01711fcdf7aa11fbe016dca4aaba Mon Sep 17 00:00:00 2001 From: Michael Larabel Date: Fri, 25 Apr 2008 13:57:09 -0400 Subject: Add new advanced features to downloads.xml process like trying from different mirror if checksum failed, etc. --- TODO | 1 - pts-core/functions/pts-functions-install.php | 69 +++++++++++++++++++++++++--- 2 files changed, 62 insertions(+), 8 deletions(-) diff --git a/TODO b/TODO index 40d4b5a..d13ee6d 100644 --- a/TODO +++ b/TODO @@ -9,4 +9,3 @@ - More MD5 checks in test scripts - Change locking system away from time-based but to PID based - Clean up tests scripts -- To downloads.xml, try another mirror (if available) when MD5 sum fails or ask user if they want to quit or attempt to continue diff --git a/pts-core/functions/pts-functions-install.php b/pts-core/functions/pts-functions-install.php index 4e56909..2caf2d2 100644 --- a/pts-core/functions/pts-functions-install.php +++ b/pts-core/functions/pts-functions-install.php @@ -74,6 +74,7 @@ function pts_install_benchmark($Benchmark) $package_url = $xml_parser->getXMLArrayValues("PhoronixTestSuite/Downloads/Package/URL"); $package_md5 = $xml_parser->getXMLArrayValues("PhoronixTestSuite/Downloads/Package/MD5"); $package_filename = $xml_parser->getXMLArrayValues("PhoronixTestSuite/Downloads/Package/FileName"); + $header_displayed = false; for($i = 0; $i < count($package_url); $i++) { @@ -84,17 +85,71 @@ function pts_install_benchmark($Benchmark) if(!is_file(BENCHMARK_ENV_DIR . $Benchmark . "/" . $package_filename[$i])) { + if(!$header_displayed) + { + echo pts_string_header("Downloading Files For: " . $Benchmark); + $header_displayed = true; + } + $urls = explode(",", $package_url[$i]); - $url = trim($urls[rand(0, count($urls) - 1)]); - echo "\nDownloading File: " . $package_filename[$i] . "\n"; - echo shell_exec("cd " . BENCHMARK_ENV_DIR . $Benchmark . "/" . " && wget " . $url . " -O " . $package_filename[$i]); + if(count($urls) > 1) + shuffle($urls); + $fail_count = 0; + $try_again = true; - if(is_file(BENCHMARK_ENV_DIR . $Benchmark . "/" . $package_filename[$i]) && !empty($package_md5[$i]) && md5_file(BENCHMARK_ENV_DIR . $Benchmark . "/" . $package_filename[$i]) != $package_md5[$i]) + if(count($urls) > 0) { - echo "\nMD5 sums don't match! Removing File!\n"; - unlink(BENCHMARK_ENV_DIR . $Benchmark . "/" . $package_filename[$i]); + do + { + echo $url = trim(array_pop($urls)); + + echo "\nDownloading File: " . $package_filename[$i] . "\n"; + echo shell_exec("cd " . BENCHMARK_ENV_DIR . $Benchmark . "/" . " && wget " . $url . " -O " . $package_filename[$i]); + + + if((is_file(BENCHMARK_ENV_DIR . $Benchmark . "/" . $package_filename[$i]) && !empty($package_md5[$i]) && md5_file(BENCHMARK_ENV_DIR . $Benchmark . "/" . $package_filename[$i]) != $package_md5[$i]) || !is_file(BENCHMARK_ENV_DIR . $Benchmark . "/" . $package_filename[$i])) + { + unlink(BENCHMARK_ENV_DIR . $Benchmark . "/" . $package_filename[$i]); + $file_downloaded = false; + $fail_count++; + echo "\nThe MD5 check-sum of the downloaded file is incorrect.\n"; + + if($fail_count > 3) + { + $try_again = false; + } + else + { + if(count($urls) > 0) + { + echo "Attempting to re-download from another mirror...\n"; + } + else + { + $try_again = pts_bool_question("Would you like to try downloading the file again (Y/n)?", true, "TRY_DOWNLOAD_AGAIN"); + + if($try_again) + array_push($urls, $url); + else + $try_again = false; + } + } + } + else + { + $file_downloaded = true; + $fail_count = 0; + } + + if(!$try_again) + { + echo "\nDownload of Needed Test Dependencies Failed! Exiting...\n\n"; + exit(0); + } + + }while(!$file_downloaded); } } } @@ -102,7 +157,7 @@ function pts_install_benchmark($Benchmark) if(is_file(BENCHMARK_RESOURCE_DIR . "$Benchmark/install.sh") || is_file(BENCHMARK_RESOURCE_DIR . "$Benchmark/install.php")) { - echo pts_string_header("Installing Benchmark:" . $Benchmark); + echo pts_string_header("Installing Benchmark: " . $Benchmark); if(is_file(BENCHMARK_RESOURCE_DIR . "$Benchmark/install.sh")) { -- cgit