3 # Purpose: query a signature file for a specific keyword and display results
4 # Authors: grml-team (grml.org), (c) Michael Prokop <mika@grml.org>, (c) Alexander Wirt <formorer@grml.org>
5 # Bug-Reports: see http://grml.org/bugs/
6 # License: This file is licensed under the GPL v2.
7 ################################################################################
20 B<grml-tips> - query a signature file for a specific keyword and display results
24 B<grml-tips> [OPTION] I<searchpattern|tag>
28 This manual page documents briefly the B<grml-tips> command.
36 Print this help and exit.
40 Match on tags only instead of the whole tip
42 =item B<--tipsfile TIPSFILE>
44 Use TIPSFILE instead of /usr/share/grml-tips/grml_tips
52 =item B<grml-tips> I<ntfs>
54 Query grml-tips file for tips / hints including keyword "ntfs".
56 =item B<grml-tips> I<.>
58 Display all available B<grml-tips> at once.
64 /usr/share/grml-tips/grml_tips
66 Signature file containing the tips.
74 grml-tips was written by Alexander Wirt <formorer@grml.org>
78 my $grml_tips = '/usr/share/grml-tips/grml_tips';
84 my $result = GetOptions (
86 "tagsonly" => \$tagsonly,
87 "tipsfile=s" => \$grml_tips,
92 #help if pattern is missing;
94 { -message => 'No search pattern provided',
99 #help if help is wanted
100 pod2usage() if $help;
104 if ( !open( my $fh, '<', "$grml_tips" ) ) {
105 say STDERR "Error: File \"$grml_tips\" not found.";
106 say STDERR "Exiting.";
113 while ( my $line = <$fh> ) {
114 if ( $line !~ /^-- $/ ) {
118 my $header = "Grml Tip Number $tips_found\n";
119 my $line = "-" x ( length($header) - 1 ) . "\n\n";
123 #extract tags from tip
124 my ($tag) = $tip =~ /^Tags: (.*)$/m;
125 my @tags = split(/[, ]+/, $tag);
126 if (grep(/^$pattern$/i, @tags) ) {
127 push @tips, $header . $line . $tip . "\n";
131 if ( $tip =~ /$pattern/mi ) {
132 push @tips, $header . $line . $tip . "\n";
145 if ( !open( my $fh, '|-', 'less -FRX' ) ) {
153 say "Sorry, could not find a tip for '$pattern'. :-(\n\n",
154 "Do you want to submit the keyword '$pattern' to grml's keyword database?\n",
155 "The grml team will write tips for the most requested and useful keywords.\n",
156 "To use and contribute to this feature you'll need a working networking connection.\n",
157 "No personal data will be transmitted to the database.\n\n",
158 "Send \"$pattern\" to grml's keyword database? [y|N] ";
160 ReadMode 4; # Turn off controls keys
162 while ( not defined( $x = ReadKey(-1) ) ) {
163 Time::HiRes::sleep(0.5);
165 ReadMode 0; # Reset tty mode before exiting
167 if ( $x =~ /(y|j)/i ) {
169 if ( -f '/etc/grml_version' ) {
170 open( my $fh, '<', '/etc/grml_version' )
171 or die "Could not open /etc/grml_version: $!";
176 elsif ( -f '/etc/debian_version' ) {
177 open( my $fh, '<', '/etc/debian_version' )
178 or die "Could not open /etc/debian_version: $!";
184 $version = 'unknown';
186 my $ua = new LWP::UserAgent;
187 $ua->agent("grml-tips 0.0 "); # set the HTTP 'browser' type
189 'http://deb.grml.org/~formorer/submissions/keyword.cgi',
190 [ 'version' => $version,
191 'keyword' => $pattern
194 if ( $res->is_success ) {
195 my $content = $res->decoded_content;
196 if ( $content =~ /Submission received/ ) {
198 "Keyword '$pattern' has been submitted to grml's keyword database.\nThanks.";
201 say "Your pattern could not be submitted.\n",
202 "Please file a bug against grml-tips at ",
203 "http://bts.grml.org/\n",
208 print "Could not submitt '$pattern': " . $res->status_line . "\n";
214 "'$pattern' has not been sent to grml's keyword database as requested.\n";
216 "If you want to submit a tip please mail it to tips\@grml.org - thank you!\n";
220 ## END OF FILE #################################################################