improve helpers for install

This commit is contained in:
Taras Machyshyn
2014-04-07 14:50:17 +03:00
parent 4b93cb26d0
commit dca3da6860
5 changed files with 22 additions and 15 deletions
+14 -10
View File
@@ -197,41 +197,45 @@ class SystemHelper
return (defined("PHP_BINDIR"))? PHP_BINDIR.DIRECTORY_SEPARATOR.'php' : 'php';
}
public function getChmodCommand($path, $permissions = array('755'), $isFile = null)
public function getChmodCommand($path, $permissions = array('755'), $isSudo = false, $isFile = null)
{
$path = $this->getFullPath($path);
$sudoStr = $isSudo ? 'sudo ' : '';
if (is_string($permissions)) {
$permissions = (array) $permissions;
}
if (!isset($isFile) && count($permissions) == 1) {
return 'chmod -R '.$permissions[0].' '.$path;
return $sudoStr.'chmod -R '.$permissions[0].' '.$path;
}
$bufPerm = (count($permissions) == 1) ? array_fill(0, 2, $permissions[0]) : $permissions;
$commands = array();
$commands[] = 'chmod '.$bufPerm[0].' $(find '.$path.' -type f)';
$commands[] = 'chmod '.$bufPerm[1].' $(find '.$path.' -type d)';
$commands[] = $sudoStr.'chmod '.$bufPerm[0].' $(find '.$path.' -type f)';
$commands[] = $sudoStr.'chmod '.$bufPerm[1].' $(find '.$path.' -type d)';
if (count($permissions) >= 2) {
return implode(' && ', $commands);
return implode('; ', $commands);
}
return $isFile ? $commands[0] : $commands[1];
}
public function getChownCommand($path)
public function getChownCommand($path, $isSudo = false)
{
$owner = posix_getuid();
$group = posix_getegid();
$sudoStr = $isSudo ? 'sudo ' : '';
if (empty($owner) || empty($group)) {
return null;
}
return 'chown -R '.$owner.':'.$group.' '.$this->getFullPath($path);
return $sudoStr.'chown -R '.$owner.':'.$group.' '.$this->getFullPath($path);
}
public function getFullPath($path)
@@ -243,12 +247,12 @@ class SystemHelper
return $this->getRootDir() . $path;
}
public function getPermissionCommands($path, $permissions = array('644', '755'), $isFile = null)
public function getPermissionCommands($path, $permissions = array('644', '755'), $isSudo = false, $isFile = null)
{
$commands = array();
$commands[] = $this->getChmodCommand($path, $permissions, $isFile);
$commands[] = $this->getChmodCommand($path, $permissions, $isSudo, $isFile);
$chown = $this->getChownCommand($path);
$chown = $this->getChownCommand($path, $isSudo);
if (isset($chown)) {
$commands[] = $chown;
}
+3 -2
View File
@@ -18,7 +18,7 @@
*
* You should have received a copy of the GNU General Public License
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
************************************************************************/
************************************************************************/
ob_start();
$result = array('success' => true, 'errorMsg' => '');
@@ -29,7 +29,8 @@ if (!$installer->isWritable()) {
foreach ($urls as &$url) {
$url = '        '.$url;
}
$result['errorMsg'] = $langs['Cannot write to files'].':<br>'.implode('<br>', $urls);
$result['errorMsg'] = $langs['Permission denied to files'].':<br>'.implode('<br>', $urls);
$result['errorFixInstruction'] = $systemHelper->getPermissionCommands('', array('644', '755'));
}
ob_clean();
+1 -1
View File
@@ -30,7 +30,7 @@ if (!empty($_REQUEST['url'])) {
else {
$result['success'] = false;
$result['errorMsg'] = $_REQUEST['url'];
$result['errorFixInstruction'] = $systemHelper->getPermissionCommands($_REQUEST['url'], array('644', '755'));
$result['errorFixInstruction'] = $systemHelper->getPermissionCommands('', array('644', '755'));
}
}
+3 -2
View File
@@ -23,7 +23,8 @@
return array(
'Main page title' => 'Welcome to EspoCRM',
'Main page header' => '',
'Bad init Permission' => 'Permission denied for "{*}" directory. Please set 775 for "{*}" or just execute this command in the terminal <pre><b>{C}</b></pre>',
'Bad init Permission' => 'Permission denied for "{*}" directory. Please set 775 for "{*}" or just execute this command in the terminal <pre><b>{C}</b></pre>
Operation not permitted? Try this one: {CSU}',
'Start page title' => 'License Agreement',
'Step1 page title' => 'License Agreement',
'License Agreement' => 'License Agreement',
@@ -90,7 +91,7 @@ return array(
'Cannot create user' => 'Cannot create user',
'Permission denied' => 'Permission denied',
'permissionInstruction' => '<br>Run this in Terminal<pre><b>"{C}"</b></pre>',
'Cannot write to files' => 'Cannot write to file(s)',
'Permission denied to files' => 'Permission denied to file(s)',
'Can not save settings' => 'Can not save settings',
'Cannot save preferences' => 'Cannot save preferences',
+1
View File
@@ -44,6 +44,7 @@ if (!$systemHelper->initWritable()) {
$message = $langs['Bad init Permission'];
$message = str_replace('{*}', $dir, $message);
$message = str_replace('{C}', $systemHelper->getPermissionCommands($dir, '775'), $message);
$message = str_replace('{CSU}', $systemHelper->getPermissionCommands($dir, '775', true), $message);
die($message);
}