Git/Makefile: Ignore gpstools/, segfault on Linux Mint 19
[sunny256-utils.git] / ga-findkey
blob1879b97b7690bc0e2b6ba89521c9388fcb451b9c
1 #!/usr/bin/env perl
3 #=======================================================================
4 # ga-findkey
5 # File ID: a7e2ddb8-0584-11e5-9395-000df06acc56
7 # Scan stdin or files specified on the command line for SHA256 keys
8 # created by git-annex.
10 # Character set: UTF-8
11 # ©opyleft 2015– Øyvind A. Holm <sunny@sunbase.org>
12 # License: GNU General Public License version 2 or later, see end of
13 # file for legal stuff.
14 #=======================================================================
16 use strict;
17 use warnings;
18 use Getopt::Long;
20 local $| = 1;
22 our %Opt = (
24 'help' => 0,
25 'quiet' => 0,
26 'unique' => 0,
27 'verbose' => 0,
28 'version' => 0,
32 our $progname = $0;
33 $progname =~ s/^.*\/(.*?)$/$1/;
34 our $VERSION = '0.1.0';
36 Getopt::Long::Configure('bundling');
37 GetOptions(
39 'help|h' => \$Opt{'help'},
40 'quiet|q+' => \$Opt{'quiet'},
41 'unique|u' => \$Opt{'unique'},
42 'verbose|v+' => \$Opt{'verbose'},
43 'version' => \$Opt{'version'},
45 ) || die("$progname: Option error. Use -h for help.\n");
47 $Opt{'verbose'} -= $Opt{'quiet'};
48 $Opt{'help'} && usage(0);
49 if ($Opt{'version'}) {
50 print_version();
51 exit(0);
54 my %keys = ();
56 exit(main());
58 sub main {
59 # {{{
60 my $Retval = 0;
62 while (<>) {
63 s/(SHA256-s\d+--[0-9a-f]{64})/print_key($1)/ge;
66 return $Retval;
67 # }}}
68 } # main()
70 sub print_key {
71 # {{{
72 my $key = shift;
73 if ($Opt{'unique'}) {
74 $keys{"$key"} || print("$key\n");
75 $keys{"$key"} = 1;
76 } else {
77 print("$key\n");
79 return('');
80 # }}}
81 } # print_key()
83 sub print_version {
84 # Print program version {{{
85 print("$progname $VERSION\n");
86 return;
87 # }}}
88 } # print_version()
90 sub usage {
91 # Send the help message to stdout {{{
92 my $Retval = shift;
94 if ($Opt{'verbose'}) {
95 print("\n");
96 print_version();
98 print(<<"END");
100 Usage: $progname [options] [file [files [...]]]
102 Scan stdin or files specified on the command line for SHA256 keys
103 created by git-annex.
105 Options:
107 -h, --help
108 Show this help.
109 -q, --quiet
110 Be more quiet. Can be repeated to increase silence.
111 -u, --unique
112 Remove duplicate keys from output, print every key only once.
113 -v, --verbose
114 Increase level of verbosity. Can be repeated.
115 --version
116 Print version information.
119 exit($Retval);
120 # }}}
121 } # usage()
123 sub msg {
124 # Print a status message to stderr based on verbosity level {{{
125 my ($verbose_level, $Txt) = @_;
127 if ($Opt{'verbose'} >= $verbose_level) {
128 print(STDERR "$progname: $Txt\n");
130 return;
131 # }}}
132 } # msg()
134 __END__
136 # This program is free software; you can redistribute it and/or modify
137 # it under the terms of the GNU General Public License as published by
138 # the Free Software Foundation; either version 2 of the License, or (at
139 # your option) any later version.
141 # This program is distributed in the hope that it will be useful, but
142 # WITHOUT ANY WARRANTY; without even the implied warranty of
143 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
144 # See the GNU General Public License for more details.
146 # You should have received a copy of the GNU General Public License
147 # along with this program.
148 # If not, see L<http://www.gnu.org/licenses/>.
150 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :