all: implement router setup for ddwrt

This commit is contained in:
Cuong Manh Le
2023-03-30 01:41:30 +07:00
committed by Cuong Manh Le
parent c94be0df35
commit 8a2cdbfaa3
18 changed files with 4001 additions and 36 deletions
+4 -7
View File
@@ -12,9 +12,6 @@ import (
var errUCIEntryNotFound = errors.New("uci: Entry not found")
const openwrtDNSMasqConfigPath = "/tmp/dnsmasq.d/ctrld.conf"
const openwrtDNSMasqConfigContent = `# GENERATED BY ctrld - DO NOT MODIFY
port=0
`
func setupOpenWrt() error {
// Delete dnsmasq port if set.
@@ -22,7 +19,7 @@ func setupOpenWrt() error {
return err
}
// Disable dnsmasq as DNS server.
if err := os.WriteFile(openwrtDNSMasqConfigPath, []byte(openwrtDNSMasqConfigContent), 0600); err != nil {
if err := os.WriteFile(openwrtDNSMasqConfigPath, []byte(dnsMasqConfigContent), 0600); err != nil {
return err
}
// Commit.
@@ -30,7 +27,7 @@ func setupOpenWrt() error {
return err
}
// Restart dnsmasq service.
if err := restartDNSMasq(); err != nil {
if err := openwrtRestartDNSMasq(); err != nil {
return err
}
return nil
@@ -42,7 +39,7 @@ func cleanupOpenWrt() error {
return err
}
// Restart dnsmasq service.
if err := restartDNSMasq(); err != nil {
if err := openwrtRestartDNSMasq(); err != nil {
return err
}
return nil
@@ -66,7 +63,7 @@ func uci(args ...string) (string, error) {
return strings.TrimSpace(stdout.String()), nil
}
func restartDNSMasq() error {
func openwrtRestartDNSMasq() error {
if out, err := exec.Command("/etc/init.d/dnsmasq", "restart").CombinedOutput(); err != nil {
return fmt.Errorf("%s: %w", string(out), err)
}