-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 <keyword>" ; exit 1
- fi
-else
- echo "Error: $TIPSFILE not found. Exiting."
- exit 1
-fi
+use strict;
+use Pod::Usage;
+
+=head1 NAME
+
+B<grml-tips> - query a signature file for a specific keyword and display results
+
+=head1 SYNOPSIS
+
+B<grml-tips> [OPTION] I<keyword>
+
+=head1 DESCRIPTION
+
+This manual page documents briefly the B<grml-tips> command.
+
+=head1 OPTIONS
+
+=over 8
+
+=item B<--help>
+
+Print this help and exit.
+
+=back
+
+=head1 EXAMPLES
+
+=over 8
+
+=item B<grml-tips> I<ntfs>
+
+Query grml-tips file for tips / hints including keyword "ntfs".
+
+=item B<grml-tips> I<.>
+
+Display all available B<grml-tips> at once.
+
+=back
+
+=head1 FILES
+
+/usr/share/grml-tips/grml_tips
+
+Signature file containing the tips.
+
+=head1 SEE ALSO
+
+L<grml(1)>
+
+=head1 AUTHOR
+
+grml-tips was written by Alexander Wirt <formorer@grml.org>
+
+=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/m ) {
+ $tip .= $line;
+ print "$tip";
+ $tip = '';
+ $tip_flag = 1;
+ } else {
+ $tip = '';
+ }
+ }
+}
+close($fh);
+
+print "Sorry, could not find a tip for '$pattern'. :-(\n"
+ . "If you want to submit a tip please mail it to tips\@grml.org - thank "
+ . "you!\n\n" unless $tip_flag;