* Added workaround for systems without agrep using awk.
[grml-tips.git] / grml-tips
1 #!/bin/sh
2 # Filename:      grml-tips
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>
5 # Bug-Reports:   see http://grml.org/bugs/
6 # License:       This file is licensed under the GPL v2.
7 # Latest change: Sam Nov 11 20:01:35 CET 2006 [mika]
8 ################################################################################
9
10 TIPSFILE='/usr/share/grml-tips/grml_tips'
11
12 if ! [ -r "$TIPSFILE" ] ; then
13    echo "Error: $TIPSFILE not found. Exiting." >&2
14    exit 1
15 fi
16
17 if [ -x /usr/bin/agrep ] ; then
18    if [ -n "$1" ] ; then
19      agrep -d "^-- $" -i "$1" $TIPSFILE && echo "" || \
20      ( echo "Sorry, could not find a tip for '$1'. :-(" >&2
21        echo 'If you want to submit a tip please mail it to tips@grml.org - thank you!' >&2
22        exit 1 )
23    else
24      echo "Usage: $0 <keyword>" >&2 ; exit 1
25    fi
26 else # workaround solution for systems without agrep :-/
27   if [ -n "$1" ] ; then
28      TIP=$(awk "BEGIN { RS = \"-- \" } /$1/" "$TIPSFILE")
29      if [ -n "$TIP" ] ; then
30         echo "$TIP"
31      else
32         echo "Sorry, could not find a tip for '$1'. :-(" >&2
33         echo 'If you want to submit a tip please mail it to tips@grml.org - thank you!' >&2
34         exit 1
35      fi
36   else
37     echo "Usage: $0 <keyword>" >&2 ; exit 1
38   fi
39 fi
40
41 ## END OF FILE #################################################################