Browse Source

Fix runcmd substitution for install script

main
Fábio Kaiser Rauber 4 months ago
parent
commit
882df2ef9d
  1. 12
      main.go

12
main.go

@ -11,10 +11,11 @@ import (
"os"
"os/exec"
"os/user"
"path/filepath"
"strconv"
"strings"
"unicode"
"path/filepath"
"gopkg.in/yaml.v3"
)
@ -190,8 +191,8 @@ func processUserData(configDriveDir string) error {
//write files
for _, file := range cc.WriteFiles {
// Replace "/usr/local" with "/opt" in Path, since Flatcar has read-only /usr
file.Path = strings.Replace(file.Path, "/usr/local", "/opt", -1)
// Replace "/usr/local" with "/opt" in Path, since Flatcar has read-only /usr
file.Path = strings.Replace(file.Path, "/usr/local", "/opt", -1)
// Create directory if it does not exist
dir := filepath.Dir(file.Path)
@ -204,7 +205,7 @@ func processUserData(configDriveDir string) error {
if err != nil {
log.Printf("Invalid file permissions for %s: %s", file.Path, file.Permissions)
}
f, err := os.OpenFile(file.Path, os.O_CREATE|os.O_WRONLY, perm)
if err != nil {
log.Printf("Error creating file: %s", err)
@ -225,8 +226,7 @@ func processUserData(configDriveDir string) error {
// Run commands
for _, cmd := range cc.RunCmd {
cmdArgs := strings.Fields(cmd)
cmdArgs[0] = strings.Replace(cmdArgs[0], "/usr/local/custom_script", "/opt/custom_script", -1)
cmdArgs := strings.Fields(strings.Replace(cmd, "/usr/local/custom_script", "/opt/custom_script", -1))
output, err := exec.Command(cmdArgs[0], cmdArgs[1:]...).CombinedOutput()
if err != nil {
log.Printf("Error running command '%s': %s\n%s", cmd, err, output)

Loading…
Cancel
Save