feat: 🎉 complete maker nginx(app)
This commit is contained in:
@@ -1,8 +1,39 @@
|
||||
package controller
|
||||
package installer
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"os/exec"
|
||||
|
||||
"gitea.loveuer.com/yizhisec/pkg3/logger"
|
||||
)
|
||||
|
||||
type installer struct {
|
||||
target string
|
||||
}
|
||||
|
||||
func NewInstaller() *installer {
|
||||
return &installer{}
|
||||
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(target string) *installer {
|
||||
return &installer{target: target}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user