diff --git a/Makefile b/Makefile index 7da89e6..d93d569 100644 --- a/Makefile +++ b/Makefile @@ -1,21 +1,34 @@ SHELL := /usr/bin/env sh TESTS := $(wildcard tests/*.sh) +INSTALL ?= install PREFIX ?= /usr/local BASH_COMP_DIR := $(shell pkg-config --variable=completionsdir bash-completion 2>/dev/null) ifeq ($(BASH_COMP_DIR),) BASH_COMP_DIR = /usr/share/bash-completion/completions endif ZSH_COMP_DIR ?= $(PREFIX)/share/zsh/site-functions +MANDIR ?= $(PREFIX)/share/man +MAN1DIR = $(MANDIR)/man1 -.PHONY: clean install test uninstall +.PHONY: all clean info install install-inline-checksum install-inline-checksum-docs test uninstall + +default: all + +all: info clean: ifneq ($(wildcard tests/*.log),) @printf "Cleaning up test logs.\n" @$(RM) tests/*.log else - @printf "Nothing to clean.\n" + @printf "No test logs to clean.\n" +endif +ifneq ($(wildcard docs/*.1.gz),) + @printf "Cleaning up man pages.\n" + @$(RM) docs/*.1.gz +else + @printf "No man pages to clean.\n" endif test: @@ -32,14 +45,30 @@ test: done; \ [ "$$FAILURE" -eq 0 ] || exit 1 -install: +info: + @help2man ./inline-checksum -o docs/inline-checksum.1 + @gzip docs/inline-checksum.1 + +install: install-inline-checksum install-inline-checksum-info + +install-inline-checksum: @printf "Installing inline-checksum to %s/bin...\n" $(DESTDIR)$(PREFIX) - @install -Dm 755 inline-checksum $(DESTDIR)$(PREFIX)/bin/inline-checksum - @install -Dm 644 inline-checksum-completion $(DESTDIR)$(BASH_COMP_DIR)/inline-checksum - @install -Dm 644 inline-checksum-completion $(DESTDIR)$(ZSH_COMP_DIR)/_inline-checksum + @$(INSTALL) -Dm 755 inline-checksum $(DESTDIR)$(PREFIX)/bin/inline-checksum + +install-inline-checksum-info: info + @printf "Installing inline-checksum bash completion to %s...\n" $(DESTDIR)$(BASH_COMP_DIR) + @$(INSTALL) -Dm 644 docs/inline-checksum-completion $(DESTDIR)$(BASH_COMP_DIR)/inline-checksum + @printf "Installing inline-checksum zsh completion to %s...\n" $(DESTDIR)$(ZSH_COMP_DIR) + @$(INSTALL) -Dm 644 docs/inline-checksum-completion $(DESTDIR)$(ZSH_COMP_DIR)/_inline-checksum + @printf "Installing inline-checksum man page to %s...\n" $(DESTDIR)$(MAN1DIR) + @$(INSTALL) -Dm 644 docs/inline-checksum.1.gz $(DESTDIR)$(MAN1DIR)/inline-checksum.1.gz + -@mandb > /dev/null 2>&1 uninstall: @printf "Uninstalling inline-checksum from %s/bin...\n" $(DESTDIR)$(PREFIX) + @printf "Uninstalling inline-checksum documentation from %s...\n" $(DESTDIR)$(PREFIX) @$(RM) $(DESTDIR)$(PREFIX)/bin/inline-checksum @$(RM) $(DESTDIR)$(BASH_COMP_DIR)/inline-checksum @$(RM) $(DESTDIR)$(ZSH_COMP_DIR)/_inline-checksum + @$(RM) $(DESTDIR)$(MAN1DIR)/inline-checksum.1.gz + -@mandb > /dev/null 2>&1 diff --git a/README.md b/README.md index e687b4b..48c759b 100644 --- a/README.md +++ b/README.md @@ -22,13 +22,13 @@ After running the test suite, you can clean up the generated log files with `mak Assuming a site provides it, a checksum can be used to verify a downloaded script before running it as follows: ```sh -curl -fsSL | inline-checksum [--algorithm[=| ]] | sh - +curl -fsSL | inline-checksum [--algorithm[=| ]] [| sh -] ``` Alternatively, a local file can have its checksum validated as follows: ```sh -inline-checksum [--algorithm[=| ]] +inline-checksum [--algorithm[=| ]] [| sh -] ``` # Uninstallation diff --git a/inline-checksum-completion b/docs/inline-checksum-completion similarity index 100% rename from inline-checksum-completion rename to docs/inline-checksum-completion diff --git a/docs/inline-checksum.1.gz b/docs/inline-checksum.1.gz new file mode 100644 index 0000000..c1a0631 Binary files /dev/null and b/docs/inline-checksum.1.gz differ diff --git a/inline-checksum b/inline-checksum index bde8de7..2af4d47 100755 --- a/inline-checksum +++ b/inline-checksum @@ -55,7 +55,7 @@ # ------------------------------------- # _program_name="$(basename "${0}")" -_version="1.1.2" +_version="1.2.0" usage() { cat <<-EOF @@ -64,18 +64,19 @@ usage() { Usage: ${_program_name} [-h|V] | [-x] [-a[=| ]] [TARGET_FILE] Options: - -h, --help Show this help message and exit. - -V, --version Show version information and exit. - -a, --algorithm The algorithm used to compute the checksum. Accepts one of 'sha256', 'sha512', or 'md5'. Defaults to 'sha256' if unspecified. - -x, --output-filename Output filename when piping, instead of file contents. The caller is responsible for cleaning up any resulting temporary files. - -- Stop processing command line arguments. + -h, --help Show this help message and exit. + -V, --version Show version information and exit. + -a, --algorithm The algorithm used to compute the checksum. Accepts one of 'sha256', 'sha512', or 'md5'. Defaults to 'sha256' if unspecified. + -x, --output-filename Output filename when piping, instead of file contents. The caller is responsible for cleaning up any resulting temporary files. + -- Stop processing command line arguments. Positional Arguments: - The checksum against which to compare. - [TARGET_FILE] The file to compute a checksum for. If absent or '-', reads input from stdin. + The checksum against which to compare. + [TARGET_FILE] The file to compute a checksum for. If absent or '-', reads input from stdin. Examples: - curl -fsSL | inline-checksum [-x] [--algorithm[=| ]] | sh - + curl -fsSL | inline-checksum [-x] [--algorithm[=| ]] [| sh -] + inline-checksum [-x] [--algorithm[=| ]] [| sh -] EOF } @@ -83,7 +84,7 @@ usage() { version() { cat <<-EOF Inline-Checksum ${_version} - Copyright © 2026 Josh Beale . + Copyright (C) 2026 Josh Beale . Licence MIT: This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.