File: dpkg-www-browser

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 (112 lines) | stat: -rwxr-xr-x 2,692 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
#!/bin/sh
#
# Dpkg browser helper used by dpkg-www.
#
# Copyright © 1999-2001 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() {
    echo "${0##*/} [-x|--xterm] [-f|--file] <file>"
}

press_enter() {
    echo ""
    echo -n "Press Enter to close this window..."; read x
}

packageURI() {
    local package="$1"
    local pkgcache=$(tempfile)
    local srcpkgcache=$(tempfile)
    trap "rm -f $pkgcache $srcpkgcache" 0
    apt-get -o "Debug::NoLocking=1" \
	    -o "Dir::Cache=/tmp" \
	    -o "Dir::Cache::pkgcache=$pkgcache" \
	    -o "Dir::Cache::srcpkgcache=$srcpkgcache" \
	    -o "Dir::Cache::archives=/var/cache/apt/archives" \
	    install --reinstall --print-uris -y "$package" \
    | grep -F "/${package}_" \
    | sed "/^'/!d; s/^'//; s/'.*//"
    rm -f $pkgcache $srcpkgcache 2>/dev/null
}

# Source optional config file
test -e /etc/dpkg-www.conf && . /etc/dpkg-www.conf 2>/dev/null

FILE=""
ACTION=""
HOST=""
PACKAGES=""

# Restart self in an xterm window. Must be the first option. Used by netscape.
if [ "$DISPLAY" -a "$1" = "-x" -o "$1" = "--xterm" ]; then
    shift 1
    xterm -T "Package Browser" -e $0 "$@"
    exit 0
fi

while [ "${1#-}" != "$1" ]; do
    case "$1" in
	-\?|-help|--help)
	    usage
	    exit
	    ;;
	-f|--file)
	    FILE="$2"
	    shift 2
	    ;;
	-*)
	    echo "Invalid option: $1" >&2
	    press_enter
	    exit 1
	    ;;
    esac
done
FILE="${FILE:-$1}"

if [ "$FILE" != "" -a ! -e "$FILE" ]; then
    echo "File not found: $FILE" >&2
    press_enter
    exit 1
fi

request="$(cat "$FILE" | head -10)"
if echo "$request" | grep -q "^Browse-package:"; then
    PACKAGE=$(
	echo "$request" | grep ^Browse-package: \
	| head -1 | sed 's/.*: *//'
    )
else
    echo "Invalid request" >&2
    press_enter
    exit 1
fi

uri="$(packageURI "$PACKAGE")"
file="${uri#file:}"
if [ ! "$file" -o "$file" = "$uri" -o ! -e "$file" ]; then
    echo "Package not found: $file" >&2
    press_enter
    exit 1
fi

if [ "$DISPLAY" ]; then
    sensible-editor "$file" &
    sleep 1
else
    exec sensible-editor "$file"
fi

# end of file