mirror of
https://github.com/hauke68/Magallanes.git
synced 2025-08-26 05:10:17 +02:00
First iteration of upgrade.
This commit is contained in:
parent
f21f63456a
commit
ff1efabaf4
@ -33,6 +33,9 @@ class Mage_Console
|
||||
} else if ($this->_args[0] == 'install') {
|
||||
$this->_action = 'install';
|
||||
|
||||
} else if ($this->_args[0] == 'upgrade') {
|
||||
$this->_action = 'upgrade';
|
||||
|
||||
} else if ($this->_args[0] == 'version') {
|
||||
$this->_action = 'version';
|
||||
|
||||
@ -102,7 +105,7 @@ class Mage_Console
|
||||
|
||||
// Logging
|
||||
$showGrettings = true;
|
||||
if (in_array($this->getAction(), array('install', 'version'))) {
|
||||
if (in_array($this->getAction(), array('install', 'upgrade', 'version'))) {
|
||||
self::$_logEnabled = false;
|
||||
$showGrettings = false;
|
||||
} else {
|
||||
@ -145,6 +148,11 @@ class Mage_Console
|
||||
$task->run();
|
||||
break;
|
||||
|
||||
case 'upgrade';
|
||||
$task = new Mage_Task_Upgrade;
|
||||
$task->run();
|
||||
break;
|
||||
|
||||
case 'init';
|
||||
$task = new Mage_Task_Init;
|
||||
$task->run();
|
||||
|
@ -4,11 +4,17 @@ class Mage_Task_Install
|
||||
public function run ()
|
||||
{
|
||||
Mage_Console::output('Installing <dark_gray>Magallanes</dark_gray>... ', 1, 0);
|
||||
$this->_recursiveCopy('./', '/opt/magallanes');
|
||||
$this->_recursiveCopy('./', '/opt/magallanes-' . MAGALLANES_VERSION);
|
||||
|
||||
if (file_exists('/opt/magallanes') && is_link('/opt/magallanes')) {
|
||||
unlink('/opt/magallanes');
|
||||
}
|
||||
symlink('/opt/magallanes-' . MAGALLANES_VERSION, '/opt/magallanes');
|
||||
chmod('/opt/magallanes/bin/mage', 0755);
|
||||
if (!file_exists('/usr/bin/mage')) {
|
||||
symlink('/opt/magallanes/bin/mage', '/usr/bin/mage');
|
||||
symlink('/opt/magallanes/bin/mage', '/usr/bin/mage');
|
||||
}
|
||||
|
||||
Mage_Console::output('<light_green>Success!</light_green>', 0, 2);
|
||||
}
|
||||
|
||||
|
114
Mage/Task/Upgrade.php
Normal file
114
Mage/Task/Upgrade.php
Normal file
@ -0,0 +1,114 @@
|
||||
<?php
|
||||
class Mage_Task_Upgrade
|
||||
{
|
||||
const DOWNLOAD = 'https://github.com/andres-montanez/Magallanes/tarball/stable';
|
||||
|
||||
public function run ()
|
||||
{
|
||||
Mage_Console::output('Upgrading <dark_gray>Magallanes</dark_gray> ... ', 1, 0);
|
||||
|
||||
$user = '';
|
||||
// Check if user is root
|
||||
Mage_Console::executeCommand('whoami', $user);
|
||||
if ($user != 'root') {
|
||||
Mage_Console::output('<red>FAIL</red>', 0, 1);
|
||||
Mage_Console::output('You need to be the <dark_gray>root</dark_gray> user to perform the upgrade.', 2);
|
||||
|
||||
} else {
|
||||
// Download Package
|
||||
$tarball = file_get_contents(self::DOWNLOAD);
|
||||
$tarballFile = tempnam('/tmp', 'magallanes_download');
|
||||
rename($tarballFile, $tarballFile . '.tar.gz');
|
||||
$tarballFile .= '.tar.gz';
|
||||
file_put_contents($tarballFile, $tarball);
|
||||
|
||||
// Unpackage
|
||||
if (file_exists('/tmp/__magallanesDownload')) {
|
||||
Mage_Console::executeCommand('rm -rf /tmp/__magallanesDownload');
|
||||
}
|
||||
Mage_Console::executeCommand('mkdir /tmp/__magallanesDownload');
|
||||
Mage_Console::executeCommand('cd /tmp/__magallanesDownload && tar xfz ' . $tarballFile);
|
||||
Mage_Console::executeCommand('rm -f ' . $tarballFile);
|
||||
|
||||
// Find Package
|
||||
$tarballDir = opendir('/tmp/__magallanesDownload');
|
||||
while (($file = readdir($tarballDir)) == true) {
|
||||
if ($file == '.' || $file == '..') {
|
||||
continue;
|
||||
} else {
|
||||
$packageDir = $file;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Get Version
|
||||
$version = false;
|
||||
if (file_exists('/tmp/__magallanesDownload/' . $packageDir . '/bin/mage')) {
|
||||
list(, $version) = file('/tmp/__magallanesDownload/' . $packageDir . '/bin/mage');
|
||||
$version = trim(str_replace('#VERSION:', '', $version));
|
||||
}
|
||||
|
||||
if ($version != false) {
|
||||
$versionCompare = version_compare(MAGALLANES_VERSION, $version);
|
||||
if ($versionCompare == 0) {
|
||||
Mage_Console::output('<yellow>SKIP</yellow>', 0, 1);
|
||||
Mage_Console::output('Your current version is up to date.', 2);
|
||||
|
||||
} else if ($versionCompare > 0) {
|
||||
Mage_Console::output('<yellow>SKIP</yellow>', 0, 1);
|
||||
Mage_Console::output('Your current version is newer.', 2);
|
||||
|
||||
} else {
|
||||
$this->_recursiveCopy('/tmp/__magallanesDownload/' . $packageDir, '/opt/magallanes-' . $version);
|
||||
unlink('/opt/magallanes');
|
||||
symlink('/opt/magallanes-' . $version, '/opt/magallanes');
|
||||
chmod('/opt/magallanes/bin/mage', 0755);
|
||||
|
||||
Mage_Console::output('<green>OK</green>', 0, 1);
|
||||
}
|
||||
|
||||
} else {
|
||||
Mage_Console::output('<red>FAIL</red>', 0, 1);
|
||||
Mage_Console::output('Corrupted download.', 2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private function _recursiveCopy ($from, $to)
|
||||
{
|
||||
if (is_dir($from)) {
|
||||
mkdir($to);
|
||||
$files = scandir($from);
|
||||
|
||||
if (count($files) > 0) {
|
||||
foreach ($files as $file) {
|
||||
if (strpos($file, '.') === 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (is_dir($from . DIRECTORY_SEPARATOR . $file)) {
|
||||
$this->_recursiveCopy(
|
||||
$from . DIRECTORY_SEPARATOR . $file,
|
||||
$to . DIRECTORY_SEPARATOR . $file
|
||||
);
|
||||
|
||||
} else {
|
||||
copy(
|
||||
$from . DIRECTORY_SEPARATOR . $file,
|
||||
$to . DIRECTORY_SEPARATOR . $file
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
} elseif (is_file($from)) {
|
||||
return copy($from, $to);
|
||||
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
2
bin/mage
2
bin/mage
@ -1,5 +1,5 @@
|
||||
#!/bin/sh
|
||||
#VERSION:0.9
|
||||
#VERSION:0.9.1
|
||||
|
||||
SCRIPT=$(readlink -f $0)
|
||||
DIR=$(dirname $SCRIPT)
|
||||
|
@ -24,7 +24,7 @@ date_default_timezone_set('UTC');
|
||||
|
||||
$baseDir = dirname(dirname(__FILE__));
|
||||
|
||||
define('MAGALLANES_VERSION', '0.9');
|
||||
define('MAGALLANES_VERSION', '0.9.1');
|
||||
|
||||
require_once $baseDir . '/Mage/Autoload.php';
|
||||
spl_autoload_register(array('Mage_Autoload', 'autoload'));
|
||||
|
Loading…
Reference in New Issue
Block a user