init: init
This commit is contained in:
@@ -0,0 +1 @@
|
|||||||
|
*~
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
module github.com/veradec/ensemble
|
||||||
|
|
||||||
|
go 1.25.0
|
||||||
|
|
||||||
|
require github.com/huml-lang/go-huml v0.3.0 // indirect
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
github.com/huml-lang/go-huml v0.3.0 h1:73QiKH2Pvt/pdlXSYM3niKnMjLcvHaroVwHhRxDh008=
|
||||||
|
github.com/huml-lang/go-huml v0.3.0/go.mod h1:13bzEPhjk4jq3E7H/wTPkIRuXtfoTDT4xPuXfMQ8sJc=
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package main
|
||||||
|
import "fmt"
|
||||||
|
func _copy(m interface{}) error {
|
||||||
|
|
||||||
|
data, ok := m.(map[string]interface{})
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("expected map[string]interface{}, got %T", m)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("[COPY] src: %s - dest: %s\n", data["src"], data["dest"])
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package main
|
||||||
|
import "fmt"
|
||||||
|
func _move(m interface{}) error {
|
||||||
|
|
||||||
|
data, ok := m.(map[string]interface{})
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("expected map[string]interface{}, got %T", m)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("[COPY] src: %s - dest: %s\n", data["src"], data["dest"])
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import ("fmt"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
func checkFileExists(path string) bool {
|
||||||
|
_, err := os.Open(path)
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func createFile(path string) bool {
|
||||||
|
f, err := os.Create(path)
|
||||||
|
if err != nil {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
fmt.Printf("[FILE] created `%s`\n", f.Name())
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
func removeFile(path string) bool {
|
||||||
|
err := os.Remove(path)
|
||||||
|
if err != nil {
|
||||||
|
// panic(err)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
fmt.Printf("[FILE] removed `%s`\n", path)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func file(m interface{}) error {
|
||||||
|
data, ok := m.(map[string]interface{})
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("expected map[string]interface{}, got %T", m)
|
||||||
|
}
|
||||||
|
shouldPresent := false
|
||||||
|
|
||||||
|
if data["state"] == "absent" {
|
||||||
|
shouldPresent = false
|
||||||
|
} else if data["state"] == "present"{
|
||||||
|
shouldPresent = true
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
path := data["path"]
|
||||||
|
|
||||||
|
|
||||||
|
if checkFileExists(path.(string)){
|
||||||
|
if shouldPresent {
|
||||||
|
// Skip
|
||||||
|
fmt.Printf("[FILE] %s exists SKIPPING\n", path)
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// Remove File
|
||||||
|
removeFile(path.(string))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if shouldPresent {
|
||||||
|
// Create File
|
||||||
|
createFile(path.(string))
|
||||||
|
} else {
|
||||||
|
// Skip
|
||||||
|
fmt.Printf("[FILE] %s doesn't exist SKIPPING\n", path)
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return nil
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package main
|
||||||
|
import "fmt"
|
||||||
|
func group(m interface{}) error {
|
||||||
|
|
||||||
|
data, ok := m.(map[string]interface{})
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("expected map[string]interface{}, got %T", m)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("[GROUP] name : %s - state: %s\n", data["name"], data["state"])
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package main
|
||||||
|
import "fmt"
|
||||||
|
func user(m interface{}) error {
|
||||||
|
|
||||||
|
data, ok := m.(map[string]interface{})
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("expected map[string]interface{}, got %T", m)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("[USER] name: %s - state: %s - gui: %v\n", data["name"], data["state"], data["uid"])
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
package main
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os/exec"
|
||||||
|
)
|
||||||
|
|
||||||
|
func checkPackageExists(pac string) bool {
|
||||||
|
command := fmt.Sprintf("pacman -Qqe %s", pac)
|
||||||
|
cmd:= exec.Command(command)
|
||||||
|
err:=cmd.Run()
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
func installPackage(pac string) {
|
||||||
|
fmt.Printf("[PACMAN] Installing `%s`\n", pac)
|
||||||
|
}
|
||||||
|
|
||||||
|
func removePackage(pac string){
|
||||||
|
fmt.Printf("[PACMAN] Removing `%s`\n", pac)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func pacman(m interface{}) error {
|
||||||
|
data, ok := m.(map[string]interface{})
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("expected map[string]interface{}, got %T", m)
|
||||||
|
}
|
||||||
|
shouldPresent := false
|
||||||
|
|
||||||
|
if data["state"] == "present" {
|
||||||
|
shouldPresent = true
|
||||||
|
} else if data["state"] == "absent"{
|
||||||
|
shouldPresent = false
|
||||||
|
}
|
||||||
|
|
||||||
|
pac := data["name"]
|
||||||
|
|
||||||
|
if checkPackageExists(pac.(string)) {
|
||||||
|
if shouldPresent {
|
||||||
|
fmt.Printf("[PACMAN] `%s` Exists Skipping\n", pac)
|
||||||
|
} else {
|
||||||
|
removePackage(pac.(string))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if shouldPresent {
|
||||||
|
installPackage(pac.(string))
|
||||||
|
} else {
|
||||||
|
fmt.Printf("[PACMAN] `%s` doesn't exist skipping\n", pac)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/huml-lang/go-huml"
|
||||||
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
|
|
||||||
|
)
|
||||||
|
|
||||||
|
import "helpers"
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
// Read the content from file
|
||||||
|
data, err := ioutil.ReadFile("test.huml")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
} else {
|
||||||
|
fmt.Println("[IO] File Found")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test Huml out
|
||||||
|
var result map[string]any
|
||||||
|
if err := huml.Unmarshal([]byte(data), &result); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Iterate over Tasks
|
||||||
|
if tasks, ok := result["tasks"].(map[string]interface{}); ok {
|
||||||
|
for key, value := range tasks {
|
||||||
|
switch key {
|
||||||
|
case "pacman":
|
||||||
|
pkg.pacman(value)
|
||||||
|
case "file":
|
||||||
|
fileio.file(value)
|
||||||
|
// case "user":
|
||||||
|
// user(value)
|
||||||
|
// case "group":
|
||||||
|
// group(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user