package command

import (
	"os/exec"
	"path/filepath"
	"strings"
)

func WriteCfgToFile(content, filePath string) error {
	cmd := "mkdir -p " + filepath.Dir(filePath)
	cmd += " && touch " + filePath
	cmd += " && echo \"" + strings.ReplaceAll(content, "\"", "\\\"") + "\" >" + filePath
	c := exec.Command("/bin/sh", "-c", cmd)
	return c.Run()
}
