package inject import ( "fmt" "os" "path/filepath" ) // Injector writes node config into a mounted image (boot/root paths supplied by caller). type Injector struct { BootPath string RootPath string } // FileSpec describes a file to write. type FileSpec struct { Path string Content []byte Mode os.FileMode RootFS bool // if true, write under root path; else boot path } func (i *Injector) Write(files []FileSpec) error { for _, f := range files { base := i.BootPath if f.RootFS { base = i.RootPath } target := filepath.Join(base, f.Path) if err := os.MkdirAll(filepath.Dir(target), 0o755); err != nil { return fmt.Errorf("mkdir %s: %w", filepath.Dir(target), err) } if err := os.WriteFile(target, f.Content, f.Mode); err != nil { return fmt.Errorf("write %s: %w", target, err) } } return nil }