diff --git a/Mage/Command/BuiltIn/UpgradeCommand.php b/Mage/Command/BuiltIn/UpgradeCommand.php
index a4587cb..168096e 100644
--- a/Mage/Command/BuiltIn/UpgradeCommand.php
+++ b/Mage/Command/BuiltIn/UpgradeCommand.php
@@ -23,10 +23,16 @@ use Exception;
class UpgradeCommand extends InstallCommand
{
/**
- * GIT Source for downloading
+ * Source for downloading
* @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
@@ -39,69 +45,55 @@ class UpgradeCommand extends InstallCommand
$user = '';
// Check if user is root
Console::executeCommand('whoami', $user);
- if ($user != 'root') {
+ $owner = posix_getpwuid(fileowner(__FILE__));
+ $owner = $owner['name'];
+
+ if ($user != 'root' && $user != $owner) {
Console::output('FAIL', 0, 1);
- Console::output('You need to be the root user to perform the upgrade.', 2);
+ Console::output('You need to be the ' . $owner . ' user to perform the upgrade, or root.', 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')) {
- Console::executeCommand('rm -rf /tmp/__magallanesDownload');
- }
- Console::executeCommand('mkdir /tmp/__magallanesDownload');
- Console::executeCommand('cd /tmp/__magallanesDownload && tar xfz ' . $tarballFile);
- 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) {
- Console::output('SKIP', 0, 1);
- Console::output('Your current version is up to date.', 2);
-
- } else if ($versionCompare > 0) {
- Console::output('SKIP', 0, 1);
- 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);
-
- Console::output('OK', 0, 1);
- }
-
- } else {
- Console::output('FAIL', 0, 1);
- Console::output('Corrupted download.', 2);
- }
- }
+ // Check version
+ $version = json_decode(file_get_contents(self::UPGRADE));
+
+ if ($version !== false) {
+ $versionCompare = version_compare(MAGALLANES_VERSION, $version->latest);
+ if ($versionCompare == 0) {
+ Console::output('SKIP', 0, 1);
+ Console::output('Your current version is up to date.', 2);
+ } else if ($versionCompare == 1) {
+ Console::output('SKIP', 0, 1);
+ Console::output('Your current version is newer.', 2);
+ } else if ($versionCompare == -1) {
+ // Download Package
+ $tarball = file_get_contents(str_replace('{version}', $version->latest, self::DOWNLOAD));
+ if ($tarball === false) {
+ Console::output('FAIL', 0, 1);
+ Console::output('Corrupted download.', 2);
+
+ } else {
+ $tarballFile = tempnam('/tmp', 'magallanes_download');
+ rename($tarballFile, $tarballFile . '.tar.gz');
+ $tarballFile .= '.tar.gz';
+ file_put_contents($tarballFile, $tarball);
+
+ Console::executeCommand('rm -rf ' . MAGALLANES_DIRECTORY);
+ Console::executeCommand('mkdir -p ' . MAGALLANES_DIRECTORY);
+ Console::executeCommand('cd ' . MAGALLANES_DIRECTORY . ' && tar xfz ' . $tarballFile);
+
+ Console::output('OK', 0, 1);
+ }
+
+ } else {
+ Console::output('FAIL', 0, 1);
+ Console::output('Invalid version.', 2);
+ }
+ } else {
+ Console::output('FAIL', 0, 1);
+ Console::output('Invalid version.', 2);
+ }
+ }
}
}
\ No newline at end of file
diff --git a/bin/mage b/bin/mage
index f26bda4..0dc8d26 100755
--- a/bin/mage
+++ b/bin/mage
@@ -13,7 +13,8 @@ date_default_timezone_set('UTC');
$baseDir = dirname(dirname(__FILE__));
-define('MAGALLANES_VERSION', '0.9.14');
+define('MAGALLANES_VERSION', '1.0.0');
+define('MAGALLANES_DIRECTORY', $baseDir);
// Preload
require_once $baseDir . '/Mage/spyc.php';