diff options
author | Quentin Dufour <quentin@deuxfleurs.fr> | 2022-07-19 16:53:55 +0200 |
---|---|---|
committer | Quentin Dufour <quentin@deuxfleurs.fr> | 2022-07-19 16:53:55 +0200 |
commit | aac8ee19d7ef80f437714f882ec8e32b06d00f41 (patch) | |
tree | b6b022091aa6d20d06c7d343a28756af7faad3c9 /nix/builder/install/install.go | |
parent | 9ce0d22c99472534838c1afe7c6dffdd0aa659a8 (diff) | |
download | bottin-aac8ee19d7ef80f437714f882ec8e32b06d00f41.tar.gz bottin-aac8ee19d7ef80f437714f882ec8e32b06d00f41.zip |
Add Nix packaging
Diffstat (limited to 'nix/builder/install/install.go')
-rw-r--r-- | nix/builder/install/install.go | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/nix/builder/install/install.go b/nix/builder/install/install.go new file mode 100644 index 0000000..4f770b0 --- /dev/null +++ b/nix/builder/install/install.go @@ -0,0 +1,57 @@ +package main + +import ( + "fmt" + "go/parser" + "go/token" + "io" + "os" + "os/exec" + "strconv" +) + +const filename = "tools.go" + +func main() { + fset := token.NewFileSet() + + var src []byte + { + f, err := os.Open(filename) + if err != nil { + panic(err) + } + + src, err = io.ReadAll(f) + if err != nil { + panic(err) + } + } + + f, err := parser.ParseFile(fset, filename, src, parser.ImportsOnly) + if err != nil { + fmt.Println(err) + return + } + + for _, s := range f.Imports { + path, err := strconv.Unquote(s.Path.Value) + if err != nil { + panic(err) + } + + cmd := exec.Command("go", "install", path) + + fmt.Printf("Executing '%s'\n", cmd) + + err = cmd.Start() + if err != nil { + panic(err) + } + + err = cmd.Wait() + if err != nil { + panic(err) + } + } +} |