mirror of
https://github.com/andres-montanez/Magallanes
synced 2024-05-10 01:36:38 +02:00
Address issue #3. Allow install in a custom directory. By default no root user is checked.
This commit is contained in:
parent
f8476197ac
commit
001fa82c51
|
@ -4,19 +4,54 @@ class Mage_Command_BuiltIn_Install
|
|||
{
|
||||
public function run()
|
||||
{
|
||||
Mage_Console::output('Installing <dark_gray>Magallanes</dark_gray>... ', 1, 0);
|
||||
$this->_recursiveCopy('./', '/opt/magallanes-' . MAGALLANES_VERSION);
|
||||
Mage_Console::output('Installing <dark_gray>Magallanes</dark_gray>... ', 1, 0);
|
||||
|
||||
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');
|
||||
}
|
||||
// Vars
|
||||
$installDir = $this->getConfig()->getParameter('installDir', '/opt/magallanes');
|
||||
$systemWide = $this->getConfig()->getParameter('systemWide', false);
|
||||
|
||||
Mage_Console::output('<light_green>Success!</light_green>', 0, 2);
|
||||
// Clean vars
|
||||
$baseDir = realpath(dirname($installDir));
|
||||
$installDir = basename($installDir);
|
||||
|
||||
// Check if install dir is available
|
||||
if (!is_dir($baseDir) || !is_writable($baseDir)) {
|
||||
Mage_Console::output('<red>Failure: install directory is invalid.</red>', 0, 2);
|
||||
|
||||
// Chck if it is a system wide install the user is root
|
||||
} else if ($systemWide && (getenv('LOGNAME') != 'root')) {
|
||||
Mage_Console::output('<red>Failure: you have to be root to perform a system wide install.</red>', 0, 2);
|
||||
|
||||
} else {
|
||||
$destinationDir = $baseDir . '/' . $installDir;
|
||||
if (!is_dir($destinationDir)) {
|
||||
mkdir($destinationDir);
|
||||
}
|
||||
|
||||
// Copy
|
||||
$this->_recursiveCopy('./', $destinationDir . '/' . MAGALLANES_VERSION);
|
||||
|
||||
// Check if there is already a symlink
|
||||
if (file_exists($destinationDir . '/' . 'latest')
|
||||
&& is_link($destinationDir . '/' . 'latest')) {
|
||||
unlink($destinationDir . '/' . 'latest');
|
||||
}
|
||||
|
||||
// Create "latest" symlink
|
||||
symlink(
|
||||
$destinationDir . '/' . MAGALLANES_VERSION,
|
||||
$destinationDir . '/' . 'latest'
|
||||
);
|
||||
chmod($destinationDir . '/' . MAGALLANES_VERSION . '/bin/mage', 0755);
|
||||
|
||||
if ($systemWide) {
|
||||
if (!file_exists('/usr/bin/mage')) {
|
||||
symlink($destinationDir . '/latest/bin/mage', '/usr/bin/mage');
|
||||
}
|
||||
}
|
||||
|
||||
Mage_Console::output('<light_green>Success!</light_green>', 0, 2);
|
||||
}
|
||||
}
|
||||
|
||||
private function _recursiveCopy($from, $to)
|
||||
|
|
22
bin/mage
22
bin/mage
|
@ -1,9 +1,19 @@
|
|||
#!/bin/sh
|
||||
#VERSION:0.9.14
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
date_default_timezone_set('UTC');
|
||||
|
||||
SCRIPT=$(readlink -f $0)
|
||||
DIR=$(dirname $SCRIPT)
|
||||
PHP_BIN=$(which php)
|
||||
$baseDir = dirname(dirname(__FILE__));
|
||||
|
||||
$PHP_BIN -d safe_mode=Off -f $DIR/mage.php -- $@
|
||||
define('MAGALLANES_VERSION', '0.9.14');
|
||||
|
||||
// Preload
|
||||
require_once $baseDir . '/Mage/spyc.php';
|
||||
require_once $baseDir . '/Mage/Autoload.php';
|
||||
spl_autoload_register(array('Mage_Autoload', 'autoload'));
|
||||
|
||||
// Clean arguments
|
||||
array_shift($argv);
|
||||
|
||||
// Run Magallanes
|
||||
$console = new Mage_Console;
|
||||
$console->run($argv);
|
||||
|
|
Loading…
Reference in a new issue