diff --git a/cmd/ctrld/service.go b/cmd/ctrld/service.go index cc42f8b..bce6503 100644 --- a/cmd/ctrld/service.go +++ b/cmd/ctrld/service.go @@ -13,7 +13,8 @@ import ( func newService(s service.Service) service.Service { // TODO: unify for other SysV system. - if router.IsGLiNet() { + switch { + case router.IsGLiNet(), router.IsOldOpenwrt(): return &sysV{s} } return s diff --git a/internal/router/openwrt.go b/internal/router/openwrt.go index 0fbe5f2..afc25ae 100644 --- a/internal/router/openwrt.go +++ b/internal/router/openwrt.go @@ -23,6 +23,16 @@ func IsGLiNet() bool { return bytes.Contains(buf, []byte(" (glinet")) } +// IsOldOpenwrt reports whether the router is an "old" version of Openwrt, +// aka versions which don't have "service" command. +func IsOldOpenwrt() bool { + if Name() != OpenWrt { + return false + } + cmd, _ := exec.LookPath("service") + return cmd == "" +} + func setupOpenWrt() error { // Delete dnsmasq port if set. if _, err := uci("delete", "dhcp.@dnsmasq[0].port"); err != nil && !errors.Is(err, errUCIEntryNotFound) {