summaryrefslogtreecommitdiff
path: root/search_cgi
blob: 624ad2e6c61f2a79129ef59e724a548d1b3e98e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/bin/sh

echo "Content-type: text/html\n\n"

query="${QUERY_STRING}"


echo "<html><body><div>Search for: </div><form method='GET' action='/cgi-bin/search_cgi'>"
echo "<input type='text' name='query'></input>"
echo "<input type='submit' value='Search!'></input>"
echo "</form>"


terms=$(echo "${query}" | tr '&' '\n' | grep -E "^query" | sed -E 's/^query=//')


if [ -z "$terms" ]; then 
	exit 0
else
	search=$(echo "$terms" | sed -E 's/\%20/ /g')
	res=$(./search_repo ./ $search )
	if [ -z "$res" ]; then 
		echo "<p>No results for \"$search\":"
		exit 0;
	else
		echo "<p>Results for \"$search\""
		for r in $res; do 
			echo "<div><a href=\"$r\" target='new'>$r</a></div>\n"
		done
	fi
fi