Page MenuHomePhabricator

D10556.id.diff
No OneTemporary

D10556.id.diff

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
@@ -100,11 +100,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('platform') === 'windows') {
$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/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
@@ -44,21 +44,40 @@
}
// 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()));
+ }
return new ExecFuture(
'winrm '.
@@ -71,6 +90,6 @@
$this->passphraseWinRMPassword->getUsernameEnvelope(),
$this->passphraseWinRMPassword->getPasswordEnvelope(),
$this->getConfig('port'),
- $change_directory.$powershell);
+ $change_directory.$command);
}
}
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
@@ -57,7 +57,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);
@@ -134,9 +143,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

Mime Type
text/plain
Expires
Thu, Mar 20, 4:54 AM (1 w, 5 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7332485
Default Alt Text
D10556.id.diff (6 KB)

Event Timeline