X-Git-Url: http://git.grml.org/?a=blobdiff_plain;f=grml-tips;h=fc9fd39f7b27b01d733b8a0b67b3011a4d68f96d;hb=42d529ed4951169521e868ba6bd35abc70de8c1a;hp=e4572dcd35434ea7995113a8355b39fe969e7853;hpb=6b52a993e2953e0ae77ec2f85d7234695ec16225;p=grml-tips.git diff --git a/grml-tips b/grml-tips index e4572dc..fc9fd39 100755 --- a/grml-tips +++ b/grml-tips @@ -1,25 +1,166 @@ -#!/bin/sh +#!/usr/bin/perl # Filename: grml-tips # Purpose: query a signature file for a specific keyword and display results -# Authors: grml-team (grml.org), (c) Michael Prokop +# Authors: grml-team (grml.org), (c) Michael Prokop , (c) Alexander Wirt # Bug-Reports: see http://grml.org/bugs/ # License: This file is licensed under the GPL v2. -# Latest change: Sat Mar 25 17:59:52 CET 2006 [mika] +# Latest change: Sam Mär 03 15:35:38 CET 2007 [mika] ################################################################################ -TIPSFILE='/usr/share/grml-tips/grml_tips' - -if [ -r "$TIPSFILE" ] ; then - if [ -n "$1" ] ; then - agrep -d "^-- $" -i "$1" $TIPSFILE && echo "" || \ - ( echo "Sorry, could not find a tip for '$1'" - echo 'If you want to submit a tip please send it to tips@grml.org - thank you!' ) - else - echo "Usage: $0 " ; exit 1 - fi -else - echo "Error: $TIPSFILE not found. Exiting." - exit 1 -fi +use strict; +use Pod::Usage; + +use Term::ReadKey; +use Time::HiRes; +use LWP::UserAgent; + +=head1 NAME + +B - query a signature file for a specific keyword and display results + +=head1 SYNOPSIS + +B [OPTION] I + +=head1 DESCRIPTION + +This manual page documents briefly the B command. + +=head1 OPTIONS + +=over 8 + +=item B<--help> + +Print this help and exit. + +=back + +=head1 EXAMPLES + +=over 8 + +=item B I + +Query grml-tips file for tips / hints including keyword "ntfs". + +=item B I<.> + +Display all available B at once. + +=back + +=head1 FILES + +/usr/share/grml-tips/grml_tips + +Signature file containing the tips. + +=head1 SEE ALSO + +L + +=head1 AUTHOR + +grml-tips was written by Alexander Wirt + +=cut + + +my $grml_tips = '/usr/share/grml-tips/grml_tips'; +my $pattern = shift; + +if ($pattern eq '') { + pod2usage( { + -message => 'No search pattern provided', + -exitval => -1, }); +} elsif ($pattern eq '--help') { + pod2usage(); +} + +my @tips; +my $fh; +if (! open ($fh, '<', "$grml_tips")) { + print "Error: $grml_tips not found.\nExiting."; + exit -1; +} + +my $tip = ''; +my $tip_flag = 0; + +while (my $line = <$fh>) { + if ($line !~ /^-- $/) { + $tip .= $line; + } else { + if ( "$tip" =~ /$pattern/mi ) { + $tip .= $line; + print "$tip"; + $tip = ''; + $tip_flag = 1; + } else { + $tip = ''; + } + } +} +close($fh); + +if (!$tip_flag) { + print "Sorry, could not find a tip for '$pattern'. :-(\n\n", + "Do you want to submit the keyword '$pattern' to grml's keyword database?\n", + "The grml team will write tips for the most requested and useful keywords.\n", + "To use and contribute to this feature you'll need a working networking connection.\n", + "No personal data will be transmitted to the database.\n\n", + "Send \"$pattern\" to grml's keyword database? [y|N] "; + + ReadMode 4; # Turn off controls keys + my $x; + while (not defined ($x = ReadKey(-1))) { + Time::HiRes::sleep(0.5); + } + ReadMode 0; # Reset tty mode before exiting + print "\n\n"; + if ($x =~ /(y|j)/i) { + my $version; + if ( -f '/etc/grml_version' ) { + open (my $fh, '<', '/etc/grml_version') or die "Could not open /etc/grml_version: $!"; + $version = <$fh>; + chomp $version; + close ($fh); + } elsif ( -f '/etc/debian_version') { + open (my $fh, '<', '/etc/debian_version') or die "Could not open /etc/debian_version: $!"; + $version = <$fh>; + chomp $version; + close ($fh); + } else { + $version = 'unknown'; + } + my $ua = new LWP::UserAgent; + $ua->agent("grml-tips 0.0 "); # set the HTTP 'browser' type + my $res = + $ua->post('http://deb.grml.org/~formorer/submissions/keyword.cgi', + [ 'version' => $version, + 'keyword' => $pattern + ], + ); + if ($res->is_success) { + my $content = $res->decoded_content; + if ($content =~ /Submission received/) { + print "Keyword '$pattern' has been submitted to grml's keyword database.\nThanks.\n"; + } else { + print "Your pattern could not be submitted.\n", + "Please file a bug against grml-tips at ", + "http://bts.grml.org/\n", + "Thanks!\n"; + } + } else { + print "Could not submitt '$pattern': " . $res->status_line . "\n"; + } + + + } else { + print "'$pattern' has not been sent to grml's keyword database as requested.\n"; + print "If you want to submit a tip please mail it to tips\@grml.org - thank you!\n"; + } +} ## END OF FILE #################################################################