diff options
author | Joe <rbo@gmx.us> | 2024-02-02 20:20:20 +0100 |
---|---|---|
committer | Joe <rbo@gmx.us> | 2024-02-02 20:20:20 +0100 |
commit | 9304f9286b2553497b7f9b46a9ed8336e5f7d2e3 (patch) | |
tree | 48f1ba83f6a22b38c059f6ffe3712c30a2711294 /src | |
parent | func pointers yo (diff) | |
download | hardflip-9304f9286b2553497b7f9b46a9ed8336e5f7d2e3.tar.gz hardflip-9304f9286b2553497b7f9b46a9ed8336e5f7d2e3.tar.bz2 hardflip-9304f9286b2553497b7f9b46a9ed8336e5f7d2e3.tar.xz hardflip-9304f9286b2553497b7f9b46a9ed8336e5f7d2e3.tar.zst hardflip-9304f9286b2553497b7f9b46a9ed8336e5f7d2e3.zip |
ok
Diffstat (limited to 'src')
-rw-r--r-- | src/c_exec.go | 59 | ||||
-rw-r--r-- | src/c_lhosts.go | 28 | ||||
-rw-r--r-- | src/c_parse.go | 4 |
3 files changed, 59 insertions, 32 deletions
diff --git a/src/c_exec.go b/src/c_exec.go index 9d36cc8..13e2b16 100644 --- a/src/c_exec.go +++ b/src/c_exec.go @@ -43,7 +43,7 @@ * POSSIBILITY OF SUCH DAMAGE. * * hardflip: src/c_exec.go - * Fri Feb 02 10:09:23 2024 + * Fri Feb 02 11:44:44 2024 * Joe * * exec the command at some point @@ -52,25 +52,32 @@ package main import ( + "bytes" "os" "os/exec" "strconv" "strings" - - "github.com/gdamore/tcell/v2" ) -func c_exec_cmd(cmd_fmt, cmd_env []string) { +func c_exec_cmd(cmd_fmt, cmd_env []string, silent bool) (error, string) { + var errb bytes.Buffer cmd := exec.Command(cmd_fmt[0], cmd_fmt[1:]...) if cmd_env != nil { cmd.Env = os.Environ() cmd.Env = append(cmd.Env, cmd_env...) } - cmd.Stdin = os.Stdin - cmd.Stdout = os.Stdout - cmd.Stderr = os.Stderr - cmd.Run() + if silent == false { + cmd.Stdin = os.Stdin + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + } else { + cmd.Stderr = &errb + } + if err := cmd.Run(); err != nil { + return err, errb.String() + } + return nil, "" } func c_format_ssh_jump(host *HostNode) string { @@ -198,7 +205,7 @@ func c_format_cmd(host *HostNode, opts HardOpts, case 1: cmd_fmt = c_format_rdp(host, pass) case 2: - cmd_fmt = []string{"/bin/sh", "-c", host.Host} + cmd_fmt = append(host.Shell, host.Host) case 3: cmd_fmt, cmd_env = c_format_openstack(host, pass) default: @@ -215,8 +222,6 @@ func c_format_cmd(host *HostNode, opts HardOpts, } func c_exec(host *HostNode, opts HardOpts, ui *HardUI) { - var err error - if host == nil { return } @@ -224,17 +229,33 @@ func c_exec(host *HostNode, opts HardOpts, ui *HardUI) { if cmd_fmt == nil { return } - ui.s.Fini() - c_exec_cmd(cmd_fmt, cmd_env) + silent := false + if host.Protocol == 2 { + silent = host.Silent + } + if silent == false { + if err := ui.s.Suspend(); err != nil { + c_error_mode("screen", err, ui) + return + } + } else { + i_draw_msg(ui.s, 1, ui.style[STYLE_BOX], ui.dim, " Exec ") + text := "running command..." + left, right := i_left_right(len(text), ui) + i_draw_text(ui.s, left, ui.dim[H] - 3, right, ui.dim[H] - 3, + ui.style[STYLE_DEF], text) + ui.s.Show() + } + if err, err_str := c_exec_cmd(cmd_fmt, cmd_env, silent); err != nil { + c_error_mode(err_str, err, ui) + } if opts.Loop == false { + ui.s.Fini() os.Exit(0) - } else { - if ui.s, err = tcell.NewScreen(); err != nil { - c_die("view", err) - } - if err := ui.s.Init(); err != nil { + } else if silent == false { + if err := ui.s.Resume(); err != nil { + ui.s.Fini() c_die("view", err) } - ui.s.SetStyle(ui.style[STYLE_DEF]) } } diff --git a/src/c_lhosts.go b/src/c_lhosts.go index d3e201e..026b65a 100644 --- a/src/c_lhosts.go +++ b/src/c_lhosts.go @@ -77,21 +77,23 @@ type JumpSettings struct { // 2: single cmd // 3: openstack type HostNode struct { - Protocol int8 `yaml:"type"` - Name string `yaml:"name"` - Host string `yaml:"host"` - Port uint16 `yaml:"port"` - User string `yaml:"user"` - Pass string `yaml:"pass"` - Priv string `yaml:"priv"` + Protocol int8 `yaml:"type"` + Name string `yaml:"name"` + Host string `yaml:"host"` + Port uint16 `yaml:"port"` + User string `yaml:"user"` + Pass string `yaml:"pass"` + Priv string `yaml:"priv"` Jump JumpSettings `yaml:"jump"` - Quality uint8 `yaml:"quality"` - Domain string `yaml:"domain"` - Width uint16 `yaml:"width"` - Height uint16 `yaml:"height"` - Dynamic bool `yaml:"dynamic"` - Note string `yaml:"note"` + Quality uint8 `yaml:"quality"` + Domain string `yaml:"domain"` + Width uint16 `yaml:"width"` + Height uint16 `yaml:"height"` + Dynamic bool `yaml:"dynamic"` + Note string `yaml:"note"` Drive map[string]string `yaml:"drive"` + Silent bool `yaml:"silent"` + Shell []string `yaml:"shell"` Stack StackSettings `yaml:"openstack"` Filename string Parent *DirsNode diff --git a/src/c_parse.go b/src/c_parse.go index 9ce5b31..11d1677 100644 --- a/src/c_parse.go +++ b/src/c_parse.go @@ -115,6 +115,10 @@ func c_read_yaml_file(file string, ui *HardUI) (*HostNode, error) { if host.Height == 0 { host.Height = 1200 } + } else if host.Protocol == 2 { + if len(host.Shell) == 0 { + host.Shell = []string{"/bin/sh", "-c"} + } } else if host.Protocol > PROTOCOL_MAX { return nil, errors.New(file + ": unknown protocol") } |