From d39b9eebc8cdcf84d3afd3fdf27b791b8deb9bb3 Mon Sep 17 00:00:00 2001 From: makeworld Date: Wed, 2 Sep 2020 14:03:30 -0400 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20Makefile,=20include=20commit?= =?UTF-8?q?=20in=20version=20output?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .goreleaser.yml | 3 +-- Makefile | 54 +++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 19 +++++++++-------- gemget.go | 43 ++++++++++++++++++++++----------------- 4 files changed, 89 insertions(+), 30 deletions(-) create mode 100644 Makefile diff --git a/.goreleaser.yml b/.goreleaser.yml index e005808..33e1873 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -1,4 +1,4 @@ -# Copied from Amfora's .goreleaser.yml +# Modified from Amfora's .goreleaser.yml # https://github.com/makeworld-the-better-one/amfora/blob/master/.goreleaser.yml project_name: gemget @@ -9,7 +9,6 @@ env: before: hooks: - go mod download - - go generate ./... builds: - env: diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..463c226 --- /dev/null +++ b/Makefile @@ -0,0 +1,54 @@ +GIT_EXISTS := $(shell git status > /dev/null 2>&1 ; echo $$?) + +ifeq ($(GIT_EXISTS), 0) + ifeq ($(shell git tag --points-at HEAD),) + # Not currently on a tag + VERSION := $(shell git describe --tags | sed 's/-.*/-next/') # v1.2.3-next + else + # On a tag + VERSION := $(shell git tag --points-at HEAD) + endif + + COMMIT := $(shell git rev-parse --verify HEAD) +endif + +INSTALL := install -o root -g root +INSTALL_DIR := /usr/local/bin +DESKTOP_DIR := /usr/share/applications + +.PHONY: all build install desktop clean uninstall fmt + +all: build + +build: +ifneq ($(GIT_EXISTS), 0) + # No Git repo + $(error No Git repo was found, which is needed to compile the commit and version) +endif + @echo "Downloading dependencies" + @go env -w GO111MODULE=on ; go mod download + @echo "Building binary" + @go env -w GO111MODULE=on CGO_ENABLED=0 ; go build -ldflags="-s -w -X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.builtBy=Makefile" + +install: + @echo "Installing Amfora to $(INSTALL_DIR)" + @$(INSTALL) -m 755 amfora $(INSTALL_DIR) + +desktop: + @echo "Setting up desktop file" + @$(INSTALL) -m 644 amfora.desktop $(DESKTOP_DIR) + @update-desktop-database $(DESKTOP_DIR) + +clean: + @echo "Removing Amfora binary in local directory" + @$(RM) amfora + +uninstall: + @echo "Removing Amfora from $(INSTALL_DIR)" + @$(RM) $(INSTALL_DIR)/amfora + @echo "Removing desktop file" + -@$(RM) $(DESKTOP_DIR)/amfora.desktop + -@update-desktop-database $(DESKTOP_DIR) + +fmt: + go fmt ./... diff --git a/README.md b/README.md index fafaa87..9e09409 100644 --- a/README.md +++ b/README.md @@ -45,20 +45,19 @@ Usage of gemget: ``` # Installation -``` -curl -sf https://gobinaries.com/makeworld-the-better-one/gemget | sh -``` -Or install a binary of the most recent release from the [releases page](https://github.com/makeworld-the-better-one/gemget/releases/). +Install a binary of the most recent release from the [releases page](https://github.com/makeworld-the-better-one/gemget/releases/). On Unix-based systems you will have to make the file executable with `chmod +x `. You can rename the file to just `gemget` for easy access, and move it to `/usr/local/bin/`. -If you have Go installed, you can also install it with: -``` -go env -w GO111MODULE=on -go get github.com/makeworld-the-better-one/gemget +If you have Go installed, you can also install it using the Makefile. + +```shell +git clone https://github.com/makeworld-the-better-one/gemget +cd gemget +# git checkout v1.2.3 # Optionally pin to a specific version instead of the latest commit +make +sudo make install # Not for Windows! ``` -Change the last part to say `gemget@master` to install from the latest commit. # Features to add -- Support TOFU with a certificate fingerprint cache, and option to disable it - Support client certificates - Support interactive input for status code 10 & 11 diff --git a/gemget.go b/gemget.go index c0d4f4c..bdc7a7f 100644 --- a/gemget.go +++ b/gemget.go @@ -11,32 +11,39 @@ import ( flag "github.com/spf13/pflag" ) -var version = "1.5.0" +var ( + version = "1.5.0" + commit = "unknown" + builtBy = "unknown" -var insecure = flag.BoolP("insecure", "i", false, "Skip checking the cert\n") -var dir = flag.StringP("directory", "d", ".", "The directory where downloads go") -var output = flag.StringP("output", "o", "", "Output path, for when there is only one URL.\n'-' means stdout and implies --quiet.\nIt overrides --directory.\n") -var errorSkip = flag.BoolP("skip", "s", false, "Move to the next URL when one fails.") -var exts = flag.BoolP("add-extension", "e", false, "Add .gmi extensions to gemini files that don't have it, like directories.\n") -var numRedirs = flag.UintP("redirects", "r", 5, "How many redirects to follow before erroring out.") -var header = flag.Bool("header", false, "Print out (even with --quiet) the response header to stdout in the format:\nHeader: \n") -var verFlag = flag.BoolP("version", "v", false, "Find out what version of gemget you're running.") -var maxSize = flag.StringP("max-size", "m", "", "Set the file size limit. Any download that exceeds this size will\ncause an Info output and be deleted.\nLeaving it blank or setting to zero bytes will result in no limit.\nThis flag is ignored when outputting to stdout.\nFormat: \nExamples: 423, 3.2KiB, '2.5 MB', '22 MiB', '10gib', 3M\n") -var maxSecs = flag.UintP("max-time", "t", 0, "Set the downloading time limit, in seconds. Any download that\ntakes longer will cause an Info output and be deleted.\n") -var inputFilePath = flag.StringP("input-file", "f", "", "Input file with a single URL on each line. Empty lines or lines starting\nwith # are ignored. URLs on the command line will be processed first.\n") -var noBar = flag.Bool("no-progress-bar", false, "Disable the progress bar output.") -var proxy = flag.StringP("proxy", "p", "", "A proxy that can requests are sent to instead.\nCan be a domain or IP with port. Port 1965 is assumed otherwise.\n") -var quiet bool // Set in main, so that it can be changed later if needed + insecure = flag.BoolP("insecure", "i", false, "Skip checking the cert\n") + dir = flag.StringP("directory", "d", ".", "The directory where downloads go") + output = flag.StringP("output", "o", "", "Output path, for when there is only one URL.\n'-' means stdout and implies --quiet.\nIt overrides --directory.\n") + errorSkip = flag.BoolP("skip", "s", false, "Move to the next URL when one fails.") + exts = flag.BoolP("add-extension", "e", false, "Add .gmi extensions to gemini files that don't have it, like directories.\n") + numRedirs = flag.UintP("redirects", "r", 5, "How many redirects to follow before erroring out.") + header = flag.Bool("header", false, "Print out (even with --quiet) the response header to stdout in the format:\nHeader: \n") + verFlag = flag.BoolP("version", "v", false, "Find out what version of gemget you're running.") + maxSize = flag.StringP("max-size", "m", "", "Set the file size limit. Any download that exceeds this size will\ncause an Info output and be deleted.\nLeaving it blank or setting to zero bytes will result in no limit.\nThis flag is ignored when outputting to stdout.\nFormat: \nExamples: 423, 3.2KiB, '2.5 MB', '22 MiB', '10gib', 3M\n") + maxSecs = flag.UintP("max-time", "t", 0, "Set the downloading time limit, in seconds. Any download that\ntakes longer will cause an Info output and be deleted.\n") + inputFilePath = flag.StringP("input-file", "f", "", "Input file with a single URL on each line. Empty lines or lines starting\nwith # are ignored. URLs on the command line will be processed first.\n") + noBar = flag.Bool("no-progress-bar", false, "Disable the progress bar output.") + proxy = flag.StringP("proxy", "p", "", "A proxy that can requests are sent to instead.\nCan be a domain or IP with port. Port 1965 is assumed otherwise.\n") -var maxBytes int64 // After maxSize is parsed this is set -var inputFile *os.File // Global var so it can be closed on fatal errors + quiet bool // Set in main, so that it can be changed later if needed + + maxBytes int64 // After maxSize is parsed this is set + inputFile *os.File // Global var so it can be closed on fatal errors +) func main() { flag.BoolVarP(&quiet, "quiet", "q", false, "Neither info strings or the progress bar will be printed.\nNote that normally infos are printed to stderr, not stdout.\n") flag.Parse() if *verFlag { - fmt.Println("gemget " + version) + fmt.Println("gemget", version) + fmt.Println("Commit:", commit) + fmt.Println("Built by:", builtBy) return }