Files
Gittea-plugin/cmd/ssh.go
Spencer e88f33071e Add newproject command and fix template bugs
- Add newproject, ssh, templates commands for full project scaffolding
- Add homelab SSH, Caddy, port, and proxy_host fields to Config
- Fix dotEnvExample: use container-internal port (3000/8000/8080) not host port
- Fix caddySnippet: use configurable proxy_host instead of localhost
- Fix dockerComposeTemplate: add build: path so image-less deploys work
- Commit gtea.exe binary
2026-05-29 12:37:14 -04:00

38 lines
1.2 KiB
Go

package cmd
import (
"fmt"
"os/exec"
"path"
"strings"
)
// sshRun executes a shell command on the remote host, returning combined output.
// Uses the system ssh binary so existing keys and ~/.ssh/config are honored.
func sshRun(user, host, command string) (string, error) {
c := exec.Command("ssh", "-o", "BatchMode=yes", user+"@"+host, command)
out, err := c.CombinedOutput()
if err != nil {
trimmed := strings.TrimSpace(string(out))
if trimmed != "" {
return string(out), fmt.Errorf("ssh %s@%s: %s: %w", user, host, trimmed, err)
}
return string(out), fmt.Errorf("ssh %s@%s: command failed: %w", user, host, err)
}
return string(out), nil
}
// sshWriteFile writes content to a remote file, creating parent directories.
// Content is streamed via stdin to avoid shell escaping issues.
func sshWriteFile(user, host, remotePath, content string) error {
dir := path.Dir(remotePath)
cmd := fmt.Sprintf("mkdir -p %s && cat > %s", dir, remotePath)
c := exec.Command("ssh", "-o", "BatchMode=yes", user+"@"+host, cmd)
c.Stdin = strings.NewReader(content)
if out, err := c.CombinedOutput(); err != nil {
return fmt.Errorf("writing %s on %s@%s: %s: %w",
remotePath, user, host, strings.TrimSpace(string(out)), err)
}
return nil
}