sumdur: New script, calculates duration for multiple media files
[sunny256-utils.git] / ga-key
blob777a132a57d2ca2657fd5978dd657a0d3f1dac05
1 #!/usr/bin/env bash
3 #=======================================================================
4 # ga-key
5 # File ID: 027211a6-f115-11e4-9e02-000df06acc56
7 # Generate SHA256 sums, use the same format as SHA256 keys in git-annex.
9 # Author: Øyvind A. Holm <sunny@sunbase.org>
10 # License: GNU General Public License version 2 or later.
11 #=======================================================================
13 progname=ga-key
14 VERSION=0.2.0
16 ARGS="$(getopt -o "\
20 " -l "\
21 help,\
22 quiet,\
23 verbose,\
24 version,\
25 " -n "$progname" -- "$@")"
26 test "$?" = "0" || exit 1
27 eval set -- "$ARGS"
29 opt_help=0
30 opt_quiet=0
31 opt_verbose=0
32 while :; do
33 case "$1" in
34 -h|--help) opt_help=1; shift ;;
35 -q|--quiet) opt_quiet=$(($opt_quiet + 1)); shift ;;
36 -v|--verbose) opt_verbose=$(($opt_verbose + 1)); shift ;;
37 --version) echo $progname $VERSION; exit 0 ;;
38 --) shift; break ;;
39 *) echo $progname: Internal error >&2; exit 1 ;;
40 esac
41 done
42 opt_verbose=$(($opt_verbose - $opt_quiet))
44 if test "$opt_help" = "1"; then
45 test $opt_verbose -gt 0 && { echo; echo $progname $VERSION; }
46 cat <<END
48 Generate SHA256 sums, use the format used by the "SHA256" backend in
49 git-annex.
51 Usage: $progname [options] FILE [FILE ...]
53 Options:
55 -h, --help
56 Show this help.
57 -q, --quiet
58 Be more quiet. Can be repeated to increase silence.
59 -v, --verbose
60 Increase level of verbosity. Can be repeated.
61 --version
62 Print version information.
64 END
65 exit 0
68 test -z "$1" && { echo $progname: Missing filename >&2; exit 1; }
70 for file in "$@"; do
71 if test ! -f "$file"; then
72 test $opt_verbose -ge 0 && echo $progname: $file: Ignoring non-file >&2
73 continue
75 echo SHA256-s$(
76 wc -c "$file" | cut -f 1 -d ' '
77 )--$(sha256sum "$file" | head -c 64)
78 done