InstallScriptWithOptions installs a script on a Proxmox node via SSH.
(ctx context.Context, opts InstallOptions)
| 830 | |
| 831 | // InstallScriptWithOptions installs a script on a Proxmox node via SSH. |
| 832 | func InstallScriptWithOptions(ctx context.Context, opts InstallOptions) (int, error) { |
| 833 | if opts.User == "" { |
| 834 | return -1, fmt.Errorf("SSH user is required") |
| 835 | } |
| 836 | if opts.Host == "" { |
| 837 | return -1, fmt.Errorf("SSH host is required") |
| 838 | } |
| 839 | if opts.Stdin == nil { |
| 840 | if opts.NonInteractive { |
| 841 | opts.Stdin = strings.NewReader("") |
| 842 | } else { |
| 843 | opts.Stdin = os.Stdin |
| 844 | } |
| 845 | } |
| 846 | if opts.Stdout == nil { |
| 847 | opts.Stdout = os.Stdout |
| 848 | } |
| 849 | if opts.Stderr == nil { |
| 850 | opts.Stderr = os.Stderr |
| 851 | } |
| 852 | |
| 853 | preset := opts.Preset |
| 854 | if opts.NonInteractive && strings.TrimSpace(preset) == "" { |
| 855 | preset = "default" |
| 856 | } |
| 857 | |
| 858 | remoteCmd, err := BuildRemoteInstallCommand(opts.User, opts.Script, opts.Env, preset) |
| 859 | if err != nil { |
| 860 | return -1, err |
| 861 | } |
| 862 | |
| 863 | getScriptsLogger().Debug("Installing script: %s on node %s", opts.Script.ScriptPath, opts.Host) |
| 864 | logRemoteCmd := remoteCmd |
| 865 | if redactedCmd, err := BuildRemoteInstallCommand(opts.User, opts.Script, RedactEnvOverrides(opts.Env), preset); err == nil { |
| 866 | logRemoteCmd = redactedCmd |
| 867 | } |
| 868 | getScriptsLogger().Debug("community-script install via SSH: user=%s host=%s cmd=%s", opts.User, opts.Host, logRemoteCmd) |
| 869 | |
| 870 | sshArgs := ssh.BuildSSHArgs(opts.User, opts.Host, opts.JumpHost) |
| 871 | args := make([]string, 0, len(sshArgs)+4) |
| 872 | if opts.Keyfile != "" { |
| 873 | args = append(args, "-i", opts.Keyfile) |
| 874 | } |
| 875 | if opts.NonInteractive { |
| 876 | args = append(args, "-T") |
| 877 | } else { |
| 878 | args = append(args, "-t") |
| 879 | } |
| 880 | args = append(args, sshArgs...) |
| 881 | args = append(args, remoteCmd) |
| 882 | |
| 883 | // #nosec G204 -- command arguments derive from validated node metadata and trusted plugin configuration. |
| 884 | sshCmd := exec.CommandContext(ctx, "ssh", args...) |
| 885 | |
| 886 | // Connect stdin/stdout/stderr for interactive session |
| 887 | sshCmd.Stdin = opts.Stdin |
| 888 | sshCmd.Stdout = opts.Stdout |
| 889 | sshCmd.Stderr = opts.Stderr |
no test coverage detected