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)
This commit is contained in:
grohiro 2017-06-29 18:13:31 +09:00
parent 15274524b2
commit 4b72952255
2 changed files with 12 additions and 8 deletions

View File

@ -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)

View File

@ -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).