diff --git a/Mage/Console.php b/Mage/Console.php
index 4d313c8..e8d219a 100644
--- a/Mage/Console.php
+++ b/Mage/Console.php
@@ -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();
diff --git a/Mage/Task/Install.php b/Mage/Task/Install.php
index fd0ea60..a682ce6 100644
--- a/Mage/Task/Install.php
+++ b/Mage/Task/Install.php
@@ -4,11 +4,17 @@ class Mage_Task_Install
public function run ()
{
Mage_Console::output('Installing Magallanes... ', 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('Success!', 0, 2);
}
diff --git a/Mage/Task/Upgrade.php b/Mage/Task/Upgrade.php
new file mode 100644
index 0000000..7aee08f
--- /dev/null
+++ b/Mage/Task/Upgrade.php
@@ -0,0 +1,114 @@
+Magallanes ... ', 1, 0);
+
+ $user = '';
+ // Check if user is root
+ Mage_Console::executeCommand('whoami', $user);
+ if ($user != 'root') {
+ Mage_Console::output('FAIL', 0, 1);
+ Mage_Console::output('You need to be the root 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('SKIP', 0, 1);
+ Mage_Console::output('Your current version is up to date.', 2);
+
+ } else if ($versionCompare > 0) {
+ Mage_Console::output('SKIP', 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('OK', 0, 1);
+ }
+
+ } else {
+ Mage_Console::output('FAIL', 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;
+ }
+ }
+}
\ No newline at end of file
diff --git a/bin/mage b/bin/mage
index 55ef640..b1f2832 100755
--- a/bin/mage
+++ b/bin/mage
@@ -1,5 +1,5 @@
#!/bin/sh
-#VERSION:0.9
+#VERSION:0.9.1
SCRIPT=$(readlink -f $0)
DIR=$(dirname $SCRIPT)
diff --git a/bin/mage.php b/bin/mage.php
index 6f773bd..35dcc09 100644
--- a/bin/mage.php
+++ b/bin/mage.php
@@ -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'));