aboutsummaryrefslogtreecommitdiff
path: root/.local/bin/mkchecksums
blob: 5a7ac1f57a0a8b58651bc00365117b74c34d0e32 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#! /usr/bin/env sh

main()
{
	# Handle opts
	opts "$@"
	shift "$OPTS"
	unset OPTS

	# Show help
	[ "$OPT_HELP_ONLY" ] && usage && exit 0
	[ -z "$1" ] && usage && exit 1

	printf "md5    %s\n" "$(md5sum "$1" | cut -f1 -d" ")"
	printf "sha1   %s\n" "$(sha1sum "$1" | cut -f1 -d" ")"
	printf "sha224 %s\n" "$(sha224sum "$1" | cut -f1 -d" ")"
	printf "sha256 %s\n" "$(sha256sum "$1" | cut -f1 -d" ")"
	printf "sha384 %s\n" "$(sha384sum "$1" | cut -f1 -d" ")"
	printf "sha512 %s\n" "$(sha512sum "$1" | cut -f1 -d" ")"
}

opts()
{
	OPTS=0

	while getopts ":h" opt
	do
		case "$opt" in
			h) OPT_HELP_ONLY=1 ;;
			*)
				printf "Invalid option passed: %s\n" "$OPTARG" >&2
				;;
		esac
	done
}

usage()
{
	cat <<EOF
Usage:
	$(basename "$0") -h
	$(basename "$0") <file>

Make a number of checksums of a given file.
EOF
}

main "$@"