File: dpkg-www

package info (click to toggle)
dpkg-www 2.59
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 192 kB
  • sloc: sh: 1,596; makefile: 16
file content (123 lines) | stat: -rwxr-xr-x 3,082 bytes parent folder | download
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
#!/bin/sh
#
# Command-line interface to dpkg-www.
#
# Copyright © 1999-2006 Massimo Dal Zotto <dz@debian.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

usage() {
    # Automatic help hack
    echo "Usage: ${0##*/} [<options...>] [<query>]"
    echo
    echo "Options:"
    echo
    sed '/^	-/!d; s/\\//; s/)//; s/#/</; s/#/>/' $0
    echo
}

urlencode() {
    perl -e '
        $s=join(" ",@ARGV);
        $s=~s/([^a-zA-Z0-9 _\.*@-])/uc sprintf("%%%02x",ord($1))/eg;
        $s=~s/ /+/g;
        print $s . "\n";'   "$*"
}

if [ -n "$DPKG_WWW_HOST" ]; then
    DPKG_WWW_URL="https://$DPKG_WWW_HOST/cgi-bin/dpkg"
else
    DPKG_WWW_URL="http://localhost/cgi-bin/dpkg"
fi
X11_BROWSERS="\
    sensible-browser x-www-browser
    firefox chromium konqueror epiphany-browser midori surf xlinks2"
TXT_BROWSERS="\
    sensible-browser www-browser
    elinks links2 links lynx w3m"

browser=
browser_args=
while [ "${1#-}" != "$1" ]; do
    case "$1" in
	-\?|-help|--help)
	    usage
	    exit
	    ;;
	-x|--xtrace)
	    shift 1
	    set -x
	    ;;
	-h|--host) #host#
	    test "$2" || { usage; exit 1; }
	    DPKG_WWW_URL="https://${2}/cgi-bin/dpkg"
	    shift 2 || exit 1
	    ;;
	-s|--stdout)
	    shift 1
	    export DISPLAY=""
	    noheader="&noheader=true"
	    if [ -x /usr/bin/lynx ]; then
		browser="lynx"
		browser_args="-dump -nolist"
	    elif [ -x /usr/bin/lynx-ssl ]; then
		browser="lynx"
		browser_args="-dump -nolist"
	    elif  [ -x /usr/bin/links ]; then
		browser="links"
		browser_args=""
	    elif  [ -x /usr/bin/w3m ]; then
		browser="w3m"
		browser_args=""
	    fi
	    ;;
 	--|*)
	    break
	    ;;
    esac
done

# Source optional local and user configuration files
test -e /etc/dpkg-www.conf && . /etc/dpkg-www.conf 2>/dev/null
test -e ~/.dpkg-www && . ~/.dpkg-www 2>/dev/null

if [ "$DISPLAY" ]; then
    for f in $browser $DPKG_WWW_BROWSER $X11_BROWSERS $TXT_BROWSERS; do
	if which $f >/dev/null 2>&1; then
	    browser=$f
	    break
	fi
    done
else
    for f in $browser $DPKG_WWW_BROWSER $TXT_BROWSERS; do
	echo $X11_BROWSERS | grep -qw "$f" && continue	# skip X11 $BROWSER
	if which $f >/dev/null 2>&1; then
	    browser=$f
	    break
	fi
    done
fi

if [ ! "$browser" ]; then
    echo "dpkg-www: no WWW browser found" >&2
    exit 1
fi

query=$(urlencode "$*")
if [ "$DEBUG" = 1 -o "$DEBUG" = true ]; then
    echo $browser $browser_args "$DPKG_WWW_URL?query=$query$noheader"
fi
exec $browser $browser_args "$DPKG_WWW_URL?query=$query$noheader"

# end of file