Set service path to services/name/provider.
This commit is contained in:
parent
63d53f5727
commit
44f3ab6f2f
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
*.swp
|
48
main.go
48
main.go
|
@ -4,6 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
"github.com/hjson/hjson-go/v4"
|
"github.com/hjson/hjson-go/v4"
|
||||||
|
@ -25,11 +26,14 @@ type NetworkingConfig struct {
|
||||||
|
|
||||||
type ServiceConfig struct {
|
type ServiceConfig struct {
|
||||||
Enable string
|
Enable string
|
||||||
Provider string
|
|
||||||
Packages []string
|
|
||||||
Src string
|
Src string
|
||||||
Ports []string
|
Ports []string
|
||||||
Volumes []string
|
Volumes []string
|
||||||
|
|
||||||
|
Provider string
|
||||||
|
Packages []string
|
||||||
|
ConfigFiles []string
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -50,23 +54,19 @@ func main() {
|
||||||
|
|
||||||
// Parse services
|
// Parse services
|
||||||
for name, service := range config.Services {
|
for name, service := range config.Services {
|
||||||
|
var b strings.Builder
|
||||||
var s ServiceConfig
|
var s ServiceConfig
|
||||||
fmt.Printf("Service: %s\n", name)
|
fmt.Printf("Service: %s\n", name)
|
||||||
|
|
||||||
// Read service config file
|
// Read service config file
|
||||||
c, err := os.ReadFile("services/" + name + ".json")
|
if service.Provider == "" { service.Provider = "system" }
|
||||||
|
fmt.Fprintf(&b, "services/%s/%s.json", name, service.Provider)
|
||||||
|
c, err := os.ReadFile(b.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Unknown service: ", err)
|
fmt.Println("Unknown service: ", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read service template file
|
|
||||||
t, err := os.ReadFile("services/" + name + ".template")
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("No template for service: ", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parse service config
|
// Parse service config
|
||||||
err = hjson.Unmarshal(c, &s)
|
err = hjson.Unmarshal(c, &s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -77,12 +77,30 @@ func main() {
|
||||||
config.Services[name] = s
|
config.Services[name] = s
|
||||||
fmt.Printf(" %v\n", s)
|
fmt.Printf(" %v\n", s)
|
||||||
|
|
||||||
tmpl, err := template.New(name).Parse(string(t))
|
// Add service packages to the global list
|
||||||
if err != nil {
|
config.System.Packages = append(config.System.Packages, s.Packages...)
|
||||||
fmt.Println(err)
|
|
||||||
return
|
// Generate a config file
|
||||||
|
for _, f := range s.ConfigFiles {
|
||||||
|
var b strings.Builder
|
||||||
|
f := strings.Split(f, ":")
|
||||||
|
|
||||||
|
// Read service template file
|
||||||
|
fmt.Fprintf(&b, "services/%s/%s", name, f[0])
|
||||||
|
t, err := os.ReadFile(b.String())
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("No template for service: ", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
tmpl, err := template.New(name).Parse(string(t))
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fmt.Printf(" Installing %s to %s\n", f[0], f[1])
|
||||||
|
err = tmpl.Execute(os.Stdout, s)
|
||||||
}
|
}
|
||||||
err = tmpl.Execute(os.Stdout, s)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse package list
|
// Parse package list
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
{
|
{
|
||||||
enable: "true",
|
enable: "true",
|
||||||
|
|
||||||
|
ports: [ "22" ],
|
||||||
|
|
||||||
provider: "system",
|
provider: "system",
|
||||||
packages: [ "openssh-server" ],
|
packages: [ "openssh-server" ],
|
||||||
ports: [ "22" ],
|
configFiles: [
|
||||||
|
"sshd.template:/etc/ssh/sshd_config",
|
||||||
|
]
|
||||||
}
|
}
|
Loading…
Reference in a new issue