From 4b7295225543aa528221b35c6b064ca332dd7bbc Mon Sep 17 00:00:00 2001 From: grohiro Date: Thu, 29 Jun 2017 18:13:31 +0900 Subject: [PATCH] Enable to allocate a TTY for `deploy:writable` task It allows to use sudo with password when running `deploy:writable` task. Added a variable {{writable_request_tty}} (boolean) --- CHANGELOG.md | 2 +- recipe/deploy/writable.php | 18 +++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bf772135..b45e0ac9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ ### Changed - Improved `config:current` output (print each host's current release) - +- Added `{{writable_request_tty}}` option for `deploy:writable` ## v5.1.1 [v5.1.0...v5.1.1](https://github.com/deployphp/deployer/compare/v5.1.0...v5.1.1) diff --git a/recipe/deploy/writable.php b/recipe/deploy/writable.php index 55241efb..460a753c 100644 --- a/recipe/deploy/writable.php +++ b/recipe/deploy/writable.php @@ -13,6 +13,10 @@ task('deploy:writable', function () { $mode = get('writable_mode'); $sudo = get('writable_use_sudo') ? 'sudo' : ''; $httpUser = get('http_user', false); + $runOpts = []; + if ($sudo) { + $runOpts['tty'] = get('writable_request_tty', false); + } if (empty($dirs)) { return; @@ -40,7 +44,7 @@ task('deploy:writable', function () { // Change owner. // -R operate on files and directories recursively // -L traverse every symbolic link to a directory encountered - run("$sudo chown -RL $httpUser $dirs"); + run("$sudo chown -RL $httpUser $dirs", $runOpts); } elseif ($mode === 'chgrp') { // Change group ownership. // -R operate on files and directories recursively @@ -49,20 +53,20 @@ task('deploy:writable', function () { if ($httpGroup === false) { throw new \RuntimeException("Please setup `http_group` config parameter."); } - run("$sudo chgrp -RH $httpGroup $dirs"); + run("$sudo chgrp -RH $httpGroup $dirs", $runOpts); } elseif ($mode === 'chmod') { $recursive = get('writable_chmod_recursive') ? '-R' : ''; - run("$sudo chmod $recursive {{writable_chmod_mode}} $dirs"); + run("$sudo chmod $recursive {{writable_chmod_mode}} $dirs", $runOpts); } elseif ($mode === 'acl') { if (strpos(run("chmod 2>&1; true"), '+a') !== false) { // Try OS-X specific setting of access-rights - run("$sudo chmod +a \"$httpUser allow delete,write,append,file_inherit,directory_inherit\" $dirs"); - run("$sudo chmod +a \"`whoami` allow delete,write,append,file_inherit,directory_inherit\" $dirs"); + run("$sudo chmod +a \"$httpUser allow delete,write,append,file_inherit,directory_inherit\" $dirs", $runOpts); + run("$sudo chmod +a \"`whoami` allow delete,write,append,file_inherit,directory_inherit\" $dirs", $runOpts); } elseif (commandExist('setfacl')) { if (!empty($sudo)) { - run("$sudo setfacl -RL -m u:\"$httpUser\":rwX -m u:`whoami`:rwX $dirs"); - run("$sudo setfacl -dRL -m u:\"$httpUser\":rwX -m u:`whoami`:rwX $dirs"); + run("$sudo setfacl -RL -m u:\"$httpUser\":rwX -m u:`whoami`:rwX $dirs", $runOpts); + run("$sudo setfacl -dRL -m u:\"$httpUser\":rwX -m u:`whoami`:rwX $dirs", $runOpts); } else { // When running without sudo, exception may be thrown // if executing setfacl on files created by http user (in directory that has been setfacl before).