InstallAgentScript

Microsoft.Unix.SSHCommand.Elevated.InstallAgentScript.WriteAction (WriteActionModuleType)

Deinstalliert einen Agent von einem Host.

Element properties:

TypeWriteActionModuleType
IsolationAny
AccessibilityInternal
RunAsDefault
InputTypeSystem.BaseData
OutputTypeSystem.BaseData

Member Modules:

ID Module Type TypeId RunAs 
InstallElevatedAgent WriteAction System.Secure.CommandExecuter Default

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
Hoststring$Config/Host$Host
Portstring$Config/Port$Port
UserNamestring$Config/UserName$Benutzername
Passwordstring$Config/Password$Kennwort
SUPasswordstring$Config/SUPassword$Erhöhtes Kennwort
SUCommandstring$Config/SUCommand$Erhöhungsbefehl
InstallCommandstring$Config/InstallCommand$Installationsbefehl

Source Code:

<WriteActionModuleType ID="Microsoft.Unix.SSHCommand.Elevated.InstallAgentScript.WriteAction" Accessibility="Internal">
<Configuration>
<xsd:element name="Host" type="xsd:string"/>
<xsd:element name="Port" type="xsd:string" minOccurs="0"/>
<xsd:element name="UserName" type="xsd:string"/>
<xsd:element name="Password" type="xsd:string"/>
<xsd:element name="SUPassword" type="xsd:string"/>
<xsd:element name="SUCommand" type="xsd:string"/>
<xsd:element name="InstallCommand" type="xsd:string"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="Host" ParameterType="string" Selector="$Config/Host$"/>
<OverrideableParameter ID="Port" ParameterType="string" Selector="$Config/Port$"/>
<OverrideableParameter ID="UserName" ParameterType="string" Selector="$Config/UserName$"/>
<OverrideableParameter ID="Password" ParameterType="string" Selector="$Config/Password$"/>
<OverrideableParameter ID="SUPassword" ParameterType="string" Selector="$Config/SUPassword$"/>
<OverrideableParameter ID="SUCommand" ParameterType="string" Selector="$Config/SUCommand$"/>
<OverrideableParameter ID="InstallCommand" ParameterType="string" Selector="$Config/InstallCommand$"/>
</OverrideableParameters>
<ModuleImplementation>
<Composite>
<MemberModules>
<WriteAction ID="InstallElevatedAgent" TypeID="System!System.Secure.CommandExecuter">
<ApplicationName>%windir%\system32\cscript.exe</ApplicationName>
<WorkingDirectory/>
<CommandLine>//nologo $file/InstallElevatedAgent.vbs$ $Config/Host$ $Config/Port$ $Config/SUCommand$ $Config/InstallCommand$</CommandLine>
<SecureInput>$Config/UserName$@@secureseparator@@$Config/Password$@@secureseparator@@$Config/SUPassword$</SecureInput>
<TimeoutSeconds>600</TimeoutSeconds>
<RequireOutput>true</RequireOutput>
<Files>
<File>
<Name>InstallElevatedAgent.vbs</Name>
<Contents><Script>
'
' Copyright (c) Microsoft Corporation. All rights reserved.
'
' Exit Codes:
' 0 = Success
' 1 = Failure
'

Option Explicit

' Enable error handling
On Error Resume Next

'----------------------------------------------------------------------------------------------------------------
' Note: This function is duplicated elsewhere; any changes here should be reflected in the other implementations!
Function FixOutput(origStr)
' Create regular expression (set to replace all occurences)
Dim regEx
Set regEx = New RegExp
regEx.Global = True

' Replace all occurences of "\rText" with "\r\nText"
regEx.Pattern = "\r([^\n])" ' Set pattern: \r not followed by \n
FixOutput = regEx.Replace(origStr, vbCrLf + "$1") ' Make replacement: \r\n + following byte

' Make sure all our line endings are Windows standard (\r\n), not just \n
regEx.Pattern = "([^\r])\n"
FixOutput = regEx.Replace(FixOutput, "$1" + vbCrLf)

' Eliminate most non-printable low-byte ASCII characters (avoids OpsMgr XML encoding problems)
' (Keep white space like tab, \r, \n)
regEx.Pattern = "[\x01\x02\x03\x04\x05\x06\x07\x08\x0B\x0C\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F]"
FixOutput = regEx.Replace(FixOutput, "")
End Function

' Note: This function is duplicated elsewhere; any changes here should be reflected in the other implementations!
Function WriteLog(strLogText)
Dim objfs, objf, regEx, logOutput

logOutput = FixOutput(strLogText)
Wscript.Echo logOutput

if (Logging = 1) Then
' Add the Date/Time header to each line
Set regEx = New RegExp
regEx.Global = True
regEx.Pattern = "\r\n"
logOutput = regEx.Replace(logOutput, vbCrLf &amp; "[" &amp; Date &amp; " " &amp; Time &amp; "] ")

Set objfs = CreateObject("Scripting.FileSystemObject")
Set objf = objfs.OpentextFile(TempFolder &amp; "\" &amp; Wscript.ScriptName &amp; ".log", 8, True)
objf.WriteLine("[" &amp; Date &amp; " " &amp; Time &amp; "] " &amp; logOutput)
Set objfs = Nothing
Set objf = Nothing
End If
End Function

Dim Logging, TempFolder
TempFolder = WScript.CreateObject("Scripting.FileSystemObject").GetSpecialFolder(2)
If Wscript.CreateObject("Scripting.FileSystemObject").FileExists(TempFolder &amp; "\EnableOpsMgrModuleLogging") then
Wscript.Echo "Debug: Logging to file '" &amp; TempFolder &amp; "\" &amp; Wscript.ScriptName &amp; ".log'"
Logging = 1
End If
'----------------------------------------------------------------------------------------------------------------

Dim oArgs, SecureInput
Set oArgs = WScript.Arguments
' Split the SecureInput using a fixed string "@@secureseparator@@". Cannot use " " as passwords may contain spaces.
SecureInput = Split(WScript.StdIn.ReadLine(), "@@secureseparator@@")

If (oArgs.Count &lt; 5) OR (UBound(SecureInput) &lt; 2) Then
WScript.Echo "Usage: SSH.vbs Host Port SUCommand Command InstallPackage"
WScript.Echo "Secure Input: Username Password SUPassword"
WScript.Echo "Create file '" &amp; TempFolder &amp; "\EnableOpsMgrModuleLogging' to enable logging"
Wscript.Quit 1
End If

Dim TmpCommand, Host, Username, Password, SUPassword, Port, SUCommand, Command, InstallPackage
Host = oArgs(0)
Port = oArgs(1)
SUCommand = oArgs(2)
Command = oArgs(3)
InstallPackage = oArgs(4)

Username = SecureInput(0)
Password = SecureInput(1)
SUPassword = SecureInput(2)

Dim scxssh
Dim Status, Result

'Create SSH Object
Set scxssh = CreateObject("sshcom.scxssh")

'Set Connection info
scxssh.ConnectWithPassword Host, Port, Username, Password

Dim sStart, sEnd, sCompressionSuffix, sUnCompressCommand, sInstallCommand, sCheckFileCommand, sRemoveCommand

'Check if InstallPackage has compression suffix (only .Z and .gz are supported)
'If InstallPackage is compressed there will be a period "." appended
sStart = InStr(command, InstallPackage &amp; ".")

If sStart &gt; 0 then
If (Mid(command, sStart+Len(InstallPackage), 2)) = ".Z" then
sCompressionSuffix = ".Z"
sUnCompressCommand = Mid(command, 1, sStart+Len(InstallPackage)+1)
sInstallCommand = Mid(command, sStart+Len(InstallPackage)+3, Len(command))
ElseIf (Mid(command, sStart+Len(InstallPackage), 3)) = ".gz" then
sCompressionSuffix = ".gz"
sUnCompressCommand = Mid(command, 1, sStart+Len(InstallPackage)+2)
sInstallCommand = Mid(command, sStart+Len(InstallPackage)+4, Len(command))
Else
WriteLog("Unknown compression suffix, aborting! (" &amp; InstallPackage &amp; ")")
WScript.Quit 1
End If
Else
'InstallPackage is not compressed
sCompressionSuffix=""
sUnCompressCommand=""
sInstallCommand=command
End If

'Add SU prefix to InstallCommand
sInstallCommand = SUCommand &amp; " '" &amp; sInstallCommand &amp; "'"

'Debug printouts
'WScript.Echo "Original Command: " &amp; command &amp; " Len: " &amp; Len(command)
'WScript.Echo "CompressionSuffix: " &amp; sCompressionSuffix &amp; " Len: " &amp; Len(sCompressionSuffix)
'WScript.Echo "UnCompressCommand: " &amp; sUnCompressCommand &amp; " Len: " &amp; Len(sUnCompressCommand)
'WScript.Echo "InstallCommand: " &amp; sInstallCommand &amp; " Len: " &amp; Len(sInstallCommand)

'If file is compressed, decompress it
If sUnCompressCommand &lt;&gt; "" then
WriteLog("Executing command: " &amp; sUnCompressCommand)

Status = 1
' Need to escape \n
Status = scxssh.ExecuteCommand3(Replace(sUnCompressCommand, "\n", "\\n"))
Result = scxssh.GetResponse()
WriteLog(Result)

' Handle Failed Command Execution
If CInt(Status) &lt;&gt; 0 then
WriteLog("Uncompresscommand Failed")
WScript.Quit CInt(Status)
End If
End If

'Open a shell for execution
Status = 1
Status = scxssh.OpenShell()
Result = scxssh.GetResponse()
WriteLog(Result)

' Handle Failed Connection
If CInt(Status) &lt;&gt; 0 then
WriteLog("Failed to connect")
WScript.Quit CInt(Status)
End If

Status = 1
Status = scxssh.ShellCommand3(sInstallCommand)
Result = scxssh.GetResponse()
WriteLog(Result)

' Handle Failed Command Execution
If CInt(Status) &lt;&gt; 0 then
WriteLog("InstallCommand Failed")
WScript.Quit CInt(Status)
End If

If Username &lt;&gt; "root" Then
'Send root password (install command uses 'su')
Status = 1
Status = scxssh.ShellCommand3(SUPassword)
Result = scxssh.GetResponse()
WriteLog(Replace(Result,SUPassword,"&lt;Password&gt;"))

' Handle Failed Command Execution
If CInt(Status) &lt;&gt; 0 then
WriteLog("SUPWCommand Failed")
WScript.Quit CInt(Status)
End If
End If

'Close the Shell and get returncode from install command
Status = 1
Status = scxssh.CloseShell()
Result = scxssh.GetResponse()
WriteLog(Result)

'Remove the staging folder, otherwise next installation may fail if another user is used.
sRemoveCommand = "rm -rf /tmp/scx-" &amp; Username
WriteLog("Executing command: " &amp; sRemoveCommand)
scxssh.ExecuteCommand3 sRemoveCommand
Result = scxssh.GetResponse()
WriteLog(Result)

'Close the SSH session
scxssh.Shutdown()

'Return status from the installation, convert from HResult
WScript.Quit CInt(Status)
</Script></Contents>
<Unicode>1</Unicode>
</File>
</Files>
</WriteAction>
</MemberModules>
<Composition>
<Node ID="InstallElevatedAgent"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.BaseData</OutputType>
<InputType>System!System.BaseData</InputType>
</WriteActionModuleType>