snipe-it icon indicating copy to clipboard operation
snipe-it copied to clipboard

v4.0.x - Very basic upgrade script [testers needed]

Open snipe opened this issue 9 years ago • 10 comments

Hi all,

I put together a very basic upgrade script that I'm hoping will make updating a little easier moving forward. Most of the pain in the ass parts about upgrading Snipe-IT comes from the framework it's built on. Remembering to run all of the composer commands, clearing the app caches, etc.

If you'd like to give it a shot, you can run it by running php upgrade.php from the web root. It's non-destructive, so it's safe to run. Note that it DOES NOT download the new files for you. The assumption would be you'd grab the new version, and then run the upgrade script. (For now.)

Eventually I'll probably try to make this is a bit more robust, possibly even trying to install the whole thing into a temp directory and then copying things over. This would all be much easier if we knew for a fact that everyone installed using git, but of course that's not always the case.

In theory, if you're on v4, your upgrade process could look something like this moving forward:

git checkout master
git pull
php upgrade.php

That's assuming (of course) you haven't donked up a bunch of permissions with your composer, that you have composer installed, etc.

Anyway, I'd love some feedback on this.

The entire script (as of this moment) is just this:

<?php
(PHP_SAPI !== 'cli' || isset($_SERVER['HTTP_USER_AGENT'])) && die('Access denied.');

$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 "Welcome to the Snipe-IT upgrader.\n\n";
echo "Please note that this script will not download the latest Snipe-IT \n";
echo "files for you, it simply runs the standard composer and artisan \n";
echo "commands needed to finalize the upgrade after \n\n";

echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! WARNING !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n";
echo "!! If you have any encrypted custom fields, BE SURE TO run the recrypter. \n";
echo "!! See the Snipe-IT documentation for help: \n";
echo "!! https://snipe-it.readme.io/docs/upgrading-to-v4\n";
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! WARNING !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n";

echo "--------------------------------------------------------\n";
echo "STEP 1: Backing up database: \n";
echo "--------------------------------------------------------\n\n";
$backup = shell_exec('php artisan snipeit:backup');
echo '-- '.$backup."\n\n";


echo "--------------------------------------------------------\n";
echo "STEP 2: Putting application into maintenance mode: \n";
echo "--------------------------------------------------------\n\n";
$down = shell_exec('php artisan down');
echo '-- '.$down."\n\n";

echo "--------------------------------------------------------\n";
echo "Step 3: Cleaning up old cached files:\n";
echo "--------------------------------------------------------\n\n";


if (file_exists('bootstrap/cache/compiled.php')) {
    echo "-- Deleting bootstrap/cache/compiled.php. It it no longer used.\n";
    @unlink('bootstrap/cache/compiled.php');
} else {
    echo "-- No bootstrap/cache/compiled.php, so nothing to delete.\n";
}

if (file_exists('bootstrap/cache/services.php')) {
    echo "-- Deleting bootstrap/cache/services.php. It it no longer used.\n";
    @unlink('bootstrap/cache/services.php');
} else {
    echo "-- No bootstrap/cache/services.php, so nothing to delete.\n";
}

if (file_exists('bootstrap/cache/config.php')) {
    echo "-- Deleting bootstrap/cache/config.php. It it no longer used.\n";
    @unlink('bootstrap/cache/config.php');
} else {
    echo "-- No bootstrap/cache/config.php, so nothing to delete.\n";
}

$config_clear = shell_exec('php artisan config:clear');
$cache_clear = shell_exec('php artisan cache:clear');
$route_clear = shell_exec('php artisan route:clear');
$view_clear = shell_exec('php artisan view:clear');
echo '-- '.$config_clear;
echo '-- '.$cache_clear;
echo '-- '.$route_clear;
echo '-- '.$view_clear;
echo "\n";

echo "--------------------------------------------------------\n";
echo "Step 4: Updating composer dependencies:\n";
echo "(This may take an moment.)\n";
echo "--------------------------------------------------------\n\n";


// Composer install
if (file_exists('composer.phar')) {
    echo "-- Local composer.phar detected, so we'll use that.\n\n";
    $composer_dump = shell_exec('php composer.phar dump');
    $composer = shell_exec('php composer.phar install --prefer-source');

} else {
    echo "-- We couldn't find a local composer.phar - trying globally.\n\n";
    $composer_dump = shell_exec('composer dump');
    $composer = shell_exec('composer install --prefer-source');
}

echo $composer_dump."\n\n";
echo $composer."\n\n";


echo "--------------------------------------------------------\n";
echo "Step 5: Migrating database:\n";
echo "--------------------------------------------------------\n\n";

$migrations = shell_exec('php artisan migrate --force');
echo '-- '.$migrations."\n\n";


echo "--------------------------------------------------------\n";
echo "Step 6: Checking for OAuth keys:\n";
echo "--------------------------------------------------------\n\n";


if ((!file_exists('storage/oauth-public.key')) || (!file_exists('storage/oauth-private.key'))) {
    echo "- No OAuth keys detected. Running passport install now.\n\n";
    $passport = shell_exec('php artisan passport:install');
    echo $passport;
} else {
    echo "- OAuth keys detected. Skipping passport install.\n\n";
}


echo "--------------------------------------------------------\n";
echo "Step 7: Caching routes and config:\n";
echo "--------------------------------------------------------\n\n";
$config_cache = shell_exec('php artisan config:cache');
$route_cache = shell_exec('php artisan route:cache');
echo '-- '.$config_cache;
echo '-- '.$route_cache;
echo "\n";



echo "--------------------------------------------------------\n";
echo "Step 8: Taking application out of maintenance mode:\n";
echo "--------------------------------------------------------\n\n";

$up = shell_exec('php artisan up');
echo '-- '.$up."\n\n";

echo "--------------------------------------------------------\n";
echo "FINISHED! Clear your browser cookies and re-login to use :\n";
echo "your upgraded Snipe-IT.\n";
echo "--------------------------------------------------------\n\n";

snipe avatar Sep 28 '17 05:09 snipe

I can try this tool for you on my test environment. So I understand correct:

  • I start from Version 3.3.0-16
  • Make DB-Backup using PHPmyadmin Type the following: -> git checkout master -> git pull -> php upgrade.php

Correct?

pvhkai avatar Sep 28 '17 07:09 pvhkai

It will actually backup your database as step 1 in the process, but it’s never, ever a bad idea to back it up separately as well :)

If you installed via git, that should work. Hopefully :)

snipe avatar Sep 28 '17 07:09 snipe

Haha funfact - I did install complete manually (without GIT) Any Idea how to start it without Git?

pvhkai avatar Sep 28 '17 07:09 pvhkai

Well... It looks like working for me but kinda brakes it. I am not sure is it from the actual update or something else. This is what I get from the browser: image

This is part of the source:

</title>
<!-- Tell the browser to be responsive to screen width -->
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">

<!-- Select2 -->
<link rel="stylesheet" href="http://MY_WEBSITE/js/plugins/select2/select2.min.css">

<!-- iCheck for checkboxes and radio inputs -->
<link rel="stylesheet" href="http://MY_WEBSITE/js/plugins/iCheck/all.css">

<!-- bootstrap tables CSS -->
<link rel="stylesheet" href="http://MY_WEBSITE/css/bootstrap-table.css">

<link rel="stylesheet" href="http://MY_WEBSITE/index.php/css/dist/all.css">

<link rel="shortcut icon" type="image/ico" href="http://MY_WEBSITE/favicon.ico">

<meta name="csrf-token" content="Jf3mJnMArro08hXv7fVV6WvcnDu4dcAEbb8rXPpJ">

  <script>
      window.Laravel = { csrfToken: 'Jf3mJnMArro08hXv7fVV6WvcnDu4dcAEbb8rXPpJ' };
  </script>

all.css and all.js are in the write place but it looks like this /index.php/ is getting in the way. Maybe I miss-configured something. The webpage is hell of a mess without css, although the links are working: image

Diniver avatar Sep 28 '17 08:09 Diniver

<link rel="stylesheet" href="http://MY_WEBSITE/index.php/css/dist/all.css">

Why is that index.php in there?

snipe avatar Sep 29 '17 02:09 snipe

Any Idea how to start it without Git?

@pvhkai you can just download the latest from the master branch instead of doing a git pull. Installing via git is just easier for future updates.

snipe avatar Sep 29 '17 03:09 snipe

Now just updated with sudo -u www-data php update.php without any errors upgrade from 4.0.7 -> 4.0.8

stillru avatar Oct 03 '17 13:10 stillru

You really don't want to be running that as sudo. Ever. Same way you never want to install snipe-it as root.

snipe avatar Oct 03 '17 13:10 snipe

Sorry, I'm tired and dumb. Just caught the additional flag.

/me needs a nap

snipe avatar Oct 03 '17 13:10 snipe

@stillru Did you install via git? I added a bit that makes it try to do a git pull from master in the latest version. Not sure if that's going to work, long term.

snipe avatar Oct 03 '17 13:10 snipe