Skip to content

Commit

Permalink
Merge pull request #7 from csvwolf/feat/install.sh
Browse files Browse the repository at this point in the history
feat: install.sh
  • Loading branch information
csvwolf authored Sep 8, 2023
2 parents 26ae49f + 674732c commit 661676a
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 10 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,23 @@ jobs:
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GO_RELEASER_GITHUB_TOKEN }}
docker:
name: Docker
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build and push
uses: docker/build-push-action@v4
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/hostker-ddns:{{github.action_ref}},${{ secrets.DOCKERHUB_USERNAME }}/hostker-ddns:latest,
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
config.json
.idea
dist/
.DS_Store
3 changes: 2 additions & 1 deletion .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ builds:
- linux
- windows
- darwin

ldflags:
- -X github.com/csvwolf/hostker-ddns/command.version={{.Version}}
archives:
- format: tar.gz
# this name template makes the OS and Arch compatible with the results of uname.
Expand Down
13 changes: 9 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
FROM golang:1.21.0
FROM ubuntu:latest

VOLUME $HOME/.hostker/ddns_config.yaml
VOLUME /root/.hostker
## 安装依赖
RUN apt-get update && \
apt-get install -y curl

RUN go get github.com/csvwolf/hostker-ddns
ENTRYPOINT hostker-ddns start
RUN curl -o /tmp/install.sh -L https://raw.githubusercontent.com/csvwolf/hostker-ddns/master/install.sh && \
chmod +x /tmp/install.sh && \
/tmp/install.sh
ENTRYPOINT ["hostker-ddns", "start"]
30 changes: 29 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ Hostker DDNS 方便用户使用 DDNS 到 Hostker 域名解析服务
## 使用

### 安装
现在可以基于 shell 脚本安装依赖了,支持 Mac / Linux;Windows 有 exe,不确定是否可用

```sh
go get github.com/csvwolf/hostker-ddns
curl -o /tmp/install.sh -L https://github.com/csvwolf/hostker-ddns/raw/master/build.sh && \
chmod +x /tmp/install.sh && \
/tmp/install.sh
```

### 初始化
Expand All @@ -26,6 +30,30 @@ hostker-ddns run # 单次运行,可以在平台中确认
hostker-ddns start # 会每分钟跑一次,可以配合 Dockerfile 使用
```

### 在容器中运行

要在容器中运行,你可以使用 `init` 命令初始化,也可以直接建立 `.ddns-config.yaml`

```yaml
# 以下信息都可以在 https://console.hostker.net/index.html#/Domain/manage/[域名] 中找到,如果不清楚,请使用 init
domain: [域名]
email: [登录邮箱]
record:
header: [主机头]
type: [类型,一般是 A 或者 AAAA]
ttl: [TTL]
value: [记录值(IP)]
token: [API 密钥]
```
之后拉镜像并执行
```shell
docker pull csvwolf/hostker-ddns:latest
docker run -d --name ddns --restart=always -v /Users/user/.hostker:/root/.hostker csvwolf/hostker-ddns
```


## DDNS 是个啥
家里的 IP 经常变,想绑个域名的话________,这么说你应该懂了。

2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#/bin/bash

go build -ldflags "-X main.version=$(git describe --tags --abbrev=0)"
go build -ldflags "-X github.com/csvwolf/hostker-ddns/command.version=$(git describe --tags --abbrev=0)"
16 changes: 16 additions & 0 deletions command/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package command

import (
"fmt"
"github.com/spf13/cobra"
)

var version = "unknown"

var VersionCmd = &cobra.Command{
Use: "version",
Short: "Print hostker-ddns version",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("Hostker-DDNS version: ", version)
},
}
55 changes: 55 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/bash

# 检测操作系统类型
unameOut="$(uname -s)"
case "${unameOut}" in
Linux*) machine=Linux;;
Darwin*) machine=Mac;;
CYGWIN*) machine=Cygwin;;
MINGW*) machine=MinGw;;
*) machine="UNKNOWN:${unameOut}"
esac

# 检测机器架构
machineArch="$(uname -m)"
case "${machineArch}" in
armv6l) arch=arm64;;
armv7l) arch=arm64;;
aarch64) arch=arm64;;
x86) arch=x86_64;;
x86_64) arch=x86_64;;
i386) arch=i386;;
*) arch="UNKNOWN:${machineArch}"
esac

# 根据操作系统和架构选择对应的下载链接
fileName=""
case "${machine}" in
Linux)
case "${arch}" in
arm64) fileName="hostker-ddns_Linux_arm64.tar.gz";;
x86_64) fileName="hostker-ddns_Linux_x86_64.tar.gz";;
i386) fileName="hostker-ddns_Linux_i386.tar.gz";;
*) echo "不支持的架构:${arch}" && exit 1;;
esac
;;
Mac)
case "${arch}" in
arm64) fileName="hostker-ddns_Darwin_arm64.tar.gz";;
x86_64) fileName="hostker-ddns_Darwin_x86_64.tar.gz";;
*) echo "不支持的架构:${arch}" && exit 1;;
esac
;;
*)
echo "不支持的操作系统:${machine}" && exit 1;;
esac

# 下载安装包
echo "正在下载安装包...${fileName}"
mkdir -p tmp
curl -sL "https://github.com/csvwolf/hostker-ddns/releases/latest/download/${fileName}" | tar -xzf - -C ./tmp
chmod +x tmp/hostker-ddns # 赋予可执行权限
mv ./tmp/hostker-ddns /usr/local/bin/
rm -rf tmp
# 完成安装
echo "安装完成!"
4 changes: 1 addition & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
"log"
)

var verson string

func main() {

var (
Expand All @@ -23,7 +21,7 @@ func main() {
root.AddCommand(command.InitCmd)
root.AddCommand(command.RunCmd)
root.AddCommand(command.StartCmd)

root.AddCommand(command.VersionCmd)
if err := root.Execute(); err != nil {
log.Fatalln(err)
return
Expand Down

0 comments on commit 661676a

Please sign in to comment.