Skip to content

Commit

Permalink
✨ Add Makefile, include commit in version output
Browse files Browse the repository at this point in the history
  • Loading branch information
makew0rld committed Sep 2, 2020
1 parent d0eb382 commit d39b9ee
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 30 deletions.
3 changes: 1 addition & 2 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -9,7 +9,6 @@ env:
before:
hooks:
- go mod download
- go generate ./...

builds:
- env:
Expand Down
54 changes: 54 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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 ./...
19 changes: 9 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <filename>`. 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

Expand Down
43 changes: 25 additions & 18 deletions gemget.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: <status> <meta>\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: <num> <optional-byte-size>\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: <status> <meta>\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: <num> <optional-byte-size>\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
}

Expand Down

0 comments on commit d39b9ee

Please sign in to comment.