/usr/lib/surfraw/opensearch is in surfraw 2.2.8-1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | #!/bin/sh
# elvis: opensearch -- Search an OpenSearch-enabled website
# ianb@erislabs.net 20060903
. surfraw || exit 1
w3_config_hook () {
def SURFRAW_opensearch_title ""
def SURFRAW_opensearch_count $SURFRAW_results
def SURFRAW_opensearch_startindex ""
def SURFRAW_opensearch_pageindex ""
def SURFRAW_opensearch_language "$SURFRAW_lang"
def SURFRAW_opensearch_inputencoding ""
def SURFRAW_opensearch_outputencoding ""
defyn SURFRAW_opensearch_list no
defyn SURFRAW_opensearch_redirect no
}
w3_usage_hook () {
cat <<EOF
Usage: $w3_argv0 [options] [url] [search words]...
Description:
Surfraw search an OpenSearch-enabled website.
If opensearch-discover and opensearch-genquery are installed then
it will handle the opensearch lookups locally, otherwise it will fall
back on a redirector.
Local options:
-r Explicitly use redirector.
-l List OpenSearch searches at url.
-title=TITLE Use search with title matching TITLE.
TITLE is case-insensitive.
Example: -t book matches "Book Search"
Many sites do not implement all (or any) of the following
parameters, in which case they will be silently ignored.
-count=NUM Number of search results returned.
Default: $SURFRAW_opensearch_count.
Environment: SURFRAW_opensearch_count.
If not set, defaults to value of SURFRAW_results
-index=NUM Offset of first result.
-page=NUM Which page of results to show.
-language=LANG Language to display results in.
LANG should be a 2-letter ISO country code.
Examples: -l=en or -lang=de.
Environment: SURFRAW_opensearch_lang, SURFRAW_lang
-inputencoding=ENC Specify how search terms are encoded.
-outputencoding=ENC Request output encoded as ENC.
Environment: SURFRAW_opensearch_search
EOF
w3_global_usage
}
w3_parse_option_hook () {
opt="$1"
optarg="$2"
case "$opt" in
-t*=*) setopt SURFRAW_opensearch_title "$optarg" ;;
-c*=*) setopt SURFRAW_opensearch_count "$optarg" ;;
-i*=*) setopt SURFRAW_opensearch_startindex "$optarg" ;;
-p*=*) setopt SURFRAW_opensearch_pageindex "$optarg" ;;
-la*=*) setopt SURFRAW_opensearch_language "$optarg" ;;
-in*=*) setopt SURFRAW_opensearch_inputencoding "$optarg" ;;
-o*=*) setopt SURFRAW_opensearch_outputencoding "$optarg" ;;
-l) setoptyn SURFRAW_opensearch_list 1 ;;
-r) setoptyn SURFRAW_opensearch_redirect yes ;;
*) return 1 ;;
esac
return 0
}
w3_config
w3_parse_args "$@"
if test -z "$w3_args"; then
w3_usage_hook
exit 0
fi
if ifno SURFRAW_opensearch_redirect &&
[ ! -x $(which opensearch-discover) ] ||
[ ! -x $(which opensearch-genquery) ]
then
setoptyn SURFRAW_opensearch_redirect yes
fi
# Clobbers command line, but we've already parsed it
set $w3_args
siteurl="$1"
shift
w3_args="$*"
# w3_args now contains a list of arguments
if ifyes SURFRAW_opensearch_redirect; then
if ifyes SURFRAW_opensearch_list; then
err "-l not supported with -r"
elif test -z "$w3_args"; then
w3_browse_url "$siteurl"
else
escaped_args=`w3_url_of_arg $w3_args`
if [ -n "$SURFRAW_opensearch_title" ]; then
err "-t not supported with -r"
fi
url="http://erislabs.net/ianb/webtools/opensearch/"
url="${url}?site=$(w3_url_of_arg "$siteurl")"
url="${url}&searchTerms=${escaped_args}"
url="${url}&count=${SURFRAW_opensearch_count}"
url="${url}&startIndex=${SURFRAW_opensearch_startindex}"
url="${url}&pageIndex=${SURFRAW_opensearch_pageindex}"
url="${url}&language=${SURFRAW_opensearch_language}"
url="${url}&inputEncoding=${SURFRAW_opensearch_inputencoding}"
url="${url}&outputEncoding=${SURFRAW_opensearch_outputencoding}"
url="${url}&fmt=html"
w3_browse_url "$url"
fi
else # dont use redirector
if ifyes SURFRAW_opensearch_list; then
opensearch-discover -q -v -a $siteurl
case "$?" in
0) ;; # OK
1) err "Cannot access $siteurl" ;;
2) err "Cannot find ${matching}OpenSearch link at $siteurl" ;;
3) err "opensearch-discover: required perl module not found" ;;
*) err "Unknown error from opensearch-discover" ;;
esac
elif test -z "$w3_args"; then
w3_browse_url "$siteurl"
else
escaped_args=`w3_url_of_arg $w3_args`
discover_args="-q"
matching="" # for error message below
if [ -n "$SURFRAW_opensearch_title" ]; then
discover_args="-q -t $SURFRAW_opensearch_title"
matching="matching "
fi
opensearchurl=`opensearch-discover $discover_args $siteurl`
case "$?" in
0) ;; # OK
1) err "Cannot access $siteurl" ;;
2) err "Cannot find ${matching}OpenSearch link at $siteurl" ;;
3) err "opensearch-discover: required perl module not found" ;;
*) err "Unknown error from opensearch-discover" ;;
esac
queryargs="-q -H"
if [ -n "$SURFRAW_opensearch_count" ]; then
queryargs="$queryargs -c $SURFRAW_opensearch_count"
fi
if [ -n "$SURFRAW_opensearch_startindex" ]; then
queryargs="$queryargs -i $SURFRAW_opensearch_startindex"
fi
if [ -n "$SURFRAW_opensearch_pageindex" ]; then
queryargs="$queryargs -p $SURFRAW_opensearch_pageindex"
fi
if [ -n "$SURFRAW_opensearch_language" ]; then
queryargs="$queryargs -l $SURFRAW_opensearch_language"
fi
if [ -n "$SURFRAW_opensearch_inputencoding" ]; then
queryargs="$queryargs -I $SURFRAW_opensearch_inputencoding"
fi
if [ -n "$SURFRAW_opensearch_outputencoding" ]; then
queryargs="$queryargs -O $SURFRAW_opensearch_outputencoding"
fi
query=`opensearch-genquery $queryargs $opensearchurl $w3_args`
case "$?" in
0) ;; # OK
1) err "Cannot access OpenSearch description $opensearchurl" ;;
2) err "Error parsing OpenSearch Description at $opensearchurl" ;;
3) err "No HTML search specified in $opensearchurl" ;;
4) err "opensearch-genquery: cannot find required perl module WWW::OpenSearch" ;;
*) err "Unknown error from opensearch-genquery" ;;
esac
w3_browse_url "$query"
fi
fi
|