Add yt-dlp v2021.09.02
[sunny256-utils.git] / ga-key
blob1fc0ade909dc14108720a997e4c3f30d40da679c
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.3.0
16 ARGS="$(getopt -o "\
21 " -l "\
22 filename,\
23 help,\
24 quiet,\
25 verbose,\
26 version,\
27 " -n "$progname" -- "$@")"
28 test "$?" = "0" || exit 1
29 eval set -- "$ARGS"
31 opt_filename=0
32 opt_help=0
33 opt_quiet=0
34 opt_verbose=0
35 while :; do
36 case "$1" in
37 -f|--filename) opt_filename=1; shift ;;
38 -h|--help) opt_help=1; shift ;;
39 -q|--quiet) opt_quiet=$(($opt_quiet + 1)); shift ;;
40 -v|--verbose) opt_verbose=$(($opt_verbose + 1)); shift ;;
41 --version) echo $progname $VERSION; exit 0 ;;
42 --) shift; break ;;
43 *) echo $progname: Internal error >&2; exit 1 ;;
44 esac
45 done
46 opt_verbose=$(($opt_verbose - $opt_quiet))
48 if test "$opt_help" = "1"; then
49 test $opt_verbose -gt 0 && { echo; echo $progname $VERSION; }
50 cat <<END
52 Generate SHA256 sums, use the format used by the "SHA256" backend in
53 git-annex.
55 Usage: $progname [options] FILE [FILE ...]
57 Options:
59 -f, --filename
60 Include filenames in output.
61 -h, --help
62 Show this help.
63 -q, --quiet
64 Be more quiet. Can be repeated to increase silence.
65 -v, --verbose
66 Increase level of verbosity. Can be repeated.
67 --version
68 Print version information.
70 END
71 exit 0
74 test -z "$1" && { echo $progname: Missing filename >&2; exit 1; }
76 for file in "$@"; do
77 if test ! -f "$file"; then
78 test $opt_verbose -ge 0 && echo $progname: $file: Ignoring non-file >&2
79 continue
81 if test "$opt_filename" = "1"; then
82 fname_str=" $file"
83 else
84 fname_str=""
86 echo SHA256-s$(
87 wc -c "$file" | cut -f 1 -d ' '
88 )--$(sha256sum "$file" | head -c 64)$fname_str
89 done