mirror of
				https://github.com/hauke68/Magallanes.git
				synced 2025-11-04 17:10:18 +01:00 
			
		
		
		
	Upgrade command.
This commit is contained in:
		
							parent
							
								
									f646647036
								
							
						
					
					
						commit
						ac08d1874c
					
				@ -23,10 +23,16 @@ use Exception;
 | 
				
			|||||||
class UpgradeCommand extends InstallCommand
 | 
					class UpgradeCommand extends InstallCommand
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * GIT Source for downloading
 | 
						 * Source for downloading
 | 
				
			||||||
	 * @var string
 | 
						 * @var string
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
    const DOWNLOAD = 'https://github.com/andres-montanez/Magallanes/tarball/stable';
 | 
					    const DOWNLOAD = 'http://download.magephp.com/magallanes.{version}.tar.gz';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * JSON for Upgrade
 | 
				
			||||||
 | 
					     * @var string
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    const UPGRADE = 'http://download.magephp.com/upgrade.json';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Command for Upgrading Magallanes
 | 
					     * Command for Upgrading Magallanes
 | 
				
			||||||
@ -39,69 +45,55 @@ class UpgradeCommand extends InstallCommand
 | 
				
			|||||||
        $user = '';
 | 
					        $user = '';
 | 
				
			||||||
        // Check if user is root
 | 
					        // Check if user is root
 | 
				
			||||||
        Console::executeCommand('whoami', $user);
 | 
					        Console::executeCommand('whoami', $user);
 | 
				
			||||||
        if ($user != 'root') {
 | 
					        $owner = posix_getpwuid(fileowner(__FILE__));
 | 
				
			||||||
 | 
					        $owner = $owner['name'];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if ($user != 'root' && $user != $owner) {
 | 
				
			||||||
            Console::output('<red>FAIL</red>', 0, 1);
 | 
					            Console::output('<red>FAIL</red>', 0, 1);
 | 
				
			||||||
            Console::output('You need to be the <dark_gray>root</dark_gray> user to perform the upgrade.', 2);
 | 
					            Console::output('You need to be the <dark_gray>' . $owner . '</dark_gray> user to perform the upgrade, or <dark_gray>root</dark_gray>.', 2);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            // Download Package
 | 
					        	// Check version
 | 
				
			||||||
            $tarball = file_get_contents(self::DOWNLOAD);
 | 
					        	$version = json_decode(file_get_contents(self::UPGRADE));
 | 
				
			||||||
            $tarballFile = tempnam('/tmp', 'magallanes_download');
 | 
					 | 
				
			||||||
            rename($tarballFile, $tarballFile . '.tar.gz');
 | 
					 | 
				
			||||||
            $tarballFile .= '.tar.gz';
 | 
					 | 
				
			||||||
            file_put_contents($tarballFile, $tarball);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Unpackage
 | 
					        	if ($version !== false) {
 | 
				
			||||||
            if (file_exists('/tmp/__magallanesDownload')) {
 | 
					        		$versionCompare = version_compare(MAGALLANES_VERSION, $version->latest);
 | 
				
			||||||
                Console::executeCommand('rm -rf /tmp/__magallanesDownload');
 | 
					        		if ($versionCompare == 0) {
 | 
				
			||||||
            }
 | 
					        			Console::output('<yellow>SKIP</yellow>', 0, 1);
 | 
				
			||||||
            Console::executeCommand('mkdir /tmp/__magallanesDownload');
 | 
					        			Console::output('Your current version is up to date.', 2);
 | 
				
			||||||
            Console::executeCommand('cd /tmp/__magallanesDownload && tar xfz ' . $tarballFile);
 | 
					 | 
				
			||||||
            Console::executeCommand('rm -f ' . $tarballFile);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Find Package
 | 
					        		} else if ($versionCompare == 1) {
 | 
				
			||||||
            $tarballDir = opendir('/tmp/__magallanesDownload');
 | 
					        			Console::output('<yellow>SKIP</yellow>', 0, 1);
 | 
				
			||||||
            while (($file = readdir($tarballDir)) == true) {
 | 
					        			Console::output('Your current version is newer.', 2);
 | 
				
			||||||
                if ($file == '.' || $file == '..') {
 | 
					 | 
				
			||||||
                    continue;
 | 
					 | 
				
			||||||
                } else {
 | 
					 | 
				
			||||||
                    $packageDir = $file;
 | 
					 | 
				
			||||||
                    break;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Get Version
 | 
					        		} else if ($versionCompare == -1) {
 | 
				
			||||||
            $version = false;
 | 
					        			// Download Package
 | 
				
			||||||
            if (file_exists('/tmp/__magallanesDownload/' . $packageDir . '/bin/mage')) {
 | 
					        			$tarball = file_get_contents(str_replace('{version}', $version->latest, self::DOWNLOAD));
 | 
				
			||||||
                list(, $version) = file('/tmp/__magallanesDownload/' . $packageDir . '/bin/mage');
 | 
					        			if ($tarball === false) {
 | 
				
			||||||
                $version = trim(str_replace('#VERSION:', '', $version));
 | 
					        				Console::output('<red>FAIL</red>', 0, 1);
 | 
				
			||||||
            }
 | 
					        				Console::output('Corrupted download.', 2);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if ($version != false) {
 | 
					        			} else {
 | 
				
			||||||
                $versionCompare = version_compare(MAGALLANES_VERSION, $version);
 | 
					        				$tarballFile = tempnam('/tmp', 'magallanes_download');
 | 
				
			||||||
                if ($versionCompare == 0) {
 | 
					        				rename($tarballFile, $tarballFile . '.tar.gz');
 | 
				
			||||||
                    Console::output('<yellow>SKIP</yellow>', 0, 1);
 | 
					        				$tarballFile .= '.tar.gz';
 | 
				
			||||||
                    Console::output('Your current version is up to date.', 2);
 | 
					        				file_put_contents($tarballFile, $tarball);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                } else if ($versionCompare > 0) {
 | 
					        				Console::executeCommand('rm -rf ' . MAGALLANES_DIRECTORY);
 | 
				
			||||||
                    Console::output('<yellow>SKIP</yellow>', 0, 1);
 | 
					        				Console::executeCommand('mkdir -p ' . MAGALLANES_DIRECTORY);
 | 
				
			||||||
                    Console::output('Your current version is newer.', 2);
 | 
					        				Console::executeCommand('cd ' . MAGALLANES_DIRECTORY . ' && tar xfz ' . $tarballFile);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                } else {
 | 
					        				Console::output('<green>OK</green>', 0, 1);
 | 
				
			||||||
                    $this->recursiveCopy('/tmp/__magallanesDownload/' . $packageDir, '/opt/magallanes-' . $version);
 | 
					        			}
 | 
				
			||||||
                    unlink('/opt/magallanes');
 | 
					 | 
				
			||||||
                    symlink('/opt/magallanes-' . $version, '/opt/magallanes');
 | 
					 | 
				
			||||||
                    chmod('/opt/magallanes/bin/mage', 0755);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    Console::output('<green>OK</green>', 0, 1);
 | 
					        		} else {
 | 
				
			||||||
                }
 | 
					        			Console::output('<red>FAIL</red>', 0, 1);
 | 
				
			||||||
 | 
					        			Console::output('Invalid version.', 2);
 | 
				
			||||||
            } else {
 | 
					        		}
 | 
				
			||||||
                Console::output('<red>FAIL</red>', 0, 1);
 | 
					        	} else {
 | 
				
			||||||
                Console::output('Corrupted download.', 2);
 | 
					        		Console::output('<red>FAIL</red>', 0, 1);
 | 
				
			||||||
            }
 | 
					        		Console::output('Invalid version.', 2);
 | 
				
			||||||
 | 
					        	}
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
							
								
								
									
										3
									
								
								bin/mage
									
									
									
									
									
								
							
							
						
						
									
										3
									
								
								bin/mage
									
									
									
									
									
								
							@ -13,7 +13,8 @@ date_default_timezone_set('UTC');
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
$baseDir = dirname(dirname(__FILE__));
 | 
					$baseDir = dirname(dirname(__FILE__));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
define('MAGALLANES_VERSION', '0.9.14');
 | 
					define('MAGALLANES_VERSION', '1.0.0');
 | 
				
			||||||
 | 
					define('MAGALLANES_DIRECTORY', $baseDir);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Preload
 | 
					// Preload
 | 
				
			||||||
require_once $baseDir . '/Mage/spyc.php';
 | 
					require_once $baseDir . '/Mage/spyc.php';
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user