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
48 =item B<grml-tips> I<ntfs>
50 Query grml-tips file for tips / hints including keyword "ntfs".
52 =item B<grml-tips> I<.>
54 Display all available B<grml-tips> at once.
60 /usr/share/grml-tips/grml_tips
62 Signature file containing the tips.
70 grml-tips was written by Alexander Wirt <formorer@grml.org>
74 my $grml_tips = '/usr/share/grml-tips/grml_tips';
79 my $result = GetOptions (
81 "tagsonly" => \$tagsonly
86 #help if pattern is missing;
88 { -message => 'No search pattern provided',
93 #help if help is wanted
98 if ( !open( my $fh, '<', "$grml_tips" ) ) {
99 say STDERR "Error: File \"$grml_tips\" not found.";
100 say STDERR "Exiting.";
107 while ( my $line = <$fh> ) {
108 if ( $line !~ /^-- $/ ) {
112 my $header = "Grml Tip Number $tips_found\n";
113 my $line = "-" x ( length($header) - 1 ) . "\n\n";
117 #extract tags from tip
118 my ($tag) = $tip =~ /^Tags: (.*)$/m;
119 my @tags = split(/[, ]+/, $tag);
120 if (grep(/^$pattern$/i, @tags) ) {
121 push @tips, $header . $line . $tip . "\n";
125 if ( $tip =~ /$pattern/mi ) {
126 push @tips, $header . $line . $tip . "\n";
139 if ( !open( my $fh, '|-', 'less -FRX' ) ) {
147 say "Sorry, could not find a tip for '$pattern'. :-(\n\n",
148 "Do you want to submit the keyword '$pattern' to grml's keyword database?\n",
149 "The grml team will write tips for the most requested and useful keywords.\n",
150 "To use and contribute to this feature you'll need a working networking connection.\n",
151 "No personal data will be transmitted to the database.\n\n",
152 "Send \"$pattern\" to grml's keyword database? [y|N] ";
154 ReadMode 4; # Turn off controls keys
156 while ( not defined( $x = ReadKey(-1) ) ) {
157 Time::HiRes::sleep(0.5);
159 ReadMode 0; # Reset tty mode before exiting
161 if ( $x =~ /(y|j)/i ) {
163 if ( -f '/etc/grml_version' ) {
164 open( my $fh, '<', '/etc/grml_version' )
165 or die "Could not open /etc/grml_version: $!";
170 elsif ( -f '/etc/debian_version' ) {
171 open( my $fh, '<', '/etc/debian_version' )
172 or die "Could not open /etc/debian_version: $!";
178 $version = 'unknown';
180 my $ua = new LWP::UserAgent;
181 $ua->agent("grml-tips 0.0 "); # set the HTTP 'browser' type
183 'http://deb.grml.org/~formorer/submissions/keyword.cgi',
184 [ 'version' => $version,
185 'keyword' => $pattern
188 if ( $res->is_success ) {
189 my $content = $res->decoded_content;
190 if ( $content =~ /Submission received/ ) {
192 "Keyword '$pattern' has been submitted to grml's keyword database.\nThanks.";
195 say "Your pattern could not be submitted.\n",
196 "Please file a bug against grml-tips at ",
197 "http://bts.grml.org/\n",
202 print "Could not submitt '$pattern': " . $res->status_line . "\n";
208 "'$pattern' has not been sent to grml's keyword database as requested.\n";
210 "If you want to submit a tip please mail it to tips\@grml.org - thank you!\n";
214 ## END OF FILE #################################################################