@@ -3,7 +3,10 @@ package os
33import (
44 "bytes"
55 "fmt"
6+ "io/fs"
67 "os"
8+ "path"
9+ "strconv"
710 "strings"
811 "text/template"
912
@@ -59,6 +62,28 @@ type CmdWithArgs struct {
5962 Cmd string `yaml:"cmd"`
6063 Args []string `yaml:"args"`
6164 SystemCall bool `yaml:"systemCall"`
65+ WriteTo * WriteTo `yaml:"writeTo"`
66+ }
67+
68+ // WriteTo represents the task to write content to file
69+ type WriteTo struct {
70+ File string
71+ Mod string
72+ Content string
73+ }
74+
75+ // Write writes content to file
76+ func (w * WriteTo ) Write () (err error ) {
77+ var mod int
78+ if mod , err = strconv .Atoi (w .Mod ); err != nil {
79+ mod = 0644
80+ }
81+
82+ parent := path .Dir (w .File )
83+ if err = os .MkdirAll (parent , 0644 ); err == nil {
84+ err = os .WriteFile (w .File , []byte (w .Content ), fs .FileMode (mod ))
85+ }
86+ return
6287}
6388
6489func parseGenericPackages (configFile string , genericPackages * genericPackages ) (err error ) {
@@ -172,11 +197,19 @@ func (i *genericPackage) Install() (err error) {
172197 }
173198
174199 if needInstall {
175- preInstall .Cmd .Args = i .sliceReplace (preInstall .Cmd .Args )
176- fmt .Println (preInstall .Cmd .Args )
200+ if preInstall .Cmd .WriteTo != nil {
201+ if err = preInstall .Cmd .WriteTo .Write (); err != nil {
202+ return
203+ }
204+ }
177205
178- if err = i .execer .RunCommand (preInstall .Cmd .Cmd , preInstall .Cmd .Args ... ); err != nil {
179- return
206+ if preInstall .Cmd .Cmd != "" {
207+ preInstall .Cmd .Args = i .sliceReplace (preInstall .Cmd .Args )
208+ fmt .Println (preInstall .Cmd .Args )
209+
210+ if err = i .execer .RunCommand (preInstall .Cmd .Cmd , preInstall .Cmd .Args ... ); err != nil {
211+ return
212+ }
180213 }
181214 }
182215 }
0 commit comments