Compare commits

...

5 Commits

Author SHA1 Message Date
hedy e504383e4a
Update README to reflect new install instructions 2023-06-19 12:30:21 +08:00
hedy 381097e8e5
Update README for new --version flag 2023-06-19 12:16:37 +08:00
hedy b48fd7633e
Add --version and Makefile etc 2023-06-19 12:15:49 +08:00
hedy b399ace963
Fix 'go install' option for install in READMEs 2023-06-19 10:18:19 +08:00
hedy 2c4c0d81f4
Fix README 2023-06-19 10:10:08 +08:00
9 changed files with 161 additions and 30 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*.out
bin

View File

@ -1,6 +1,6 @@
MIT License
Copyright (c) 2021 Hedy Li
Copyright (c) 2021-2023 hedy
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@ -18,4 +18,4 @@ 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.
SOFTWARE.

59
Makefile Normal file
View File

@ -0,0 +1,59 @@
.PHONY: help build clean build-all package release
.DEFAULT_GOAL := help
pkg_root = .
### Calculate a few variables for use in building
VERSION = $(shell git describe --tags --abbrev=0 --always)
COMMIT = $(shell git log --pretty='format:%h' -n 1)
BUILDDATE = $(shell date +"%Y-%m-%dT%H:%M:%S")
# ldflags inject new values into variables at compilation time
# this is how we dynamically set the version/etc of the application
ldflags = "-X 'main.appVersion=$(VERSION)' \
-X 'main.appCommit=$(COMMIT)' \
-X 'main.buildTime=$(BUILDDATE)' \
-w -s"
##@ Help
help: ## Display this help
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
@echo
@echo "Variable pkg_root is set to . by default. This should be the directory of spsrv source code."
##@ Utilities
init: ## Install utils
go mod download
dep-tidy: ## Remove unused dependencies
go mod tidy
dep-upgrade: ## Upgrade versions of dependencies
go get -u
##@ Build
build: clean ## Build spsrv for your native architecture
go build -o ./bin/spsrv -ldflags=$(ldflags) $(pkg_root)
build-all: clean ## Build spsrv for linux and mac
GOOS=darwin GOARCH=amd64 go build -o ./bin/spsrv-darwin-amd64/spsrv -ldflags=$(ldflags) $(pkg_root)
GOOS=darwin GOARCH=arm64 go build -o ./bin/spsrv-darwin-arm64/spsrv -ldflags=$(ldflags) $(pkg_root)
GOOS=linux GOARCH=amd64 go build -o ./bin/spsrv-linux-amd64/spsrv -ldflags=$(ldflags) $(pkg_root)
GOOS=linux GOARCH=arm64 go build -o ./bin/spsrv-linux-arm64/spsrv -ldflags=$(ldflags) $(pkg_root)
clean: ## Delete any compiled artifacts
rm -rf ./bin
##@ Release
package: build-all ## Build everything and package up arch-specific tarballs
tar czvf ./bin/spsrv-darwin-amd64.tar.gz ./bin/spsrv-darwin-amd64
tar czvf ./bin/spsrv-darwin-arm64.tar.gz ./bin/spsrv-darwin-arm64
tar czvf ./bin/spsrv-linux-amd64.tar.gz ./bin/spsrv-linux-amd64
tar czvf ./bin/spsrv-linux-arm64.tar.gz ./bin/spsrv-linux-arm64
release: package ## Attach packages to sr.ht ref for current tag
./_scripts/release.sh
##@ Test
test: ## Run tests
go test $(shell go list ./...) -coverprofile=coverage.out
# go tool cover -func=coverage.out

View File

@ -17,6 +17,7 @@ Table of Contents
=> #todo todo
Known servers running spsrv
=> spartan://hedy.tilde.cafe:3333
=> spartan://tilde.team
=> spartan://tilde.cafe
@ -26,36 +27,51 @@ Known servers running spsrv
## install
you have two options for now:
you have three options:
### Option 1: with go get
### Option 1: Prebuilt binary
prebuilt binaries for darwin and linux architectures arm/amd-64 are provided since v0.5.4. Head over to the tags page on git.sr.ht, click on a desired tag and download the binary for your architecture.
=> https://git.sr.ht/~hedy/spsrv/refs
### Option 2: with go
first, you need to have go installed and have a folder ~/go with $GOPATH pointing to it.
```
go get git.sr.ht/~hedy/spsrv
go install git.sr.ht/~hedy/spsrv@latest
```
there will be a binary at ~/go/bin/ with the source code at ~/go/src/
feel free to move the binary somewhere else like /usr/sbin/
### Option 2: just build it yourself
note that it's recommended to pin any latest version `@v0.0.0` rather than the latest commit since it may not be stable.
### Option 3: just build it yourself
run git clone https://git.sr.ht/~hedy/spsrv from any directory and cd spsrv
make sure you have go installed and working.
```
git checkout v0.0.0 # optionally pin a specific tag
go build
git checkout v0.0.0 # recommended to pin a specific tag
make build
```
when it finishes, the binary will be in the current directory.
when it finishes, the binary will be in ./bin.
if you don't have make, you can just `go build` (just that version and build information will not be available with `spsrv --version`).
### otherwise...
If you don't have/want go installed, you can contact me, and if you're lucky, I have the same OS as you and you can use my compiled binary (lol). I'll eventually have automated uploads of binaries for various architectures for each release in the future.
if you do not wish to install go or clone the repo, and your architecture is not supported in the prebuilt binaries, drop an email to my public inbox (or contact me privately) so I could perhaps compile a binary for your architecture.
=> mailto:~hedy/inbox@lists.sr.ht public inbox
## configuration
@ -114,7 +130,7 @@ Check out some example configuraton in the examples/ directory.
You can override values in config file if you supply them from the command line:
```
Usage: spsrv [ [ -c <path> -h <hostname> -p <port> -d <path> ] | --help ]
Usage: spsrv [ [ -c <path> -h <hostname> -p <port> -d <path> ] | --help | --version ]
-c, --config string Path to config file
-d, --dir string Root content directory

View File

@ -15,11 +15,16 @@ Known servers running spsrv:
* [earthlight.xyz:3000](https://portal.mozz.us/spartan/earthlight.xyz:3000)
* [jdcard.com:3300](https://portal.mozz.us/spartan/jdcard.com:3300/)
---
**Table of contents**
<!-- vim-markdown-toc GFM -->
* [install](#install)
* [Option 1: with `go get`](#option-1-with-go-get)
* [Option 2: just build it yourself](#option-2-just-build-it-yourself)
* [Option 1: prebuilt binaries](#option-1-prebuilt-binaries)
* [Option 2: with `go install`](#option-2-with-go-install)
* [Option 3: just build it yourself](#option-3-just-build-it-yourself)
* [otherwise...](#otherwise)
* [configuration](#configuration)
* [config options](#config-options)
@ -31,47 +36,61 @@ Known servers running spsrv:
## install
you have two options for now:
you have three options:
### Option 1: with `go get`
### Option 1: prebuilt binaries
prebuilt binaries for darwin and linux architectures arm/amd-64 are provided
since v0.5.4. Head over to the [tags page on
git.sr.ht](https://git.sr.ht/~hedy/spsrv/refs), click on a desired tag and
download the binary for your architecture.
### Option 2: with `go install`
first, you need to have go installed and have a folder `~/go` with `$GOPATH`
pointing to it.
```
go get git.sr.ht/~hedy/spsrv
go install git.sr.ht/~hedy/spsrv@latest
```
there will be a binary at `~/go/bin/` with the source code at `~/go/src/`
feel free to move the binary somewhere else like `/usr/sbin/`
note that it's recommended to pin any latest version `@v0.0.0` rather than the
latest commit since it may not be stable.
### Option 2: just build it yourself
### Option 3: just build it yourself
run `git clone https://git.sr.ht/~hedy/spsrv` from any directory and `cd spsrv`
make sure you have go installed and working.
```
git checkout v0.0.0 # optionally pin a specific tag
go build
git checkout v0.0.0 # recommended to pin a specific tag
make build
```
when it finishes, the binary will be in the current directory.
when it finishes, the binary will be in `./bin`.
if you don't have make, you can just `go build` (just that version and build
information will not be available with `spsrv --version`).
### otherwise...
If you don't have/want go installed, you can contact me, and if you're lucky, I
have the same OS as you and you can use my compiled binary (lol). I'll
eventually have automated uploads of binaries for various architectures for
each release in the future.
if you do not wish to install go or clone the repo, and your architecture is not
supported in the prebuilt binaries, drop an email to my [public
inbox](mailto:~hedy/inbox@lists.sr.ht) (or contact me privately) so I could
perhaps compile a binary for your architecture.
## configuration
The default config file location is `/etc/spsrv.conf` you can specify your own path by running spsrv like
The default config file location is `/etc/spsrv.conf` you can specify your own
path by running spsrv like
```
spsrv -c /path/to/file.conf
@ -118,7 +137,7 @@ Check out some example configuraton in the [examples/](examples/) directory.
You can override values in config file if you supply them from the command line:
```
Usage: spsrv [ [ -c <path> -h <hostname> -p <port> -d <path> ] | --help ]
Usage: spsrv [ [ -c <path> -h <hostname> -p <port> -d <path> ] | --help | --version ]
-c, --config string Path to config file
-d, --dir string Root content directory

20
_scripts/release.sh Executable file
View File

@ -0,0 +1,20 @@
#!/usr/bin/env sh
set -e
git_tag=`git describe --exact-match 2> /dev/null || echo ""`
if [ "$git_tag" != "" ]; then
echo "Releasing $git_tag!"
mv ./bin/spsrv-darwin-amd64.tar.gz ./bin/spsrv-darwin-amd64-$git_tag.tar.gz
mv ./bin/spsrv-darwin-arm64.tar.gz ./bin/spsrv-darwin-arm64-$git_tag.tar.gz
mv ./bin/spsrv-linux-amd64.tar.gz ./bin/spsrv-linux-amd64-$git_tag.tar.gz
mv ./bin/spsrv-linux-arm64.tar.gz ./bin/spsrv-linux-arm64-$git_tag.tar.gz
curl -H"Authorization: token $SRHT_TOKEN" https://git.sr.ht/api/~hedy/repos/spsrv/artifacts/$git_tag -F "file=@./bin/spsrv-darwin-amd64-$git_tag.tar.gz"
curl -H"Authorization: token $SRHT_TOKEN" https://git.sr.ht/api/~hedy/repos/spsrv/artifacts/$git_tag -F "file=@./bin/spsrv-darwin-arm64-$git_tag.tar.gz"
curl -H"Authorization: token $SRHT_TOKEN" https://git.sr.ht/api/~hedy/repos/spsrv/artifacts/$git_tag -F "file=@./bin/spsrv-linux-amd64-$git_tag.tar.gz"
curl -H"Authorization: token $SRHT_TOKEN" https://git.sr.ht/api/~hedy/repos/spsrv/artifacts/$git_tag -F "file=@./bin/spsrv-linux-arm64-$git_tag.tar.gz"
echo ""
echo "DONE!"
else
echo "Non-tagged commit, not releasing!"
fi

2
go.mod
View File

@ -3,6 +3,6 @@ module spsrv
go 1.15
require (
github.com/BurntSushi/toml v0.3.1
github.com/BurntSushi/toml v1.3.2
github.com/spf13/pflag v1.0.5
)

4
go.sum
View File

@ -1,4 +1,4 @@
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8=
github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=

View File

@ -52,13 +52,21 @@ var (
rootDir = flag.StringP("dir", "d", cliDefaultChar, "Root content directory")
confPath = flag.StringP("config", "c", "/etc/spsrv.conf", "Path to config file")
helpFlag = flag.BoolP("help", "?", false, "Get CLI help")
versionFlag = flag.BoolP("version", "v", false, "View version and exit")
)
var (
appVersion = "unknown version"
buildTime = "date unknown"
appCommit = "unknown"
)
func main() {
// Custom usage function because we don't want the "pflag: help requested" message, and
// we don't want to show the default values.
flag.Usage = func() {
fmt.Println(`Usage: spsrv [ [ -c <path> -h <hostname> -p <port> -d <path> ] | --help ]
fmt.Println(`Usage: spsrv [ [ -c <path> -h <hostname> -p <port> -d <path> ] | --help | --version ]
-c, --config string Path to config file
-d, --dir string Root content directory
@ -71,6 +79,13 @@ func main() {
flag.Usage()
return
}
if *versionFlag {
fmt.Printf("spsrv %s, commit %s, built %s", appVersion, appCommit, buildTime)
return
}
conf, err := LoadConfig(*confPath)
if err != nil {
fmt.Println("Error loading config")