From dca3da68609a62747fa4056f54837cd810569cf4 Mon Sep 17 00:00:00 2001 From: Taras Machyshyn Date: Mon, 7 Apr 2014 14:50:17 +0300 Subject: [PATCH] improve helpers for install --- install/core/SystemHelper.php | 24 +++++++++++++--------- install/core/actions/checkWritable.php | 5 +++-- install/core/actions/fixAjaxPermission.php | 2 +- install/core/i18n/en_US.php | 5 +++-- install/index.php | 1 + 5 files changed, 22 insertions(+), 15 deletions(-) diff --git a/install/core/SystemHelper.php b/install/core/SystemHelper.php index 504dabe18d..1686a42f57 100644 --- a/install/core/SystemHelper.php +++ b/install/core/SystemHelper.php @@ -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; } diff --git a/install/core/actions/checkWritable.php b/install/core/actions/checkWritable.php index 1d9dcb98bb..327024824b 100644 --- a/install/core/actions/checkWritable.php +++ b/install/core/actions/checkWritable.php @@ -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'].':
'.implode('
', $urls); + $result['errorMsg'] = $langs['Permission denied to files'].':
'.implode('
', $urls); + $result['errorFixInstruction'] = $systemHelper->getPermissionCommands('', array('644', '755')); } ob_clean(); diff --git a/install/core/actions/fixAjaxPermission.php b/install/core/actions/fixAjaxPermission.php index d300bf1179..5f27c98641 100644 --- a/install/core/actions/fixAjaxPermission.php +++ b/install/core/actions/fixAjaxPermission.php @@ -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')); } } diff --git a/install/core/i18n/en_US.php b/install/core/i18n/en_US.php index a9f4c77f16..6ab2c67ff5 100644 --- a/install/core/i18n/en_US.php +++ b/install/core/i18n/en_US.php @@ -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
{C}
', + 'Bad init Permission' => 'Permission denied for "{*}" directory. Please set 775 for "{*}" or just execute this command in the terminal
{C}
+ 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' => '
Run this in Terminal
"{C}"
', - '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', diff --git a/install/index.php b/install/index.php index a4c8225bb9..61ce909108 100644 --- a/install/index.php +++ b/install/index.php @@ -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); }