search.sh - gopherhole - My gopherhole source code.
 (HTM) git clone git://jay.scot/gopherhole
 (DIR) Log
 (DIR) Files
 (DIR) Refs
       ---
       search.sh (629B)
       ---
            1 #!/bin/sh
            2 
            3 if [ $# -lt 1 ];
            4 then
            5         printf "usage: %s search\n" "$(basename "$0")" >&2
            6         exit 1
            7 fi
            8 
            9 root="/home/jay/gopher"
           10 content="phlog/txt/*.txt"
           11 keyword="$1"
           12 
           13 if echo "$keyword" | grep -q '[$;<>`|]'; then
           14         printf "Haha your at it mate, calm doon with the pish characters.\n"
           15         printf "Trying shell escape in like its 1990.. I guess you are on gopher.\n"
           16         return 0
           17 fi
           18 
           19 for file in $root/$content; do
           20         if [ -f "$file" ]; then
           21                 if grep -iq "$keyword" "$file"; then
           22                         header=$(grep '^--\[' "$file" | head -n 1 | sed 's/^--\[\(.*\)/\1/')
           23                         printf "[0|%s|/phlog/txt/%s|server|port]\n" "$header" "$(basename "$file")"
           24                 fi
           25         fi
           26 done