/** * Command for Upgrading Magallanes * @see \Mage\Command\BuiltIn\InstallCommand::run() */ public function run() { $exitCode = 100; Console::output('Upgrading <dark_gray>Magallanes</dark_gray> ... ', 1, 0); $user = ''; // Check if user is root Console::executeCommand('whoami', $user); $owner = posix_getpwuid(fileowner(__FILE__)); $owner = $owner['name']; if ($user != 'root' && $user != $owner) { Console::output('<red>FAIL</red>', 0, 1); 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 { // Check version $version = json_decode(file_get_contents(self::UPGRADE)); if ($version !== false && $version !== null) { $versionCompare = version_compare(MAGALLANES_VERSION, $version->latest); if ($versionCompare == 0) { Console::output('<yellow>SKIP</yellow>', 0, 1); Console::output('Your current version is up to date.', 2); $exitCode = 0; } else { if ($versionCompare == 1) { Console::output('<yellow>SKIP</yellow>', 0, 1); Console::output('Your current version is newer.', 2); $exitCode = 0; } else { if ($versionCompare == -1) { // Download Package $tarball = file_get_contents(str_replace('{version}', $version->latest, self::DOWNLOAD)); if ($tarball === false) { Console::output('<red>FAIL</red>', 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('cd ' . dirname($tarballFile) . ' && tar xfz ' . $tarballFile); Console::executeCommand('mv ' . dirname($tarballFile) . '/magallanes ' . MAGALLANES_DIRECTORY); Console::output('<green>OK</green>', 0, 1); $exitCode = 0; } } else { Console::output('<red>FAIL</red>', 0, 1); Console::output('Invalid version.', 2); } } } } else { Console::output('<red>FAIL</red>', 0, 1); Console::output('Invalid version.', 2); } } return $exitCode; }
/** * Switches the original source * code dir to tempory name * and recreates orginal dir * allows encryption to be done * into source dir, so other functions * work without changing * * @throws ErrorWithMessageException If source dir can't be renamed * @throws ErrorWithMessageException If original source dir cant be created * * @return bool */ private function switchSrcToTmp() { $ret = Console::executeCommand('mv ' . $this->source . ' ' . $this->ionSource, $out); if (!$ret) { throw new ErrorWithMessageException('Cant create tmp dir :' . $out, $ret); } $ret = Console::executeCommand('mkdir -p ' . $this->source, $out); if (!$ret) { throw new ErrorWithMessageException('Cant re-create dir :' . $out, $ret); } return true; }
/** * Runs a Shell Command Localy * * @param string $command * @param string $output * @return boolean */ protected final function runCommandLocal($command, &$output = null) { return Console::executeCommand($command, $output); }