diff --git a/.goreleaser.yaml b/.goreleaser.yaml index e82d5d0..f2bb004 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -1,9 +1,9 @@ +version: 2 before: hooks: - go mod tidy builds: - - - id: yukid + - id: yukid binary: yukid env: - CGO_ENABLED=0 @@ -16,8 +16,7 @@ builds: - -trimpath ldflags: - -s -w -X github.com/ustclug/Yuki/pkg/info.Version={{.Version}} -X github.com/ustclug/Yuki/pkg/info.BuildDate={{.Date}} -X github.com/ustclug/Yuki/pkg/info.GitCommit={{.Commit}} - - - id: yukictl + - id: yukictl binary: yukictl env: - CGO_ENABLED=0 @@ -30,6 +29,11 @@ builds: - -trimpath ldflags: - -s -w -X github.com/ustclug/Yuki/pkg/info.Version={{.Version}} -X github.com/ustclug/Yuki/pkg/info.BuildDate={{.Date}} -X github.com/ustclug/Yuki/pkg/info.GitCommit={{.Commit}} + hooks: + post: + - cmd: sh -c "{{ .Path }} completion bash > bash_completion" + dir: "{{ dir (dir .Path) }}" + output: true archives: - format: binary name_template: "{{ .Binary }}_{{ .Os }}_{{ .Arch }}" @@ -39,6 +43,33 @@ snapshot: name_template: "{{ incpatch .Version }}-next" changelog: use: github-native +nfpms: + - id: default + package_name: yuki + homepage: https://github.com/ustclug/Yuki + maintainer: "USTC LUG " + description: |- + USTC Mirror Manager + formats: + - deb + umask: 0o022 + dependencies: + - "docker.io | docker-engine | docker-ce" + section: admin + priority: extra + provides: + - yukid + - yukictl + contents: + - src: dist/bash_completion + dst: /etc/bash_completion.d/yukictl + - src: etc/daemon.example.toml + dst: /etc/yuki/ + - src: etc/yukid.service + dst: /lib/systemd/system/ + - src: yukictl + dst: /usr/bin/yuki + type: symlink # modelines, feel free to remove those if you don't want/use them: # yaml-language-server: $schema=https://goreleaser.com/static/schema.json diff --git a/Makefile b/Makefile index 4ffe8e3..2fc3f64 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,13 @@ .PHONY: all all: yukid yukictl +.PHONY: release +release: + goreleaser release --snapshot --clean + .PHONY: clean clean: - rm -f yukid yukictl *.deb + rm -rf yukid yukictl dist/ .PHONY: lint lint: @@ -33,17 +37,3 @@ yukid: .PHONY: yukictl yukictl: go build -ldflags "$(go_ldflags)" -trimpath ./cmd/yukictl - -.PHONY: deb - -deb_dir := $(shell mktemp -d) -deb: | yukid yukictl - install -Dm644 etc/daemon.example.toml -t $(deb_dir)/etc/yuki - install -Dm644 etc/yukid.service -t $(deb_dir)/lib/systemd/system - install -Dm755 yukid yukictl -t $(deb_dir)/usr/local/bin - ln -s yukictl $(deb_dir)/usr/local/bin/yuki - install -d $(addprefix $(deb_dir), /etc/bash_completion.d /DEBIAN) - $(deb_dir)/usr/local/bin/yukictl completion bash > $(deb_dir)/etc/bash_completion.d/yukictl - sed "s/\$$VERSION\>/$(version:v%=%)/g;s/\$$ARCH\>/$(shell go env GOARCH)/g" \ - etc/debian-control > $(deb_dir)/DEBIAN/control - dpkg-deb --root-owner-group --build -Zxz $(deb_dir) . diff --git a/etc/debian-control b/etc/debian-control deleted file mode 100644 index 457fb7d..0000000 --- a/etc/debian-control +++ /dev/null @@ -1,9 +0,0 @@ -Package: yuki -Version: $VERSION -Architecture: $ARCH -Priority: optional -Section: admin -Maintainer: USTC LUG -Homepage: https://github.com/ustclug/Yuki -Depends: docker-engine | docker.io | docker-ce -Description: USTC Mirror Manager diff --git a/etc/postinst.sh b/etc/postinst.sh new file mode 100755 index 0000000..dfea659 --- /dev/null +++ b/etc/postinst.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +# Only run if systemd is running +[ -d /run/systemd ] || exit 0 + +systemctl enable yukid.service diff --git a/etc/yukid.service b/etc/yukid.service index f41e3a3..2157df3 100644 --- a/etc/yukid.service +++ b/etc/yukid.service @@ -8,8 +8,8 @@ ConditionPathExists=/etc/yuki/daemon.toml [Service] Type=exec User=mirror -ExecStart=/usr/local/bin/yukid -ExecReload=/usr/local/bin/yukictl reload +ExecStart=/usr/bin/yukid +ExecReload=/usr/bin/yukictl reload Restart=on-failure RestartSec=5