Debian Codegraph @

dhomepage

raw
1 #!/bin/sh
2 #
3 # Copyright (C) 2008 Thadeu Lima de Souza Cascardo <[email protected]>
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License along
16 # with this program; if not, write to the Free Software Foundation, Inc.,
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 #
19
20 VERSION="0.3"
21
22 version()
23 {
24 echo "dhomepage version $VERSION"
25 echo "dhomepage is licensed under the GNU General Public License"
26 echo "version 2 or later"
27 }
28
29 usage()
30 {
31 echo "dhomepage PACKAGE"
32 echo ""
33 echo "--version Show version information"
34 echo "--help Show this help message"
35 echo ""
36 }
37
38 PACKAGE="$1"
39
40 if [ -z "$PACKAGE" ]; then
41 usage
42 exit 0
43 fi
44
45 case "$1" in
46 --help)
47 usage
48 exit 0
49 ;;
50 --version)
51 version
52 exit 0
53 ;;
54 esac
55
56 RESULT=$(grep-aptavail -PX $PACKAGE -s Homepage,Description)
57 if [ -z "$RESULT" ]; then
58 echo "Package $PACKAGE does not seem to exist."
59 exit 2
60 fi
61
62 HOMEPAGE=$(echo "$RESULT" | grep '^Homepage: ' | sed 's,^Homepage: ,,' | sort -u)
63
64 if [ -z "$HOMEPAGE" ]; then
65 HOMEPAGE=$(echo "$RESULT" | grep '^ Homepage: ' | \
66 sed -n '{s,^ Homepage: ,,;p}' | sort -u)
67 fi
68
69 if [ -z "$HOMEPAGE" ]; then
70 echo "$PACKAGE has no homepage"
71 exit 1
72 fi
73
74 # Check for browsers
75 if [ -x "$(which sensible-browser)" ]; then
76 DH_BROWSER=sensible-browser
77 elif [ -n "$BROWSER" -a -x "$(which "$BROWSER")" ]; then
78 DH_BROWSER="$BROWSER"
79 elif [ -n "$DISPLAY" -a -x "$(which x-www-browser)" ]; then
80 DH_BROWSER=x-www-browser
81 elif [ -x "$(which www-browser)" ]; then
82 DH_BROWSER=www-browser
83 else
84 echo "$0: Warning: No browser found. Just printing the homepage URL." 1>&2
85 DH_BROWSER=echo
86 fi
87
88 for URL in $HOMEPAGE; do
89 "$DH_BROWSER" "$URL"
90 done