initial commit
This commit is contained in:
commit
5ba52dd285
19 files changed
+639
No files matched your search
@@ -0,0 +1,32 @@
|
||||
package utils
|
||||
|
||||
import "strings"
|
||||
|
||||
func DecodeHosts(input string) map[string]any {
|
||||
result := make(map[string]any)
|
||||
pairs := strings.SplitSeq(input, "\n")
|
||||
|
||||
for pair := range pairs {
|
||||
if pair == "" {
|
||||
continue
|
||||
}
|
||||
kv := strings.Split(pair, " ")
|
||||
if len(kv) == 2 {
|
||||
key := strings.TrimSpace(kv[0])
|
||||
value := strings.TrimSpace(kv[1])
|
||||
if key != "" {
|
||||
result[key] = value
|
||||
}
|
||||
continue
|
||||
}
|
||||
if len(kv) != 0 {
|
||||
key := strings.TrimSpace(kv[0])
|
||||
var value []string
|
||||
for i := 1; i < len(kv); i++ {
|
||||
value = append(value, kv[i])
|
||||
}
|
||||
result[key] = value
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package utils
|
||||
|
||||
import "strings"
|
||||
|
||||
func DecodeResolvs(input string) []string {
|
||||
var result []string
|
||||
pairs := strings.SplitSeq(input, "\n")
|
||||
|
||||
for pair := range pairs {
|
||||
if pair == "" {
|
||||
continue
|
||||
}
|
||||
kv := strings.SplitN(pair, " ", 2)
|
||||
if len(kv) != 2 {
|
||||
continue
|
||||
}
|
||||
value := strings.TrimSpace(kv[1])
|
||||
if value != "" {
|
||||
result = append(result, value)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package utils
|
||||
|
||||
import "strings"
|
||||
|
||||
func DecodeSettings(input string, pairDelim string, kvDelim string) map[string]string {
|
||||
result := make(map[string]string)
|
||||
pairs := strings.SplitSeq(input, pairDelim)
|
||||
|
||||
for pair := range pairs {
|
||||
if pair == "" {
|
||||
continue
|
||||
}
|
||||
kv := strings.SplitN(pair, kvDelim, 2)
|
||||
if len(kv) != 2 {
|
||||
continue
|
||||
}
|
||||
key := strings.TrimSpace(kv[0])
|
||||
value := strings.TrimSpace(kv[1])
|
||||
if key != "" {
|
||||
result[key] = value
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
func RestartDnsmasq() {
|
||||
switch os.Getenv("SYSTEM_INITIALIZATION") {
|
||||
case "rc":
|
||||
exec.Command("rc", "restart", "dnsmasq").Run()
|
||||
case "openrc":
|
||||
exec.Command("rc-service", "dnsmasq", "restart").Run()
|
||||
case "systemd":
|
||||
exec.Command("systemctl", "restart", "dnsmasq").Run()
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user