This commit is contained in:
parent
a664edaed7
commit
8c633fd4b2
@ -33,7 +33,7 @@ commands:
|
|||||||
Args:
|
Args:
|
||||||
- docker-ce-cli
|
- docker-ce-cli
|
||||||
packageManager: apt
|
packageManager: apt
|
||||||
packageOperation: install
|
packageOperation: upgrade
|
||||||
|
|
||||||
cmd-lists:
|
cmd-lists:
|
||||||
cmds-to-run: # this can be any name you want
|
cmds-to-run: # this can be any name you want
|
||||||
|
@ -45,12 +45,14 @@ func (command *Command) RunCmd(cmdCtxLogger zerolog.Logger, opts *ConfigOpts) ([
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Get the command type
|
||||||
|
// This must be done before concatenating the arguments
|
||||||
|
command = getCommandType(command)
|
||||||
|
|
||||||
for _, v := range command.Args {
|
for _, v := range command.Args {
|
||||||
ArgsStr += fmt.Sprintf(" %s", v)
|
ArgsStr += fmt.Sprintf(" %s", v)
|
||||||
}
|
}
|
||||||
|
|
||||||
command = getCommandType(command)
|
|
||||||
|
|
||||||
if command.Type == "user" {
|
if command.Type == "user" {
|
||||||
if command.UserOperation == "password" {
|
if command.UserOperation == "password" {
|
||||||
cmdCtxLogger.Info().Str("password", command.UserPassword).Msg("user password to be updated")
|
cmdCtxLogger.Info().Str("password", command.UserPassword).Msg("user password to be updated")
|
||||||
@ -60,7 +62,6 @@ func (command *Command) RunCmd(cmdCtxLogger zerolog.Logger, opts *ConfigOpts) ([
|
|||||||
var errSSH error
|
var errSSH error
|
||||||
// is host defined
|
// is host defined
|
||||||
if command.Host != nil {
|
if command.Host != nil {
|
||||||
print("host is defined")
|
|
||||||
outputArr, errSSH = command.RunCmdSSH(cmdCtxLogger, opts)
|
outputArr, errSSH = command.RunCmdSSH(cmdCtxLogger, opts)
|
||||||
if errSSH != nil {
|
if errSSH != nil {
|
||||||
return outputArr, errSSH
|
return outputArr, errSSH
|
||||||
@ -78,7 +79,7 @@ func (command *Command) RunCmd(cmdCtxLogger zerolog.Logger, opts *ConfigOpts) ([
|
|||||||
cmd.Stderr = cmdOutWriters
|
cmd.Stderr = cmdOutWriters
|
||||||
|
|
||||||
if err := cmd.Run(); err != nil {
|
if err := cmd.Run(); err != nil {
|
||||||
return nil, fmt.Errorf("error running command %s policy: %w", ArgsStr, err)
|
return nil, fmt.Errorf("error running command %s: %w", ArgsStr, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return parsePackageVersion(cmdOutBuf.String(), cmdCtxLogger, command, cmdOutBuf)
|
return parsePackageVersion(cmdOutBuf.String(), cmdCtxLogger, command, cmdOutBuf)
|
||||||
@ -98,6 +99,7 @@ func (command *Command) RunCmd(cmdCtxLogger zerolog.Logger, opts *ConfigOpts) ([
|
|||||||
cmdCtxLogger.Info().Str("Command", fmt.Sprintf("Running command %s on local machine", command.Name)).Send()
|
cmdCtxLogger.Info().Str("Command", fmt.Sprintf("Running command %s on local machine", command.Name)).Send()
|
||||||
|
|
||||||
localCMD = exec.Command(command.Cmd, command.Args...)
|
localCMD = exec.Command(command.Cmd, command.Args...)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if command.Dir != nil {
|
if command.Dir != nil {
|
||||||
|
@ -492,7 +492,8 @@ func (command *Command) RunCmdSSH(cmdCtxLogger zerolog.Logger, opts *ConfigOpts)
|
|||||||
env: command.Environment,
|
env: command.Environment,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
// Get the command type
|
||||||
|
// This must be done before concatenating the arguments
|
||||||
command.Type = strings.TrimSpace(command.Type)
|
command.Type = strings.TrimSpace(command.Type)
|
||||||
command = getCommandType(command)
|
command = getCommandType(command)
|
||||||
|
|
||||||
@ -506,7 +507,7 @@ func (command *Command) RunCmdSSH(cmdCtxLogger zerolog.Logger, opts *ConfigOpts)
|
|||||||
Str("Host", *command.Host).
|
Str("Host", *command.Host).
|
||||||
Msgf("Running %s on host %s", getCommandTypeLabel(command.Type), *command.Host)
|
Msgf("Running %s on host %s", getCommandTypeLabel(command.Type), *command.Host)
|
||||||
|
|
||||||
cmdCtxLogger.Debug().Str("cmd", command.Cmd).Strs("args", command.Args).Send()
|
// cmdCtxLogger.Debug().Str("cmd", command.Cmd).Strs("args", command.Args).Send()
|
||||||
|
|
||||||
// Ensure SSH client is connected
|
// Ensure SSH client is connected
|
||||||
if command.RemoteHost.SshClient == nil {
|
if command.RemoteHost.SshClient == nil {
|
||||||
|
@ -259,8 +259,6 @@ func getCommandType(command *Command) *Command {
|
|||||||
case "checkVersion":
|
case "checkVersion":
|
||||||
command.Cmd, command.Args = command.pkgMan.CheckVersion(command.PackageName, command.PackageVersion)
|
command.Cmd, command.Args = command.pkgMan.CheckVersion(command.PackageName, command.PackageVersion)
|
||||||
}
|
}
|
||||||
} else if command.Type != "package" {
|
|
||||||
command.packageCmdSet = false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if command.Type == "user" && !command.userCmdSet {
|
if command.Type == "user" && !command.userCmdSet {
|
||||||
|
@ -40,6 +40,7 @@ func (a *AptManager) Install(pkg, version string, args []string) (string, []stri
|
|||||||
if args != nil {
|
if args != nil {
|
||||||
baseArgs = append(baseArgs, args...)
|
baseArgs = append(baseArgs, args...)
|
||||||
}
|
}
|
||||||
|
fmt.Printf("baseArgs: %v\n", baseArgs)
|
||||||
return baseCmd, baseArgs
|
return baseCmd, baseArgs
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,11 +106,6 @@ func (a *AptManager) SetAuthCommand(authCommand string) {
|
|||||||
a.authCommand = authCommand
|
a.authCommand = authCommand
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetPackageParser assigns a PackageParser.
|
|
||||||
func (a *AptManager) SetPackageParser(parser pkgcommon.PackageParser) {
|
|
||||||
a.Parser = parser
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parse parses the apt-cache policy output to extract Installed and Candidate versions.
|
// Parse parses the apt-cache policy output to extract Installed and Candidate versions.
|
||||||
func (a *AptManager) Parse(output string) (*pkgcommon.PackageVersion, error) {
|
func (a *AptManager) Parse(output string) (*pkgcommon.PackageVersion, error) {
|
||||||
// Check for error message in the output
|
// Check for error message in the output
|
||||||
|
Loading…
Reference in New Issue
Block a user