diff --git a/upgrade.php b/upgrade.php index dc03797954..2fd1c45426 100644 --- a/upgrade.php +++ b/upgrade.php @@ -1,38 +1,45 @@ 1){ + for ($arg=1; $arg<$argc; $arg++){ + switch ($argv[$arg]) { + case '--skip-php-compatibility-checks': + $skip_php_checks = true; + break; + case '--branch': + $arg++; + $branch = $argv[$arg]; + $branch_override = true; + break; + default: // for legacy support from before we started using --branch + $branch = $argv[$arg]; + $branch_override = true; + break; + } + } } -$php_min_works = $upgrade_requirements['php_min_version']; -$php_max_wontwork = $upgrade_requirements['php_max_wontwork']; -// done fetching requirements - - -if ((strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') || (!function_exists('posix_getpwuid'))) { - echo "Skipping user check as it is not supported on Windows or Posix is not installed on this server. \n"; -} else { - $pwu_data = posix_getpwuid(posix_geteuid()); - $username = $pwu_data['name']; - - if (($username=='root') || ($username=='admin')) { - die("\nERROR: This script should not be run as root/admin. Exiting.\n\n"); - } -} - - echo "--------------------------------------------------------\n"; echo "WELCOME TO THE SNIPE-IT UPGRADER! \n"; echo "--------------------------------------------------------\n\n"; @@ -46,6 +53,55 @@ echo "- run migrations to get your schema up to date \n"; echo "- clear out old cache settings\n\n"; +// Fetching most current upgrade requirements from github. Read more here: https://github.com/snipe/snipe-it/pull/14127 +$remote_requirements_file = "https://raw.githubusercontent.com/snipe/snipe-it/$branch/.upgrade_requirements.json"; +$upgrade_requirements = json_decode(url_get_contents($remote_requirements_file), true); + +if (! $upgrade_requirements) { + if(!$skip_php_checks){ + echo "\nERROR: Failed to retrieve remote requirements from $remote_requirements_file\n\n"; + if ($branch_override){ + echo "NOTE: You passed a custom branch: $branch\n"; + echo " If the above URL doesn't work, that may be why. Please check you branch spelling/extistance\n\n"; + } + echo "We suggest correcting this, but if you can't, please verify that your requirements conform to those at that url.\n\n"; + echo " -- DANGER -- DO AT YOUR OWN RISK --\n"; + echo " IF YOU ARE SURE, re-run this script with --skip-php-compatibility-checks to skip this check.\n"; + echo " -- DANGER -- THIS COULD BREAK YOUR INSTALLATION"; + die("Exiting.\n\n"); + } + echo "NOTICE: Unable to fetch upgrade requirements, but continuing because you passed --skip-php-compatibility-checks...\n"; +} + +echo "Launching using branch: $branch\n"; + +if($upgrade_requirements){ + $php_min_works = $upgrade_requirements['php_min_version']; + $php_max_wontwork = $upgrade_requirements['php_max_wontwork']; + echo "Found PHP requirements, will check for PHP > $php_min_works and < $php_max_wontwork\n"; +} +// done fetching requirements +$yesno = readline("\nProceed with upgrade? [Y/n]: "); +if ($yesno == "yes" || $yesno == "YES" ||$yesno == "y" ||$yesno == "Y"){ + # don't do anything +} else { + die("Exiting.\n\n"); +} + +echo "\n"; + +if ((strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') || (!function_exists('posix_getpwuid'))) { + echo "Skipping user check as it is not supported on Windows or Posix is not installed on this server. \n"; +} else { + $pwu_data = posix_getpwuid(posix_geteuid()); + $username = $pwu_data['name']; + + if (($username=='root') || ($username=='admin')) { + die("\nERROR: This script should not be run as root/admin. Exiting.\n\n"); + } +} + + echo "--------------------------------------------------------\n"; echo "STEP 1: Checking .env file: \n"; @@ -153,24 +209,25 @@ if ($env_bad !='') { } -echo "\n--------------------------------------------------------\n"; -echo "STEP 2: Checking PHP requirements: (Required PHP >=". $php_min_works. " - <".$php_max_wontwork.") \n"; -echo "--------------------------------------------------------\n\n"; +if(!$skip_php_checks){ + echo "\n--------------------------------------------------------\n"; + echo "STEP 2: Checking PHP requirements: (Required PHP >=". $php_min_works. " - <".$php_max_wontwork.") \n"; + echo "--------------------------------------------------------\n\n"; -if ((version_compare(phpversion(), $php_min_works, '>=')) && (version_compare(phpversion(), $php_max_wontwork, '<'))) { + if ((version_compare(phpversion(), $php_min_works, '>=')) && (version_compare(phpversion(), $php_max_wontwork, '<'))) { - echo "√ Current PHP version: (" . phpversion() . ") is at least " . $php_min_works . " and less than ".$php_max_wontwork."! Continuing... \n"; - echo sprintf("FYI: The php.ini used by this PHP is: %s\n\n", get_cfg_var('cfg_file_path')); + echo "√ Current PHP version: (" . phpversion() . ") is at least " . $php_min_works . " and less than ".$php_max_wontwork."! Continuing... \n"; + echo sprintf("FYI: The php.ini used by this PHP is: %s\n\n", get_cfg_var('cfg_file_path')); -} else { - echo "!!!!!!!!!!!!!!!!!!!!!!!!! PHP VERSION ERROR !!!!!!!!!!!!!!!!!!!!!!!!!\n"; - echo "This version of PHP (".phpversion().") is NOT compatible with Snipe-IT.\n"; - echo "Snipe-IT requires PHP versions between ".$php_min_works." and ".$php_max_wontwork.".\n"; - echo "Please install a compatible version of PHP and re-run this script again. \n"; - echo "!!!!!!!!!!!!!!!!!!!!!!!!! ABORTING THE UPGRADER !!!!!!!!!!!!!!!!!!!!!!\n"; - exit(1); + } else { + echo "!!!!!!!!!!!!!!!!!!!!!!!!! PHP VERSION ERROR !!!!!!!!!!!!!!!!!!!!!!!!!\n"; + echo "This version of PHP (".phpversion().") is NOT compatible with Snipe-IT.\n"; + echo "Snipe-IT requires PHP versions between ".$php_min_works." and ".$php_max_wontwork.".\n"; + echo "Please install a compatible version of PHP and re-run this script again. \n"; + echo "!!!!!!!!!!!!!!!!!!!!!!!!! ABORTING THE UPGRADER !!!!!!!!!!!!!!!!!!!!!!\n"; + exit(1); + } } - echo "Checking Required PHP extensions... \n\n"; // Get the list of installed extensions @@ -319,14 +376,22 @@ if ($dirs_not_writable!='') { echo "--------------------------------------------------------\n"; echo "STEP 4: Backing up database: \n"; echo "--------------------------------------------------------\n\n"; -$backup = shell_exec('php artisan snipeit:backup'); -echo '-- '.$backup."\n\n"; +$backup = exec('php artisan snipeit:backup', $backup_results, $return_code); +echo '-- ' . implode("\n", $backup_results) . "\n\n"; +if ($return_code > 0) { + die("Something went wrong with your backup. Aborting!\n\n"); +} +unset($return_code); echo "--------------------------------------------------------\n"; echo "STEP 5: Putting application into maintenance mode: \n"; echo "--------------------------------------------------------\n\n"; -$down = shell_exec('php artisan down'); -echo '-- '.$down."\n"; +exec('php artisan down', $down_results, $return_code); +echo '-- ' . implode("\n", $down_results) . "\n"; +if ($return_code > 0) { + die("Something went wrong with downing you site. This can't be good. Please investigate the error. Aborting!n\n"); +} +unset($return_code); echo "--------------------------------------------------------\n";