1
0

net-dns/ddns-go: new package, add 5.6.6

This commit is contained in:
Puqns67 2023-12-03 19:50:33 +08:00
parent 0aed0b7638
commit 852821b180
Signed by: Puqns67
GPG Key ID: 9669DF042554F536
9 changed files with 469 additions and 0 deletions

2
net-dns/ddns-go/Manifest Normal file
View File

@ -0,0 +1,2 @@
DIST ddns-go-5.6.6-deps.tar.xz 189936 BLAKE2B 679ace3a66b1fafc1df23557f443fc03445f2a3356dacd5559ab702bb18f10369565733f3ec7860a15246071f36e0aed3be53520cf0b56ca18b35bb3ad21e54a SHA512 42dda58dd1d9fcdc7ebf3875d70c3dc88fa386bae94738a60156931e04cfc62a53d2cbc19145063a1d5fa5b6bc0ef7fad6308dbeab06f9ac03e868b9871cfd59
DIST ddns-go-5.6.6.tar.gz 144632 BLAKE2B 0ce97235bba555d87fbd429348b9091f30eb82bf03e10704f0f667248f6cda83d170382b050a6bc1de1e62b4124a18cb2faf5dd97ca7bb3b023878e7913a0264 SHA512 6c1ca63fc8729d0be48240209aa01e2cac843afe08e8fa9625d25eb481d9c36fd92f9879e4a7e7a67ce6d5612f8b6ea80e48eb709ab5a03cf94d86eb22605780

View File

@ -0,0 +1,45 @@
# Copyright 2023 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
EAPI=8
inherit go-module systemd
DESCRIPTION="简单好用的 DDNS。自动获得你的公网 IPv4 或 IPv6 地址,并解析到对应的域名服务。"
HOMEPAGE="https://github.com/jeessy2/ddns-go"
SRC_URI="https://github.com/jeessy2/ddns-go/archive/refs/tags/v${PV}.tar.gz -> ${P}.tar.gz
https://github.com/Puqns67/gentoo-deps/releases/download/${P}/${P}-deps.tar.xz"
LICENSE="MIT"
SLOT="0"
KEYWORDS="~amd64 ~riscv"
RESTRICT="mirror"
DEPEND=""
RDEPEND="${DEPEND}"
BDEPEND=">=dev-lang/go-1.20"
PATCHES=(
"${FILESDIR}/ddns-go-5.6.6-remove-update-support.patch"
"${FILESDIR}/ddns-go-5.6.6-remove-service-management-support.patch"
)
src_compile() {
ego build \
-trimpath \
-ldflags="-s -w \
-X 'main.version=${PV}' \
-X 'main.buildTime=$(date -u +"%Y-%m-%dT%H:%M:%SZ")'" \
-o ddns-go \
.
}
src_install() {
dobin ddns-go
systemd_dounit "${FILESDIR}/ddns-go.service"
systemd_newunit "${FILESDIR}/ddns-go_at.service" ddns-go@.service
systemd_dounit "${FILESDIR}/ddns-go-web.service"
systemd_newunit "${FILESDIR}/ddns-go-web_at.service" ddns-go-web@.service
keepdir /etc/ddns-go
}

View File

@ -0,0 +1,309 @@
From adf0886cea3b03c1acff3d78054554ad1df46fa0 Mon Sep 17 00:00:00 2001
From: Puqns67 <me@puqns67.icu>
Date: Sun, 3 Dec 2023 11:33:17 +0800
Subject: [PATCH 2/2] build: remove service management support for this build
---
go.mod | 3 -
go.sum | 5 --
main.go | 223 +-------------------------------------------------------
3 files changed, 1 insertion(+), 230 deletions(-)
diff --git a/go.mod b/go.mod
index a70d477..67459b2 100644
--- a/go.mod
+++ b/go.mod
@@ -3,9 +3,6 @@ module github.com/jeessy2/ddns-go/v5
go 1.20
require (
- github.com/kardianos/service v1.2.2
github.com/wagslane/go-password-validator v0.3.0
gopkg.in/yaml.v3 v3.0.1
)
-
-require golang.org/x/sys v0.13.0 // indirect
diff --git a/go.sum b/go.sum
index 36b9ca3..cecce49 100644
--- a/go.sum
+++ b/go.sum
@@ -1,10 +1,5 @@
-github.com/kardianos/service v1.2.2 h1:ZvePhAHfvo0A7Mftk/tEzqEZ7Q4lgnR8sGz4xu1YX60=
-github.com/kardianos/service v1.2.2/go.mod h1:CIMRFEJVL+0DS1a3Nx06NaMn4Dz63Ng6O7dl0qH0zVM=
github.com/wagslane/go-password-validator v0.3.0 h1:vfxOPzGHkz5S146HDpavl0cw1DSVP061Ry2PX0/ON6I=
github.com/wagslane/go-password-validator v0.3.0/go.mod h1:TI1XJ6T5fRdRnHqHt14pvy1tNVnrwe7m3/f1f2fDphQ=
-golang.org/x/sys v0.0.0-20201015000850-e3ed0017c211/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
-golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
-golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
diff --git a/main.go b/main.go
index 4896399..78c848f 100644
--- a/main.go
+++ b/main.go
@@ -8,7 +8,6 @@ import (
"net"
"net/http"
"os"
- "os/exec"
"path/filepath"
"strconv"
"time"
@@ -17,7 +16,6 @@ import (
"github.com/jeessy2/ddns-go/v5/dns"
"github.com/jeessy2/ddns-go/v5/util"
"github.com/jeessy2/ddns-go/v5/web"
- "github.com/kardianos/service"
)
// ddns-go 版本
@@ -33,9 +31,6 @@ var every = flag.Int("f", 300, "同步间隔时间(秒)")
// 缓存次数
var ipCacheTimes = flag.Int("cacheTimes", 5, "间隔N次与服务商比对")
-// 服务管理
-var serviceType = flag.String("s", "", "服务管理, 支持install, uninstall, restart")
-
// 配置文件路径
var configFilePath = flag.String("c", util.GetConfigFilePathDefault(), "自定义配置文件路径")
@@ -78,34 +73,7 @@ func main() {
util.NewDialerResolver(*customDNSServer + ":53")
}
os.Setenv(util.IPCacheTimesENV, strconv.Itoa(*ipCacheTimes))
- switch *serviceType {
- case "install":
- installService()
- case "uninstall":
- uninstallService()
- case "restart":
- restartService()
- default:
- if util.IsRunInDocker() {
- run()
- } else {
- s := getService()
- status, _ := s.Status()
- if status != service.StatusUnknown {
- // 以服务方式运行
- s.Run()
- } else {
- // 非服务方式运行
- switch s.Platform() {
- case "windows-service":
- log.Println("可使用 .\\ddns-go.exe -s install 安装服务运行")
- default:
- log.Println("可使用 sudo ./ddns-go -s install 安装服务运行")
- }
- run()
- }
- }
- }
+ run()
}
func run() {
@@ -163,131 +131,6 @@ func runWebServer() error {
return http.Serve(l, nil)
}
-type program struct{}
-
-func (p *program) Start(s service.Service) error {
- // Start should not block. Do the actual work async.
- go p.run()
- return nil
-}
-func (p *program) run() {
- run()
-}
-func (p *program) Stop(s service.Service) error {
- // Stop should not block. Return with a few seconds.
- return nil
-}
-
-func getService() service.Service {
- options := make(service.KeyValue)
- var depends []string
-
- // 确保服务等待网络就绪后再启动
- switch service.ChosenSystem().String() {
- case "unix-systemv":
- options["SysvScript"] = sysvScript
- case "windows-service":
- // 将 Windows 服务的启动类型设为自动(延迟启动)
- options["DelayedAutoStart"] = true
- default:
- // 向 Systemd 添加网络依赖
- depends = append(depends, "Requires=network.target",
- "After=network-online.target")
- }
-
- svcConfig := &service.Config{
- Name: "ddns-go",
- DisplayName: "ddns-go",
- Description: "简单好用的DDNS。自动更新域名解析到公网IP(支持阿里云、腾讯云dnspod、Cloudflare、Callback、华为云、百度云、Porkbun、GoDaddy、Google Domain)",
- Arguments: []string{"-l", *listen, "-f", strconv.Itoa(*every), "-cacheTimes", strconv.Itoa(*ipCacheTimes), "-c", *configFilePath},
- Dependencies: depends,
- Option: options,
- }
-
- if *noWebService {
- svcConfig.Arguments = append(svcConfig.Arguments, "-noweb")
- }
-
- if *skipVerify {
- svcConfig.Arguments = append(svcConfig.Arguments, "-skipVerify")
- }
-
- if *customDNSServer != "" {
- svcConfig.Arguments = append(svcConfig.Arguments, "-dns", *customDNSServer)
- }
-
- prg := &program{}
- s, err := service.New(prg, svcConfig)
- if err != nil {
- log.Fatalln(err)
- }
- return s
-}
-
-// 卸载服务
-func uninstallService() {
- s := getService()
- s.Stop()
- if service.ChosenSystem().String() == "unix-systemv" {
- if _, err := exec.Command("/etc/init.d/ddns-go", "stop").Output(); err != nil {
- log.Println(err)
- }
- }
- if err := s.Uninstall(); err == nil {
- log.Println("ddns-go 服务卸载成功!")
- } else {
- log.Printf("ddns-go 服务卸载失败, ERR: %s\n", err)
- }
-}
-
-// 安装服务
-func installService() {
- s := getService()
-
- status, err := s.Status()
- if err != nil && status == service.StatusUnknown {
- // 服务未知,创建服务
- if err = s.Install(); err == nil {
- s.Start()
- log.Println("安装 ddns-go 服务成功! 请打开浏览器并进行配置。")
- if service.ChosenSystem().String() == "unix-systemv" {
- if _, err := exec.Command("/etc/init.d/ddns-go", "enable").Output(); err != nil {
- log.Println(err)
- }
- if _, err := exec.Command("/etc/init.d/ddns-go", "start").Output(); err != nil {
- log.Println(err)
- }
- }
- return
- }
-
- log.Printf("安装 ddns-go 服务失败, ERR: %s\n", err)
- }
-
- if status != service.StatusUnknown {
- log.Println("ddns-go 服务已安装, 无需再次安装")
- }
-}
-
-// 重启服务
-func restartService() {
- s := getService()
- status, err := s.Status()
- if err == nil {
- if status == service.StatusRunning {
- if err = s.Restart(); err == nil {
- log.Println("重启 ddns-go 服务成功!")
- }
- } else if status == service.StatusStopped {
- if err = s.Start(); err == nil {
- log.Println("启动 ddns-go 服务成功!")
- }
- }
- } else {
- log.Println("ddns-go 服务未安装, 请先安装服务")
- }
-}
-
// 打开浏览器
func autoOpenExplorer() {
_, err := config.GetConfigCached()
@@ -310,67 +153,3 @@ func autoOpenExplorer() {
}
}
}
-
-const sysvScript = `#!/bin/sh /etc/rc.common
-DESCRIPTION="{{.Description}}"
-cmd="{{.Path}}{{range .Arguments}} {{.|cmd}}{{end}}"
-name="ddns-go"
-pid_file="/var/run/$name.pid"
-stdout_log="/var/log/$name.log"
-stderr_log="/var/log/$name.err"
-START=99
-get_pid() {
- cat "$pid_file"
-}
-is_running() {
- [ -f "$pid_file" ] && cat /proc/$(get_pid)/stat > /dev/null 2>&1
-}
-start() {
- if is_running; then
- echo "Already started"
- else
- echo "Starting $name"
- {{if .WorkingDirectory}}cd '{{.WorkingDirectory}}'{{end}}
- $cmd >> "$stdout_log" 2>> "$stderr_log" &
- echo $! > "$pid_file"
- if ! is_running; then
- echo "Unable to start, see $stdout_log and $stderr_log"
- exit 1
- fi
- fi
-}
-stop() {
- if is_running; then
- echo -n "Stopping $name.."
- kill $(get_pid)
- for i in $(seq 1 10)
- do
- if ! is_running; then
- break
- fi
- echo -n "."
- sleep 1
- done
- echo
- if is_running; then
- echo "Not stopped; may still be shutting down or shutdown may have failed"
- exit 1
- else
- echo "Stopped"
- if [ -f "$pid_file" ]; then
- rm "$pid_file"
- fi
- fi
- else
- echo "Not running"
- fi
-}
-restart() {
- stop
- if is_running; then
- echo "Unable to stop, will not attempt to start"
- exit 1
- fi
- start
-}
-`
--
2.43.0

View File

@ -0,0 +1,45 @@
From 01f9502e859a68e4084cd9347b63b62a4183a26b Mon Sep 17 00:00:00 2001
From: Puqns67 <me@puqns67.icu>
Date: Sun, 3 Dec 2023 17:17:25 +0800
Subject: [PATCH 1/2] build: remove update support for this build
---
main.go | 8 --------
1 file changed, 8 deletions(-)
diff --git a/main.go b/main.go
index 1272697..4896399 100644
--- a/main.go
+++ b/main.go
@@ -16,7 +16,6 @@ import (
"github.com/jeessy2/ddns-go/v5/config"
"github.com/jeessy2/ddns-go/v5/dns"
"github.com/jeessy2/ddns-go/v5/util"
- "github.com/jeessy2/ddns-go/v5/util/update"
"github.com/jeessy2/ddns-go/v5/web"
"github.com/kardianos/service"
)
@@ -25,9 +24,6 @@ import (
// ddns-go version
var versionFlag = flag.Bool("v", false, "ddns-go 版本")
-// 更新 ddns-go
-var updateFlag = flag.Bool("u", false, "更新 ddns-go")
-
// 监听地址
var listen = flag.String("l", ":9876", "监听地址")
@@ -67,10 +63,6 @@ func main() {
fmt.Println(version)
return
}
- if *updateFlag {
- update.Self(version)
- return
- }
if _, err := net.ResolveTCPAddr("tcp", *listen); err != nil {
log.Fatalf("解析监听地址异常,%s", err)
}
--
2.43.0

View File

@ -0,0 +1,14 @@
[Unit]
Description=DDNS-GO with default config, and web user interface
Requires=network.target
After=network-online.target
Conflicts=ddns-go.service ddns-go@config.service ddns-go-web@config.service
[Service]
Type=simple
ExecStart=/usr/bin/ddns-go -c /etc/ddns-go/config.yaml
Restart=on-failure
RestartSec=60
[Install]
WantedBy=multi-user.target

View File

@ -0,0 +1,14 @@
[Unit]
Description=DDNS-GO with config %i, and web user interface
Requires=network.target
After=network-online.target
Conflicts=ddns-go.service ddns-go-web.service ddns-go@%i.service
[Service]
Type=simple
ExecStart=/usr/bin/ddns-go -c /etc/ddns-go/%i.yaml
Restart=on-failure
RestartSec=60
[Install]
WantedBy=multi-user.target

View File

@ -0,0 +1,14 @@
[Unit]
Description=DDNS-GO with default config
Requires=network.target
After=network-online.target
Conflicts=ddns-go@config.service ddns-go-web.service ddns-go-web@config.service
[Service]
Type=simple
ExecStart=/usr/bin/ddns-go -noweb -c /etc/ddns-go/config.yaml
Restart=on-failure
RestartSec=60
[Install]
WantedBy=multi-user.target

View File

@ -0,0 +1,14 @@
[Unit]
Description=DDNS-GO with config %i
Requires=network.target
After=network-online.target
Conflicts=ddns-go.service ddns-go-web.service ddns-go-web@%i.service
[Service]
Type=simple
ExecStart=/usr/bin/ddns-go -noweb -c /etc/ddns-go/%i.yaml
Restart=on-failure
RestartSec=60
[Install]
WantedBy=multi-user.target

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE pkgmetadata SYSTEM "https://www.gentoo.org/dtd/metadata.dtd">
<pkgmetadata>
<maintainer type="person">
<email>me@puqns67.icu</email>
<name>Puqns67</name>
</maintainer>
<upstream>
<bugs-to>https://github.com/jeessy2/ddns-go/issues</bugs-to>
<remote-id type="github">jeessy2/ddns-go</remote-id>
</upstream>
</pkgmetadata>