mirror of
https://github.com/hauke68/Magallanes.git
synced 2025-09-18 22:50:16 +02:00
Changing EOL to Linux LF
This commit is contained in:
parent
9d1e6aba6f
commit
89d82b9992
@ -1,266 +1,266 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Mage\Task\BuiltIn\Filesystem;
|
namespace Mage\Task\BuiltIn\Filesystem;
|
||||||
|
|
||||||
use Mage\Task\AbstractTask;
|
use Mage\Task\AbstractTask;
|
||||||
use Mage\Task\SkipException;
|
use Mage\Task\SkipException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Task for setting permissions on given paths. Change will be done on local or
|
* Task for setting permissions on given paths. Change will be done on local or
|
||||||
* remote host depending on the stage of the deployment.
|
* remote host depending on the stage of the deployment.
|
||||||
*
|
*
|
||||||
* Usage :
|
* Usage :
|
||||||
* pre-deploy:
|
* pre-deploy:
|
||||||
* - filesystem/permissions: {paths: /var/www/myapp/app/cache:/var/www/myapp/app/cache, checkPathsExist: true, owner: www-data, group: www-data, rights: 775}
|
* - filesystem/permissions: {paths: /var/www/myapp/app/cache:/var/www/myapp/app/cache, checkPathsExist: true, owner: www-data, group: www-data, rights: 775}
|
||||||
* on-deploy:
|
* on-deploy:
|
||||||
* - filesystem/permissions: {paths: app/cache:app/logs, checkPathsExist: true, owner: www-data, group: www-data, rights: 775}
|
* - filesystem/permissions: {paths: app/cache:app/logs, checkPathsExist: true, owner: www-data, group: www-data, rights: 775}
|
||||||
*
|
*
|
||||||
* @author Jérémy Huet <jeremy.huet@gmail.com>
|
* @author Jérémy Huet <jeremy.huet@gmail.com>
|
||||||
*/
|
*/
|
||||||
class PermissionsTask extends AbstractTask
|
class PermissionsTask extends AbstractTask
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Paths to change of permissions separated by PATH_SEPARATOR.
|
* Paths to change of permissions separated by PATH_SEPARATOR.
|
||||||
*
|
*
|
||||||
* If the stage is on local host you should give full paths. If on remote
|
* If the stage is on local host you should give full paths. If on remote
|
||||||
* you may give full or relative to the current release directory paths.
|
* you may give full or relative to the current release directory paths.
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
private $paths;
|
private $paths;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If set to true, will check existance of given paths on the host and
|
* If set to true, will check existance of given paths on the host and
|
||||||
* throw SkipException if at least one does not exist.
|
* throw SkipException if at least one does not exist.
|
||||||
*
|
*
|
||||||
* @var boolean
|
* @var boolean
|
||||||
*/
|
*/
|
||||||
private $checkPathsExist = true;
|
private $checkPathsExist = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Owner to set for the given paths (ex : "www-data")
|
* Owner to set for the given paths (ex : "www-data")
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
private $owner;
|
private $owner;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Group to set for the given paths (ex : "www-data")
|
* Group to set for the given paths (ex : "www-data")
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
private $group;
|
private $group;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rights to set for the given paths (ex: "755")
|
* Rights to set for the given paths (ex: "755")
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
private $rights;
|
private $rights;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize parameters.
|
* Initialize parameters.
|
||||||
*
|
*
|
||||||
* @throws SkipException
|
* @throws SkipException
|
||||||
*/
|
*/
|
||||||
public function init()
|
public function init()
|
||||||
{
|
{
|
||||||
parent::init();
|
parent::init();
|
||||||
|
|
||||||
if (! is_null($this->getParameter('checkPathsExist'))) {
|
if (! is_null($this->getParameter('checkPathsExist'))) {
|
||||||
$this->setCheckPathsExist($this->getParameter('checkPathsExist'));
|
$this->setCheckPathsExist($this->getParameter('checkPathsExist'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $this->getParameter('paths')) {
|
if (! $this->getParameter('paths')) {
|
||||||
throw new SkipException('Param paths is mandatory');
|
throw new SkipException('Param paths is mandatory');
|
||||||
}
|
}
|
||||||
$this->setPaths(explode(PATH_SEPARATOR, $this->getParameter('paths', '')));
|
$this->setPaths(explode(PATH_SEPARATOR, $this->getParameter('paths', '')));
|
||||||
|
|
||||||
if (! is_null($this->getParameter('owner'))) {
|
if (! is_null($this->getParameter('owner'))) {
|
||||||
$this->setOwner($this->getParameter('owner'));
|
$this->setOwner($this->getParameter('owner'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! is_null($this->getParameter('group'))) {
|
if (! is_null($this->getParameter('group'))) {
|
||||||
$this->setGroup($this->getParameter('group'));
|
$this->setGroup($this->getParameter('group'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! is_null($this->getParameter('rights'))) {
|
if (! is_null($this->getParameter('rights'))) {
|
||||||
$this->setRights($this->getParameter('rights'));
|
$this->setRights($this->getParameter('rights'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getName()
|
public function getName()
|
||||||
{
|
{
|
||||||
return "Change rights / owner / group for paths : " . $this->getPathsForCmd() . " [built-in]";
|
return "Change rights / owner / group for paths : " . $this->getPathsForCmd() . " [built-in]";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function run()
|
public function run()
|
||||||
{
|
{
|
||||||
$command = '';
|
$command = '';
|
||||||
|
|
||||||
if ($this->paths && $this->owner) {
|
if ($this->paths && $this->owner) {
|
||||||
$command .= 'chown -R ' . $this->owner . ' ' . $this->getPathsForCmd() . ';';
|
$command .= 'chown -R ' . $this->owner . ' ' . $this->getPathsForCmd() . ';';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->paths && $this->group) {
|
if ($this->paths && $this->group) {
|
||||||
$command .= 'chgrp -R ' . $this->group . ' ' . $this->getPathsForCmd() . ';';
|
$command .= 'chgrp -R ' . $this->group . ' ' . $this->getPathsForCmd() . ';';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->paths && $this->rights) {
|
if ($this->paths && $this->rights) {
|
||||||
$command .= 'chmod -R ' . $this->rights . ' ' . $this->getPathsForCmd() . ';';
|
$command .= 'chmod -R ' . $this->rights . ' ' . $this->getPathsForCmd() . ';';
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = $this->runCommand($command);
|
$result = $this->runCommand($command);
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transforms paths array to a string separated by 1 space in order to use
|
* Transforms paths array to a string separated by 1 space in order to use
|
||||||
* it in a command line.
|
* it in a command line.
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function getPathsForCmd($paths = null)
|
protected function getPathsForCmd($paths = null)
|
||||||
{
|
{
|
||||||
if (is_null($paths)) {
|
if (is_null($paths)) {
|
||||||
$paths = $this->paths;
|
$paths = $this->paths;
|
||||||
}
|
}
|
||||||
|
|
||||||
return implode(' ', $paths);
|
return implode(' ', $paths);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set paths. Will check if they exist on the host depending on
|
* Set paths. Will check if they exist on the host depending on
|
||||||
* checkPathsExist flag.
|
* checkPathsExist flag.
|
||||||
*
|
*
|
||||||
* @param array $paths
|
* @param array $paths
|
||||||
* @return PermissionsTask
|
* @return PermissionsTask
|
||||||
* @throws SkipException
|
* @throws SkipException
|
||||||
*/
|
*/
|
||||||
protected function setPaths(array $paths)
|
protected function setPaths(array $paths)
|
||||||
{
|
{
|
||||||
if ($this->checkPathsExist == true) {
|
if ($this->checkPathsExist == true) {
|
||||||
$commands = array();
|
$commands = array();
|
||||||
foreach ($paths as $path) {
|
foreach ($paths as $path) {
|
||||||
$commands[] = '(([ -f ' . $path . ' ]) || ([ -d ' . $path . ' ]))';
|
$commands[] = '(([ -f ' . $path . ' ]) || ([ -d ' . $path . ' ]))';
|
||||||
}
|
}
|
||||||
|
|
||||||
$command = implode(' && ', $commands);
|
$command = implode(' && ', $commands);
|
||||||
if (! $this->runCommand($command)) {
|
if (! $this->runCommand($command)) {
|
||||||
throw new SkipException('Make sure all paths given exist on the host : ' . $this->getPathsForCmd($paths));
|
throw new SkipException('Make sure all paths given exist on the host : ' . $this->getPathsForCmd($paths));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->paths = $paths;
|
$this->paths = $paths;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function getPaths()
|
protected function getPaths()
|
||||||
{
|
{
|
||||||
return $this->paths;
|
return $this->paths;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set checkPathsExist.
|
* Set checkPathsExist.
|
||||||
*
|
*
|
||||||
* @param boolean $checkPathsExist
|
* @param boolean $checkPathsExist
|
||||||
* @return PermissionsTask
|
* @return PermissionsTask
|
||||||
*/
|
*/
|
||||||
protected function setCheckPathsExist($checkPathsExist)
|
protected function setCheckPathsExist($checkPathsExist)
|
||||||
{
|
{
|
||||||
$this->checkPathsExist = $checkPathsExist;
|
$this->checkPathsExist = $checkPathsExist;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
protected function getCheckPathsExist()
|
protected function getCheckPathsExist()
|
||||||
{
|
{
|
||||||
return $this->checkPathsExist;
|
return $this->checkPathsExist;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set owner.
|
* Set owner.
|
||||||
*
|
*
|
||||||
* @todo check existance of $owner on host, might be different ways depending on OS.
|
* @todo check existance of $owner on host, might be different ways depending on OS.
|
||||||
*
|
*
|
||||||
* @param string $owner
|
* @param string $owner
|
||||||
* @return PermissionsTask
|
* @return PermissionsTask
|
||||||
*/
|
*/
|
||||||
protected function setOwner($owner)
|
protected function setOwner($owner)
|
||||||
{
|
{
|
||||||
$this->owner = $owner;
|
$this->owner = $owner;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function getOwner()
|
protected function getOwner()
|
||||||
{
|
{
|
||||||
return $this->owner;
|
return $this->owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set group.
|
* Set group.
|
||||||
*
|
*
|
||||||
* @todo check existance of $group on host, might be different ways depending on OS.
|
* @todo check existance of $group on host, might be different ways depending on OS.
|
||||||
*
|
*
|
||||||
* @param string $group
|
* @param string $group
|
||||||
* @return PermissionsTask
|
* @return PermissionsTask
|
||||||
*/
|
*/
|
||||||
protected function setGroup($group)
|
protected function setGroup($group)
|
||||||
{
|
{
|
||||||
$this->group = $group;
|
$this->group = $group;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function getGroup()
|
protected function getGroup()
|
||||||
{
|
{
|
||||||
return $this->group;
|
return $this->group;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set rights.
|
* Set rights.
|
||||||
*
|
*
|
||||||
* @todo better way to check if $rights is in a correct format.
|
* @todo better way to check if $rights is in a correct format.
|
||||||
*
|
*
|
||||||
* @param string $rights
|
* @param string $rights
|
||||||
* @return PermissionsTask
|
* @return PermissionsTask
|
||||||
*/
|
*/
|
||||||
protected function setRights($rights)
|
protected function setRights($rights)
|
||||||
{
|
{
|
||||||
if (strlen($rights) != 3 || !is_numeric($rights) || $rights > 777) {
|
if (strlen($rights) != 3 || !is_numeric($rights) || $rights > 777) {
|
||||||
throw new SkipException('Make sure the rights "' . $rights . '" are in a correct format.');
|
throw new SkipException('Make sure the rights "' . $rights . '" are in a correct format.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->rights = $rights;
|
$this->rights = $rights;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function getRights()
|
protected function getRights()
|
||||||
{
|
{
|
||||||
return $this->rights;
|
return $this->rights;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,32 +1,32 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Mage\Task\BuiltIn\Filesystem;
|
namespace Mage\Task\BuiltIn\Filesystem;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Task for giving Apache write permissions on given paths.
|
* Task for giving Apache write permissions on given paths.
|
||||||
*
|
*
|
||||||
* Usage :
|
* Usage :
|
||||||
* pre-deploy:
|
* pre-deploy:
|
||||||
* - filesystem/permissions-writable-by-apache: {paths: /var/www/myapp/app/cache:/var/www/myapp/app/cache, checkPathsExist: true}
|
* - filesystem/permissions-writable-by-apache: {paths: /var/www/myapp/app/cache:/var/www/myapp/app/cache, checkPathsExist: true}
|
||||||
* on-deploy:
|
* on-deploy:
|
||||||
* - filesystem/permissions-writable-by-apache: {paths: app/cache:app/logs, checkPathsExist: true}
|
* - filesystem/permissions-writable-by-apache: {paths: app/cache:app/logs, checkPathsExist: true}
|
||||||
*
|
*
|
||||||
* @author Jérémy Huet <jeremy.huet@gmail.com>
|
* @author Jérémy Huet <jeremy.huet@gmail.com>
|
||||||
*/
|
*/
|
||||||
class PermissionsWritableByApacheTask extends PermissionsTask
|
class PermissionsWritableByApacheTask extends PermissionsTask
|
||||||
{
|
{
|
||||||
public function init()
|
public function init()
|
||||||
{
|
{
|
||||||
parent::init();
|
parent::init();
|
||||||
|
|
||||||
$this->setGroup('www-data')
|
$this->setGroup('www-data')
|
||||||
->setRights('775');
|
->setRights('775');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getName()
|
public function getName()
|
||||||
{
|
{
|
||||||
return "Gives write permissions to Apache user for given paths [built-in]";
|
return "Gives write permissions to Apache user for given paths [built-in]";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user