diff --git a/upgrade.php b/upgrade.php index 705624a91..92d75f3a2 100644 --- a/upgrade.php +++ b/upgrade.php @@ -1,7 +1,7 @@ $line) { + + if ((strlen($line) > 1) && (strpos($line, "#") !== 0)) { + + list ($env_key, $env_value) = $env_line = explode('=', $line); + + // The array starts at 0 + $show_line_num = $line_num+1; + + $env_value = trim($env_value); + + if ($env_key == 'APP_KEY') { + if (($env_value=='') || (strlen($env_value) < 20)) { + $env_bad .= "✘ APP_KEY ERROR in your .env on line #'.$show_line_num.': Your APP_KEY should not be blank. Run `php artisan key:generate` to generate one.\n"; + } else { + $env_good .= "√ Your APP_KEY is not blank. \n"; + } + } + + if ($env_key == 'APP_URL') { + + $app_url_length = strlen($env_value); + + if (($env_value!="null") && ($env_value!="")) { + $env_good .= '√ Your APP_URL is not null or blank. It is set to '.$env_value."\n"; + + if (!str_begins(trim($env_value), 'http://') && (!str_begins($env_value, 'https://'))) { + $env_bad .= '✘ APP_URL ERROR in your .env on line #'.$show_line_num.': Your APP_URL should start with https:// or http://!! It is currently set to: '.$env_value; + } else { + $env_good .= '√ Your APP_URL is set to '.$env_value.' and starts with the protocol (https:// or http://)'."\n"; + } + + if (str_ends(trim($env_value), "/")) { + $env_bad .= '✘ APP_URL ERROR in your .env on line #'.$show_line_num.': Your APP_URL should NOT end with a trailing slash. It is currently set to: '.$env_value; + } else { + $env_good .= '√ Your APP_URL ('.$env_value.') does not have a trailing slash.'."\n"; + } + + + } else { + $env_bad .= "✘ APP_URL ERROR in your .env on line #".$show_line_num.": Your APP_URL CANNOT be set to null or left blank.\n"; + } + + } + + + } + +} + +echo $env_good; + +if ($env_bad !='') { + + echo "\n--------------------- !! ERROR !! ----------------------\n"; + echo "Your .env file is misconfigured. Upgrade cannot continue.\n"; + echo "--------------------------------------------------------\n\n"; + echo $env_bad; + echo "\n\n--------------------------------------------------------\n"; + echo "ABORTING THE INSTALLER \n"; + echo "Please correct the issues above in ".getcwd()."/.env and try again.\n"; + echo "--------------------------------------------------------\n"; + exit; +} + + +echo "--------------------------------------------------------\n"; +echo "STEP 2: Checking PHP requirements: \n"; +echo "--------------------------------------------------------\n\n"; + +if (version_compare(PHP_VERSION, $required_php_min, '<')) { echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ERROR !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"; echo "This version of PHP (".PHP_VERSION.") is not compatible with Snipe-IT.\n"; - echo "Snipe-IT requires PHP version ".$required_version." or greater. Please upgrade \n"; + echo "Snipe-IT requires PHP version ".$required_php_min." or greater. Please upgrade \n"; echo "your version of PHP (web/php-fcgi and cli) and try running this script again.\n\n\n"; exit; } else { - echo "Current PHP version: (" . PHP_VERSION . ") is at least ".$required_version." - continuing... \n"; + echo "Current PHP version: (" . PHP_VERSION . ") is at least ".$required_php_min." - continuing... \n"; echo sprintf("FYI: The php.ini used by this PHP is: %s\n\n", get_cfg_var('cfg_file_path')); } @@ -121,10 +205,10 @@ if ($ext_missing!='') { echo "--------------------- !! ERROR !! ----------------------\n"; echo $ext_missing; - echo "------------------------- :( ---------------------------\n"; + echo "--------------------------------------------------------\n"; echo "ABORTING THE INSTALLER \n"; echo "Please install the extensions above and re-run this script.\n"; - echo "------------------------- :( ---------------------------\n"; + echo "--------------------------------------------------------\n"; exit; } else { echo $ext_installed."\n"; @@ -132,21 +216,73 @@ if ($ext_missing!='') { } + echo "--------------------------------------------------------\n"; -echo "STEP 2: Backing up database: \n"; +echo "STEP 3: Checking directory permissions: \n"; +echo "--------------------------------------------------------\n\n"; + + +$writable_dirs_array = + [ + 'bootstrap/cache', + 'storage', + 'storage/logs', + 'storage/logs/laravel.log', + 'storage/framework', + 'storage/framework/cache', + 'storage/framework/sessions', + 'storage/framework/views', + 'storage/app', + 'storage/app/backups', + 'storage/app/backup-temp', + 'storage/private_uploads', + 'public/uploads', + ]; + +$dirs_writable = ''; +$dirs_not_writable = ''; + +// Loop through the directories that need to be writable +foreach ($writable_dirs_array as $writable_dir) { + if (is_writable($writable_dir)) { + $dirs_writable .= '√ '.getcwd().'/'.$writable_dir." is writable \n"; + } else { + $dirs_not_writable .= '✘ PERMISSIONS ERROR: '.getcwd().'/'.$writable_dir." is NOT writable\n"; + } +} + +echo $dirs_writable."\n"; + +// Print out a useful error message +if ($dirs_not_writable!='') { + echo "--------------------------------------------------------\n"; + echo "The following directories/files do not seem writable: \n"; + echo "--------------------------------------------------------\n"; + + echo $dirs_not_writable; + + echo "--------------------- !! ERROR !! ----------------------\n"; + echo "Please check the permissions on the directories above and re-run this script.\n"; + echo "------------------------- :( ---------------------------\n\n"; +} + + + +echo "--------------------------------------------------------\n"; +echo "STEP 4: Backing up database: \n"; echo "--------------------------------------------------------\n\n"; $backup = shell_exec('php artisan snipeit:backup'); echo '-- '.$backup."\n\n"; echo "--------------------------------------------------------\n"; -echo "STEP 3: Putting application into maintenance mode: \n"; +echo "STEP 5: Putting application into maintenance mode: \n"; echo "--------------------------------------------------------\n\n"; $down = shell_exec('php artisan down'); echo '-- '.$down."\n"; echo "--------------------------------------------------------\n"; -echo "STEP 4: Pulling latest from Git (".$branch." branch): \n"; +echo "STEP 6: Pulling latest from Git (".$branch." branch): \n"; echo "--------------------------------------------------------\n\n"; $git_version = shell_exec('git --version'); @@ -172,7 +308,7 @@ if ((strpos('git version', $git_version)) === false) { echo "--------------------------------------------------------\n"; -echo "Step 5: Cleaning up old cached files:\n"; +echo "STEP 7: Cleaning up old cached files:\n"; echo "--------------------------------------------------------\n\n"; // Build an array of the files we generally want to delete because they @@ -205,7 +341,7 @@ echo '-- '.$view_clear; echo "\n"; echo "--------------------------------------------------------\n"; -echo "Step 6: Updating composer dependencies:\n"; +echo "STEP 8: Updating composer dependencies:\n"; echo "(This may take a moment.)\n"; echo "--------------------------------------------------------\n\n"; @@ -231,7 +367,7 @@ echo $composer; echo "--------------------------------------------------------\n"; -echo "Step 7: Migrating database:\n"; +echo "STEP 9: Migrating database:\n"; echo "--------------------------------------------------------\n\n"; $migrations = shell_exec('php artisan migrate --force'); @@ -239,7 +375,7 @@ echo $migrations."\n"; echo "--------------------------------------------------------\n"; -echo "Step 8: Checking for OAuth keys:\n"; +echo "STEP 10: Checking for OAuth keys:\n"; echo "--------------------------------------------------------\n\n"; @@ -253,7 +389,7 @@ if ((!file_exists('storage/oauth-public.key')) || (!file_exists('storage/oauth-p echo "--------------------------------------------------------\n"; -echo "Step 9: Taking application out of maintenance mode:\n"; +echo "STEP 11: Taking application out of maintenance mode:\n"; echo "--------------------------------------------------------\n\n"; $up = shell_exec('php artisan up'); @@ -267,3 +403,13 @@ echo "your upgraded Snipe-IT!\n"; echo "--------------------------------------------------------\n\n"; +function str_begins($haystack, $needle) { + return 0 === substr_compare($haystack, $needle, 0, strlen($needle)); +} + +function str_ends($haystack, $needle) { + return 0 === substr_compare($haystack, $needle, -strlen($needle)); +} + + +