From 6e71ec1cf4fed890ee045afb1a18b6475902e2ad Mon Sep 17 00:00:00 2001 From: Lonny Wong Date: Sat, 8 Jun 2024 17:39:11 +0800 Subject: [PATCH] Initial project --- .github/FUNDING.yml | 1 + .github/workflows/gotest.yml | 36 +++++++++++++++++ .github/workflows/publish.yml | 39 ++++++++++++++++++ .gitignore | 9 +++++ .goreleaser.yaml | 74 +++++++++++++++++++++++++++++++++++ LICENSE | 2 +- Makefile | 37 ++++++++++++++++++ README.md | 3 +- cmd/tsshd/main.go | 35 +++++++++++++++++ go.mod | 10 +++++ go.sum | 12 ++++++ tsshd/main.go | 51 ++++++++++++++++++++++++ 12 files changed, 307 insertions(+), 2 deletions(-) create mode 100644 .github/FUNDING.yml create mode 100644 .github/workflows/gotest.yml create mode 100644 .github/workflows/publish.yml create mode 100644 .goreleaser.yaml create mode 100644 Makefile create mode 100644 cmd/tsshd/main.go create mode 100644 go.mod create mode 100644 go.sum create mode 100644 tsshd/main.go diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..6c0e945 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1 @@ +github: trzsz diff --git a/.github/workflows/gotest.yml b/.github/workflows/gotest.yml new file mode 100644 index 0000000..755c0ef --- /dev/null +++ b/.github/workflows/gotest.yml @@ -0,0 +1,36 @@ +name: Go test tsshd +on: [push] +jobs: + go-test-on-linux: + runs-on: ubuntu-latest + steps: + - name: Checkout tsshd + uses: actions/checkout@v4 + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: "1.20" + - name: go test + run: go test -v -count=1 ./tsshd + go-test-on-macos: + runs-on: macos-latest + steps: + - name: Checkout tsshd + uses: actions/checkout@v4 + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: "1.20" + - name: go test + run: go test -v -count=1 ./tsshd + go-test-on-windows: + runs-on: windows-latest + steps: + - name: Checkout tsshd + uses: actions/checkout@v4 + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: "1.20" + - name: go test + run: go test -v -count=1 ./tsshd diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..1debaca --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,39 @@ +name: Release and publish tsshd +on: + release: + types: [released] +jobs: + release-and-publish: + name: Release and publish tsshd + runs-on: ubuntu-latest + steps: + - name: Checkout tsshd + uses: actions/checkout@v4 + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: "1.20" + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v5 + with: + distribution: goreleaser + version: latest + args: release --clean --skip=publish + - name: Upload Release Assets + uses: trzsz/upload-release-assets@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + release_id: ${{ github.event.release.id }} + assets_path: | + dist/*.tar.gz + dist/*.zip + dist/*.rpm + dist/*_checksums.txt + - name: Publish rpm to Gemfury + env: + FURY_TOKEN: ${{ secrets.FURY_TOKEN }} + run: | + for filename in dist/tsshd*.rpm; do + curl -F package=@"$filename" https://{$FURY_TOKEN}@push.fury.io/trzsz/ + done diff --git a/.gitignore b/.gitignore index 6f6f5e6..c4123a9 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,12 @@ # Go workspace file go.work go.work.sum + +bin/ +debian/files + +*.swp +*.swo + +dist/ +vendor/ diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..d3eaaaa --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,74 @@ +project_name: tsshd +before: + hooks: + - go mod tidy +builds: + - id: tsshd + main: ./cmd/tsshd + binary: tsshd + env: + - CGO_ENABLED=0 + goos: + - linux + - windows + - darwin + goarch: + - "386" + - amd64 + - arm + - arm64 + - loong64 + goarm: + - "6" + - "7" + ignore: + - goos: windows + goarch: arm + - goos: darwin + goarch: arm +archives: + - id: tsshd + name_template: >- + {{ .ProjectName }}_ + {{- .Version }}_ + {{- if eq .Os "darwin" }}macos_ + {{- else }}{{ .Os }}_{{ end }} + {{- if eq .Arch "amd64" }}x86_64 + {{- else if eq .Arch "386" }}i386 + {{- else if eq .Arch "arm64" }}aarch64 + {{- else if eq .Arch "arm" }}armv{{ .Arm }} + {{- else }}{{ .Arch }}{{ end }} + wrap_in_directory: true + format_overrides: + - goos: windows + format: zip + files: + - none* +nfpms: + - id: tsshd + builds: + - tsshd + file_name_template: >- + {{ .ProjectName }}_ + {{- .Version }}_ + {{- if eq .Os "darwin" }}macos_ + {{- else }}{{ .Os }}_{{ end }} + {{- if eq .Arch "amd64" }}x86_64 + {{- else if eq .Arch "386" }}i386 + {{- else if eq .Arch "arm64" }}aarch64 + {{- else if eq .Arch "arm" }}armv{{ .Arm }} + {{- else }}{{ .Arch }}{{ end }} + homepage: https://trzsz.github.io/ + maintainer: Lonny Wong + description: |- + The `tssh --udp` works like `mosh`, and the `tsshd` works like `mosh-server`. + license: MIT + formats: + - rpm + bindir: /usr/bin + rpm: + group: Unspecified +snapshot: + name_template: "{{ .Version }}.next" +checksum: + name_template: "{{ .ProjectName }}_{{ .Version }}_checksums.txt" diff --git a/LICENSE b/LICENSE index 66057dd..691a3c5 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2024 trzsz +Copyright (c) 2024 The Trzsz SSH Authors. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..37ca645 --- /dev/null +++ b/Makefile @@ -0,0 +1,37 @@ +BIN_DIR := ./bin +BIN_DST := /usr/bin + +ifdef GOOS + ifeq (${GOOS}, windows) + WIN_TARGET := True + endif +else + ifeq (${OS}, Windows_NT) + WIN_TARGET := True + endif +endif + +ifdef WIN_TARGET + TSSHD := tsshd.exe +else + TSSHD := tsshd +endif + +GO_TEST := ${shell basename `which gotest 2>/dev/null` 2>/dev/null || echo go test} + +.PHONY: all clean test install + +all: ${BIN_DIR}/${TSSHD} + +${BIN_DIR}/${TSSHD}: $(wildcard ./cmd/tsshd/*.go ./tsshd/*.go) go.mod go.sum + go build -o ${BIN_DIR}/ ./cmd/tsshd + +clean: + -rm -f ${BIN_DIR}/tsshd{,.exe} + +test: + ${GO_TEST} -v -count=1 ./tsshd + +install: all + mkdir -p ${DESTDIR}${BIN_DST} + cp ${BIN_DIR}/tsshd ${DESTDIR}${BIN_DST}/ diff --git a/README.md b/README.md index 695269b..40012d4 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,3 @@ # tsshd -The `tssh --udp` works like `mosh`, and the `tsshd` works like `mosh-server`. + +The [`tssh --udp`](https://github.com/trzsz/trzsz-ssh) works like [`mosh`](https://github.com/mobile-shell/mosh), and the `tsshd` works like `mosh-server`. diff --git a/cmd/tsshd/main.go b/cmd/tsshd/main.go new file mode 100644 index 0000000..44de1b5 --- /dev/null +++ b/cmd/tsshd/main.go @@ -0,0 +1,35 @@ +/* +MIT License + +Copyright (c) 2024 The Trzsz SSH Authors. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +package main + +import ( + "os" + + "github.com/trzsz/tsshd/tsshd" +) + +func main() { + os.Exit(tsshd.TsshdMain()) +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..f9f63cc --- /dev/null +++ b/go.mod @@ -0,0 +1,10 @@ +module github.com/trzsz/tsshd + +go 1.20 + +require github.com/trzsz/go-arg v1.5.3 + +require ( + github.com/alexflint/go-scalar v1.2.0 // indirect + github.com/stretchr/testify v1.8.4 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..fd85adb --- /dev/null +++ b/go.sum @@ -0,0 +1,12 @@ +github.com/alexflint/go-scalar v1.2.0 h1:WR7JPKkeNpnYIOfHRa7ivM21aWAdHD0gEWHCx+WQBRw= +github.com/alexflint/go-scalar v1.2.0/go.mod h1:LoFvNMqS1CPrMVltza4LvnGKhaSpc3oyLEBUZVhhS2o= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/trzsz/go-arg v1.5.3 h1:eIDwDEmvSahtr5HpQOLrSa+YMqWQQ0H20xx60XgXQJw= +github.com/trzsz/go-arg v1.5.3/go.mod h1:IC6Z/FiVH7uYvcbp1/gJhDYCFPS/GkL0APYakVvgY4I= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/tsshd/main.go b/tsshd/main.go new file mode 100644 index 0000000..38761e9 --- /dev/null +++ b/tsshd/main.go @@ -0,0 +1,51 @@ +/* +MIT License + +Copyright (c) 2024 The Trzsz SSH Authors. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +package tsshd + +import ( + "fmt" + + "github.com/trzsz/go-arg" +) + +const kTsshdVersion = "0.1.0" + +type tsshdArgs struct { +} + +func (tsshdArgs) Description() string { + return "tsshd works with `tssh --udp`, just like mosh-server.\n" +} + +func (tsshdArgs) Version() string { + return fmt.Sprintf("trzsz sshd %s", kTsshdVersion) +} + +// TsshdMain is the main function of `tsshd` binary. +func TsshdMain() int { + var args tsshdArgs + arg.MustParse(&args) + return 0 +}