Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15444556
D10556.id25362.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
11 KB
Referenced Files
None
Subscribers
None
D10556.id25362.diff
View Options
diff --git a/src/applications/drydock/blueprint/DrydockAmazonEC2HostBlueprintImplementation.php b/src/applications/drydock/blueprint/DrydockAmazonEC2HostBlueprintImplementation.php
--- a/src/applications/drydock/blueprint/DrydockAmazonEC2HostBlueprintImplementation.php
+++ b/src/applications/drydock/blueprint/DrydockAmazonEC2HostBlueprintImplementation.php
@@ -689,7 +689,7 @@
$resource->setAttribute(
'aws-status',
- 'Waiting for successful %s connection', $protocol_name);
+ pht('Waiting for successful %s connection', $protocol_name));
$resource->save();
while (true) {
@@ -702,7 +702,7 @@
$ssh_future = $ssh->getExecFuture('echo "test"');
$ssh_future->resolvex();
if ($ssh_future->getWasKilledByTimeout()) {
- throw new Exception('%s execution timed out.', $protocol_name);
+ throw new Exception(pht('%s execution timed out.', $protocol_name));
}
break;
@@ -986,8 +986,29 @@
switch ($type) {
case 'command':
+ case 'command-'.PhutilCommandString::MODE_POWERSHELL:
+ case 'command-'.PhutilCommandString::MODE_WINDOWSCMD:
+ case 'command-'.PhutilCommandString::MODE_BASH:
+ $interface = new DrydockSSHCommandInterface();
+ if ($resource->getAttribute('protocol') === 'winrm') {
+ $interface = new DrydockWinRMCommandInterface();
+ }
+
+ switch ($type) {
+ case 'command':
+ case 'command-'.PhutilCommandString::MODE_POWERSHELL:
+ $interface->setEscapingMode(PhutilCommandString::MODE_POWERSHELL);
+ break;
+ case 'command-'.PhutilCommandString::MODE_WINDOWSCMD:
+ $interface->setEscapingMode(PhutilCommandString::MODE_WINDOWSCMD);
+ break;
+ case 'command-'.PhutilCommandString::MODE_BASH:
+ $interface->setEscapingMode(PhutilCommandString::MODE_BASH);
+ break;
+ }
+
if ($resource->getAttribute('protocol') === 'ssh') {
- return id(new DrydockSSHCommandInterface())
+ return $interface
->setConfiguration(array(
'host' => $resource->getAttribute('host'),
'port' => $resource->getAttribute('port'),
@@ -995,7 +1016,7 @@
'platform' => $resource->getAttribute('platform')))
->setWorkingDirectory($lease->getAttribute('path'));
} else if ($resource->getAttribute('protocol') === 'winrm') {
- return id(new DrydockWinRMCommandInterface())
+ return $interface
->setConfiguration(array(
'host' => $resource->getAttribute('host'),
'port' => $resource->getAttribute('port'),
diff --git a/src/applications/drydock/blueprint/DrydockPreallocatedHostBlueprintImplementation.php b/src/applications/drydock/blueprint/DrydockPreallocatedHostBlueprintImplementation.php
--- a/src/applications/drydock/blueprint/DrydockPreallocatedHostBlueprintImplementation.php
+++ b/src/applications/drydock/blueprint/DrydockPreallocatedHostBlueprintImplementation.php
@@ -116,11 +116,27 @@
switch ($type) {
case 'command':
+ case 'command-'.PhutilCommandString::MODE_POWERSHELL:
+ case 'command-'.PhutilCommandString::MODE_WINDOWSCMD:
+ case 'command-'.PhutilCommandString::MODE_BASH:
$interface = new DrydockSSHCommandInterface();
if ($resource->getAttribute('protocol') === 'winrm') {
$interface = new DrydockWinRMCommandInterface();
}
+ switch ($type) {
+ case 'command':
+ case 'command-'.PhutilCommandString::MODE_POWERSHELL:
+ $interface->setEscapingMode(PhutilCommandString::MODE_POWERSHELL);
+ break;
+ case 'command-'.PhutilCommandString::MODE_WINDOWSCMD:
+ $interface->setEscapingMode(PhutilCommandString::MODE_WINDOWSCMD);
+ break;
+ case 'command-'.PhutilCommandString::MODE_BASH:
+ $interface->setEscapingMode(PhutilCommandString::MODE_BASH);
+ break;
+ }
+
return $interface
->setConfiguration(array(
'host' => $resource->getAttribute('host'),
diff --git a/src/applications/drydock/interface/command/DrydockCommandInterface.php b/src/applications/drydock/interface/command/DrydockCommandInterface.php
--- a/src/applications/drydock/interface/command/DrydockCommandInterface.php
+++ b/src/applications/drydock/interface/command/DrydockCommandInterface.php
@@ -3,6 +3,11 @@
abstract class DrydockCommandInterface extends DrydockInterface {
private $workingDirectory;
+ private $escapingMode;
+
+ public function __construct() {
+ $this->escapingMode = PhutilCommandString::MODE_DEFAULT;
+ }
public function setWorkingDirectory($working_directory) {
$this->workingDirectory = $working_directory;
@@ -13,6 +18,15 @@
return $this->workingDirectory;
}
+ public function setEscapingMode($escaping_mode) {
+ $this->escapingMode = $escaping_mode;
+ return $this;
+ }
+
+ public function getEscapingMode() {
+ return $this->escapingMode;
+ }
+
final public function getInterfaceType() {
return 'command';
}
diff --git a/src/applications/drydock/interface/command/DrydockSSHCommandInterface.php b/src/applications/drydock/interface/command/DrydockSSHCommandInterface.php
--- a/src/applications/drydock/interface/command/DrydockSSHCommandInterface.php
+++ b/src/applications/drydock/interface/command/DrydockSSHCommandInterface.php
@@ -43,9 +43,39 @@
$argv = func_get_args();
if ($this->getConfig('platform') === 'windows') {
+
+ $escape_mode = null;
+ $command_line = null;
+
+ switch ($this->getEscapingMode()) {
+ case PhutilCommandString::MODE_WINDOWSCMD:
+ case PhutilCommandString::MODE_BASH:
+ $escape_mode = PhutilCommandString::MODE_POWERSHELL;
+ $command_line = 'iex $original_command';
+ break;
+ case PhutilCommandString::MODE_POWERSHELL:
+ $escape_mode = PhutilCommandString::MODE_POWERSHELL;
+ $command_line = <<<EOF
+
+# Encode the command as base64...
+\$bytes_command = [System.Text.Encoding]::Unicode.GetBytes(\$original_command)
+\$encoded_command = [Convert]::ToBase64String(\$bytes_command)
+
+C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe `
+ -NonInteractive `
+ -OutputFormat Text `
+ -EncodedCommand \$encoded_command
+EOF;
+ break;
+ default:
+ throw new Exception(pht(
+ 'Unknown shell %s',
+ $this->getShell()));
+ }
+
// Handle Windows by executing the command under PowerShell.
$command = id(new PhutilCommandString($argv))
- ->setEscapingMode(PhutilCommandString::MODE_POWERSHELL);
+ ->setEscapingMode($escape_mode);
$encapsulate_command = array('%s', (string)$command);
$double_command = id(new PhutilCommandString($encapsulate_command))
@@ -87,17 +117,11 @@
$change_directory
-# Encode the command as base64...
\$original_command = $double_command
-\$bytes_command = [System.Text.Encoding]::Unicode.GetBytes(\$original_command)
-\$encoded_command = [Convert]::ToBase64String(\$bytes_command)
# Run powershell from itself to get a "standard" exit code. This still
# doesn't actually catch every kind of error :(
-C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe `
- -NonInteractive `
- -OutputFormat Text `
- -EncodedCommand \$encoded_command
+$command_line
exit \$LastExitCode
EOF;
diff --git a/src/applications/drydock/interface/command/DrydockWinRMCommandInterface.php b/src/applications/drydock/interface/command/DrydockWinRMCommandInterface.php
--- a/src/applications/drydock/interface/command/DrydockWinRMCommandInterface.php
+++ b/src/applications/drydock/interface/command/DrydockWinRMCommandInterface.php
@@ -41,22 +41,40 @@
$change_directory .= 'cd '.$this->getWorkingDirectory().' & ';
}
- // Encode the command to run under Powershell.
- $command = id(new PhutilCommandString($argv))
- ->setEscapingMode(PhutilCommandString::MODE_POWERSHELL);
+ switch ($this->getEscapingMode()) {
+ case PhutilCommandString::MODE_WINDOWSCMD:
+ $command = id(new PhutilCommandString($argv))
+ ->setEscapingMode(PhutilCommandString::MODE_WINDOWSCMD);
+ break;
+ case PhutilCommandString::MODE_BASH:
+ $command = id(new PhutilCommandString($argv))
+ ->setEscapingMode(PhutilCommandString::MODE_BASH);
+ break;
+ case PhutilCommandString::MODE_DEFAULT:
+ case PhutilCommandString::MODE_POWERSHELL:
+ // Encode the command to run under Powershell.
+ $command = id(new PhutilCommandString($argv))
+ ->setEscapingMode(PhutilCommandString::MODE_POWERSHELL);
- // When Microsoft says "Unicode" they don't mean UTF-8.
- $command = mb_convert_encoding($command, 'UTF-16LE');
- $command = base64_encode($command);
+ // When Microsoft says "Unicode" they don't mean UTF-8.
+ $command = mb_convert_encoding($command, 'UTF-16LE');
+ $command = base64_encode($command);
- $powershell =
- 'C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe';
- $powershell .=
- ' -ExecutionPolicy Bypass'.
- ' -NonInteractive'.
- ' -InputFormat Text'.
- ' -OutputFormat Text'.
- ' -EncodedCommand '.$command;
+ $powershell =
+ 'C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe';
+ $powershell .=
+ ' -ExecutionPolicy Bypass'.
+ ' -NonInteractive'.
+ ' -InputFormat Text'.
+ ' -OutputFormat Text'.
+ ' -EncodedCommand '.$command;
+ $command = $powershell;
+ break;
+ default:
+ throw new Exception(pht(
+ 'Unknown shell %s',
+ $this->getShell()));
+ }
$future = new ExecFuture(
'winrm '.
@@ -69,7 +87,7 @@
$this->passphraseWinRMPassword->getUsernameEnvelope(),
$this->passphraseWinRMPassword->getPasswordEnvelope(),
$this->getConfig('port'),
- $change_directory.$powershell);
+ $change_directory.$command);
$future->setTimeout($this->execTimeout);
return $future;
}
diff --git a/src/applications/harbormaster/step/HarbormasterCommandBuildStepImplementation.php b/src/applications/harbormaster/step/HarbormasterCommandBuildStepImplementation.php
--- a/src/applications/harbormaster/step/HarbormasterCommandBuildStepImplementation.php
+++ b/src/applications/harbormaster/step/HarbormasterCommandBuildStepImplementation.php
@@ -52,7 +52,16 @@
$this->platform = null;
- $interface = $lease->getInterface('command');
+ $interface = null;
+
+ switch (idx($settings, 'shell', PhutilCommandString::MODE_DEFAULT)) {
+ case PhutilCommandString::MODE_DEFAULT:
+ $interface = $lease->getInterface('command');
+ break;
+ default:
+ $interface = $lease->getInterface('command-'.$settings['shell']);
+ break;
+ }
$future = $interface->getExecFuture('%C', $command);
@@ -129,9 +138,20 @@
'name' => pht('Command'),
'type' => 'text',
'required' => true,
- 'caption' => pht(
- 'Under Windows, this is executed under PowerShell.'.
- 'Under UNIX, this is executed using the user\'s shell.'),
+ ),
+ 'shell' => array(
+ 'name' => pht('Shell'),
+ 'type' => 'select',
+ 'options' => array(
+ PhutilCommandString::MODE_DEFAULT =>
+ 'Default (Shell on Linux; Powershell on Windows)',
+ PhutilCommandString::MODE_BASH => 'Bash',
+ PhutilCommandString::MODE_WINDOWSCMD =>
+ 'Windows Command Prompt',
+ PhutilCommandString::MODE_POWERSHELL =>
+ 'Windows Powershell',
+ ),
+ 'required' => true,
),
'hostartifact' => array(
'name' => pht('Host'),
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Mar 28, 10:04 AM (5 d, 12 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7725301
Default Alt Text
D10556.id25362.diff (11 KB)
Attached To
Mode
D10556: [drydock/core] Support different shells in Harbormaster / Drydock
Attached
Detach File
Event Timeline
Log In to Comment