Files
forge/internal/controller/installer/installer.go
2025-11-27 11:06:38 +08:00

41 lines
918 B
Go

package installer
import (
"context"
"errors"
"os/exec"
"gitea.loveuer.com/yizhisec/pkg3/logger"
)
type installer struct {
workdir string
target string
}
func (i *installer) targetOK(ctx context.Context) error {
if i.target == "" {
logger.Debug("🎯 installer.targetOK: target = self")
return nil
}
// run ssh <target>, check if it's reachable, and it's root user
cmd := exec.CommandContext(ctx, "ssh", i.target, "whoami")
output, err := cmd.CombinedOutput()
if err != nil {
logger.Debug("❌ installer.targetOK: check target %s failed, err = %v", i.target, err)
return err
}
if string(output) != "root\n" {
logger.Debug("❌ installer.targetOK: check target %s failed, output = %s", i.target, string(output))
return errors.New("target is not root user")
}
return nil
}
func NewInstaller(workdir, target string) *installer {
return &installer{workdir: workdir, target: target}
}