Import tool with package adding support and JSON configs.
This commit is contained in:
commit
f9f2413e44
28
goolinux.conf
Normal file
28
goolinux.conf
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
system.packages = [ vim, tmux, go, ];
|
||||||
|
networking = {
|
||||||
|
hostname = "goolinux";
|
||||||
|
domain = "goolinux.org";
|
||||||
|
|
||||||
|
firewall.enable = true;
|
||||||
|
firewall = {
|
||||||
|
allowedPorts = [
|
||||||
|
22, 80, 443,
|
||||||
|
4533,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
services = {
|
||||||
|
ssh.enable = true;
|
||||||
|
proxy.enable = true;
|
||||||
|
|
||||||
|
navidrome.enable = true;
|
||||||
|
navidrome = {
|
||||||
|
# provider = docker;
|
||||||
|
src = deluan/navidrome;
|
||||||
|
ports = [ 4533:4533 ];
|
||||||
|
volumes = [
|
||||||
|
/data/docker/navidrome:/data
|
||||||
|
/data/music:/music:ro
|
||||||
|
];
|
||||||
|
};
|
||||||
|
};
|
28
goolinux.json
Normal file
28
goolinux.json
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
{
|
||||||
|
|
||||||
|
"system": {
|
||||||
|
"packages": [
|
||||||
|
"tmux", "vim", "ripgrep",
|
||||||
|
"go"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
"networking": {
|
||||||
|
},
|
||||||
|
|
||||||
|
"services": {
|
||||||
|
"proxy": { "enable": "true" },
|
||||||
|
"ssh": { "enable": "true" },
|
||||||
|
"navidrome": {
|
||||||
|
"enable": "true",
|
||||||
|
"provider": "docker",
|
||||||
|
"src": "deluan/navidrome",
|
||||||
|
"ports": [ "4533:4533" ],
|
||||||
|
"volumes": [
|
||||||
|
"/data/docker/navidrome:/data",
|
||||||
|
"/data/music:/music:ro"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
72
main.go
Normal file
72
main.go
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
|
||||||
|
"github.com/bitly/go-simplejson"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
var err error
|
||||||
|
|
||||||
|
fd, err := os.Open("goolinux.json")
|
||||||
|
defer fd.Close()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
userJSON, err := simplejson.NewFromReader(fd)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse services
|
||||||
|
services := userJSON.Get("services").MustMap()
|
||||||
|
for service, _ := range services {
|
||||||
|
s := userJSON.Get("services").Get(service).MustMap()
|
||||||
|
if s["enable"] == "false" { continue }
|
||||||
|
|
||||||
|
fmt.Printf("Service: %s\n", service)
|
||||||
|
for key, value := range s {
|
||||||
|
fmt.Printf(" %s: %s\n", key, value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse package list
|
||||||
|
packages := userJSON.Get("system").Get("packages").MustStringArray()
|
||||||
|
fmt.Println(packages)
|
||||||
|
|
||||||
|
// Add extra packages needed
|
||||||
|
// ...
|
||||||
|
|
||||||
|
// Install packages
|
||||||
|
var installString = []string{"add", "--no-interactive", "--no-progress"}
|
||||||
|
var testArgs, args []string
|
||||||
|
var out []byte
|
||||||
|
testArgs = append(installString, "-s")
|
||||||
|
testArgs = append(testArgs, packages...)
|
||||||
|
out, err = exec.Command("/sbin/apk", testArgs...).CombinedOutput()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("===")
|
||||||
|
fmt.Println(err)
|
||||||
|
fmt.Println(string(out))
|
||||||
|
fmt.Println("===")
|
||||||
|
fmt.Println("Error preparing packages")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
args = append(installString, packages...)
|
||||||
|
out, err = exec.Command("/sbin/apk", args...).CombinedOutput()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("===")
|
||||||
|
fmt.Println(err)
|
||||||
|
fmt.Println(string(out))
|
||||||
|
fmt.Println("===")
|
||||||
|
fmt.Println("Error installing packages")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue