test-ly-files: Display symlink creation, add `-v` to `ln`
[sunny256-utils.git] / ga-other
blobce03f18253020a5ce21eb92e3e637c4363edb94f
1 #!/usr/bin/env bash
3 #=======================================================================
4 # ga-other
5 # File ID: 8ccdcd38-f1c3-11e3-96ba-c80aa9e67bbd
7 # Read filenames from stdin and store the git-annex key to
8 # /kopiert-annex/$1. For documenting where I got files from or who I've
9 # given a copy to. If all copies should be destroyed (FSM forbid) I know
10 # where to get another copy. Example:
12 # ls | ga-other Some_Bloke
13 # find -type l | ga-other Another_Bloke
15 # Author: Øyvind A. Holm <sunny@sunbase.org>
16 # License: GNU General Public License version 2 or later.
17 #=======================================================================
19 progname=ga-other
20 VERSION=0.1.0
22 ARGS="$(getopt -o "\
26 " -l "\
27 help,\
28 quiet,\
29 verbose,\
30 version,\
31 " -n "$progname" -- "$@")"
32 test "$?" = "0" || exit 1
33 eval set -- "$ARGS"
35 opt_help=0
36 opt_quiet=0
37 opt_verbose=0
38 while :; do
39 case "$1" in
40 -h|--help) opt_help=1; shift ;;
41 -q|--quiet) opt_quiet=$(($opt_quiet + 1)); shift ;;
42 -v|--verbose) opt_verbose=$(($opt_verbose + 1)); shift ;;
43 --version) echo $progname $VERSION; exit 0 ;;
44 --) shift; break ;;
45 *) echo $progname: Internal error >&2; exit 1 ;;
46 esac
47 done
48 opt_verbose=$(($opt_verbose - $opt_quiet))
50 if test "$opt_help" = "1"; then
51 test $opt_verbose -gt 0 && { echo; echo $progname $VERSION; }
52 cat <<END
54 Read filenames from stdin and store the git-annex key to
55 /kopiert-annex/$1. For documenting where I got files from or who I've
56 given a copy to. If all copies should be destroyed (FSM forbid) I know
57 where to get another copy. Example:
59 ls | ga-other Some_Bloke
60 find -type l | ga-other Another_Bloke
62 Usage: $progname [options]
64 Options:
66 -h, --help
67 Show this help.
68 -q, --quiet
69 Be more quiet. Can be repeated to increase silence.
70 -v, --verbose
71 Increase level of verbosity. Can be repeated.
72 --version
73 Print version information.
75 END
76 exit 0
79 test -z "$1" && { echo $progname: Name not specified >&2; exit 1; }
80 topdir="$(git rev-parse --show-toplevel)"
81 kopidir="$topdir/kopiert-annex"
82 test -d "$kopidir" || mkdir "$kopidir" || \
83 { echo $progname: $kopidir: Cannot create directory >&2; exit 1; }
84 filename="$1.txt"
85 destfile="$kopidir/$filename"
87 while read f; do
88 key=$(git annex lookupkey "$f")
89 test -n "$key" && echo "$key" >>"$destfile"
90 done
92 sort -u "$destfile" >"$destfile.tmp"
93 mv "$destfile.tmp" "$destfile"