init: init
This commit is contained in:
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user