dynlay
This commit is contained in:
		| @ -1,53 +0,0 @@ | |||||||
| package main |  | ||||||
|  |  | ||||||
| import ( |  | ||||||
| 	"flag" |  | ||||||
| 	"os" |  | ||||||
| 	"strings" |  | ||||||
|  |  | ||||||
| 	"novit.nc/direktil/inits/pkg/apply" |  | ||||||
| 	"novit.nc/direktil/pkg/config" |  | ||||||
| 	dlog "novit.nc/direktil/pkg/log" |  | ||||||
| ) |  | ||||||
|  |  | ||||||
| var ( |  | ||||||
| 	log = dlog.Get("dkl-apply-config") |  | ||||||
| ) |  | ||||||
|  |  | ||||||
| func main() { |  | ||||||
| 	configPath := flag.String("config", "config.yaml", "config to load (\"-\" for stdin)") |  | ||||||
| 	doFiles := flag.Bool("files", false, "apply files") |  | ||||||
| 	filesFilters := flag.String("files-filters", "", "comma-separated filters to select files to apply") |  | ||||||
| 	flag.Parse() |  | ||||||
|  |  | ||||||
| 	log.SetConsole(os.Stderr) |  | ||||||
|  |  | ||||||
| 	var ( |  | ||||||
| 		cfg *config.Config |  | ||||||
| 		err error |  | ||||||
| 	) |  | ||||||
|  |  | ||||||
| 	if *configPath == "-" { |  | ||||||
| 		log.Print("loading config from stdin") |  | ||||||
| 		cfg, err = config.Read(os.Stdin) |  | ||||||
|  |  | ||||||
| 	} else { |  | ||||||
| 		log.Print("loading config from ", *configPath) |  | ||||||
| 		cfg, err = config.Load(*configPath) |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	if err != nil { |  | ||||||
| 		log.Print("failed to load config: ", err) |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	if *doFiles { |  | ||||||
| 		filters := []string{} |  | ||||||
| 		if *filesFilters != "" { |  | ||||||
| 			filters = strings.Split(*filesFilters, ",") |  | ||||||
| 		} |  | ||||||
| 		if err = apply.Files(cfg /*log,*/, filters...); err != nil { |  | ||||||
| 			log.Taint(dlog.Fatal, "failed to apply files: ", err) |  | ||||||
| 			os.Exit(1) |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
| @ -5,6 +5,7 @@ import ( | |||||||
|  |  | ||||||
| 	"github.com/spf13/cobra" | 	"github.com/spf13/cobra" | ||||||
|  |  | ||||||
|  | 	"novit.nc/direktil/inits/pkg/cmd/applyconfig" | ||||||
| 	cmddynlay "novit.nc/direktil/inits/pkg/cmd/dynlay" | 	cmddynlay "novit.nc/direktil/inits/pkg/cmd/dynlay" | ||||||
| 	cmdinit "novit.nc/direktil/inits/pkg/cmd/init" | 	cmdinit "novit.nc/direktil/inits/pkg/cmd/init" | ||||||
| ) | ) | ||||||
| @ -14,6 +15,7 @@ func main() { | |||||||
|  |  | ||||||
| 	root.AddCommand(cmdinit.Command()) | 	root.AddCommand(cmdinit.Command()) | ||||||
| 	root.AddCommand(cmddynlay.Command()) | 	root.AddCommand(cmddynlay.Command()) | ||||||
|  | 	root.AddCommand(applyconfig.Command()) | ||||||
|  |  | ||||||
| 	if err := root.Execute(); err != nil { | 	if err := root.Execute(); err != nil { | ||||||
| 		log.Fatal("error: ", err) | 		log.Fatal("error: ", err) | ||||||
|  | |||||||
| @ -6,7 +6,7 @@ modd.conf {} | |||||||
|   prep: CGO_ENABLED=0 go build -o dist -trimpath ./cmd/... |   prep: CGO_ENABLED=0 go build -o dist -trimpath ./cmd/... | ||||||
|  |  | ||||||
|   prep: rsync -za --stats dist/dkl bw:/usr/local/bin/ |   prep: rsync -za --stats dist/dkl bw:/usr/local/bin/ | ||||||
|   prep: ssh bw dkl dynlay --url-prefix https://dkl.nwrk.info/dist/layers kubernetes v1.19.4_containerd.1.4.1 |   prep: ssh bw dkl apply-config config.yaml | ||||||
|  |  | ||||||
|   #prep: ./update-test-data |   #prep: ./update-test-data | ||||||
|   #daemon: ./test-vm 1 |   #daemon: ./test-vm 1 | ||||||
|  | |||||||
							
								
								
									
										63
									
								
								pkg/cmd/applyconfig/applyconfig.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										63
									
								
								pkg/cmd/applyconfig/applyconfig.go
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,63 @@ | |||||||
|  | package applyconfig | ||||||
|  |  | ||||||
|  | import ( | ||||||
|  | 	"flag" | ||||||
|  | 	"os" | ||||||
|  | 	"strings" | ||||||
|  |  | ||||||
|  | 	"github.com/spf13/cobra" | ||||||
|  | 	"novit.nc/direktil/inits/pkg/apply" | ||||||
|  | 	"novit.nc/direktil/pkg/config" | ||||||
|  |  | ||||||
|  | 	dlog "novit.nc/direktil/pkg/log" | ||||||
|  | ) | ||||||
|  |  | ||||||
|  | var ( | ||||||
|  | 	filesFilters string | ||||||
|  | 	log          = dlog.Get("dkl") | ||||||
|  | ) | ||||||
|  |  | ||||||
|  | func Command() (c *cobra.Command) { | ||||||
|  | 	c = &cobra.Command{ | ||||||
|  | 		Use:   "apply-config <config.yaml>", | ||||||
|  | 		Short: "apply a config to the current system", | ||||||
|  | 		Args:  cobra.ExactArgs(1), | ||||||
|  |  | ||||||
|  | 		Run: run, | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	flag.StringVar(&filesFilters, "files-filters", "", "comma-separated filters to select files to apply") | ||||||
|  |  | ||||||
|  | 	return c | ||||||
|  | } | ||||||
|  |  | ||||||
|  | func run(_ *cobra.Command, args []string) { | ||||||
|  | 	configPath := args[0] | ||||||
|  |  | ||||||
|  | 	var ( | ||||||
|  | 		cfg *config.Config | ||||||
|  | 		err error | ||||||
|  | 	) | ||||||
|  |  | ||||||
|  | 	if configPath == "-" { | ||||||
|  | 		log.Print("loading config from stdin") | ||||||
|  | 		cfg, err = config.Read(os.Stdin) | ||||||
|  |  | ||||||
|  | 	} else { | ||||||
|  | 		log.Print("loading config from ", configPath) | ||||||
|  | 		cfg, err = config.Load(configPath) | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	if err != nil { | ||||||
|  | 		log.Print("failed to load config: ", err) | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	filters := []string{} | ||||||
|  | 	if filesFilters != "" { | ||||||
|  | 		filters = strings.Split(filesFilters, ",") | ||||||
|  | 	} | ||||||
|  | 	if err = apply.Files(cfg /*log,*/, filters...); err != nil { | ||||||
|  | 		log.Taint(dlog.Fatal, "failed to apply files: ", err) | ||||||
|  | 		os.Exit(1) | ||||||
|  | 	} | ||||||
|  | } | ||||||
| @ -80,9 +80,10 @@ func run(_ *cobra.Command, args []string) { | |||||||
| 		for _, path := range paths { | 		for _, path := range paths { | ||||||
| 			existing[path] = true | 			existing[path] = true | ||||||
|  |  | ||||||
|  | 			target := "/" + path | ||||||
|  |  | ||||||
| 			fmt.Println("linking", path) | 			fmt.Println("linking", path) | ||||||
|  |  | ||||||
| 			target := "/" + path |  | ||||||
| 			os.Remove(target) | 			os.Remove(target) | ||||||
|  |  | ||||||
| 			os.MkdirAll(filepath.Dir(target), 0755) | 			os.MkdirAll(filepath.Dir(target), 0755) | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user