1 | #!/bin/sh |
---|
2 | # $Id: htmlview.sh,v 1.6 2003-05-01 08:34:18 jweiss Exp $ |
---|
3 | |
---|
4 | # htmlview script adapted from the infoagents locker to take advantage |
---|
5 | # of the local netscape, if present. |
---|
6 | |
---|
7 | # |
---|
8 | # htmlview - script to view an HTML doc in an existing browser if |
---|
9 | # possible, otherwise start up a new one |
---|
10 | usage="Usage: htmlview [ -c ] [ -f ] URL |
---|
11 | -c indicates that SSL/certificate authentication is required. |
---|
12 | -f forces Lynx to treat displayed files as HTML" |
---|
13 | optstring=cf |
---|
14 | |
---|
15 | # Parse options |
---|
16 | cert_required=false |
---|
17 | force_lynx_html=false |
---|
18 | args="`getopt $optstring $*`" |
---|
19 | if [ $? != 0 ]; then |
---|
20 | echo "$usage" >&2 |
---|
21 | exit 2 |
---|
22 | fi |
---|
23 | for arg in $args |
---|
24 | do |
---|
25 | case $arg in |
---|
26 | -c) cert_required=true |
---|
27 | ;; |
---|
28 | -f) lynx_flags="-force_html" |
---|
29 | ;; |
---|
30 | --) |
---|
31 | ;; |
---|
32 | *) |
---|
33 | url_arg=$arg |
---|
34 | ;; |
---|
35 | esac |
---|
36 | done |
---|
37 | |
---|
38 | # Handle files in current directory appropriately. |
---|
39 | case "$url_arg" in |
---|
40 | "") |
---|
41 | # No URL supplied. |
---|
42 | echo "$usage" >&2 |
---|
43 | exit 2 |
---|
44 | ;; |
---|
45 | http:* | ftp:* | gopher:* | /*) |
---|
46 | # Full URL's and absolute pathnames require no special treatment. |
---|
47 | url=$url_arg |
---|
48 | ;; |
---|
49 | https:*) |
---|
50 | # https URL's require SSL (and maybe certificate) support. |
---|
51 | cert_required=true |
---|
52 | url=$url_arg |
---|
53 | ;; |
---|
54 | *) |
---|
55 | # Relative path to existing file--need absolute path for running browser. |
---|
56 | if [ -r $url_arg ]; then |
---|
57 | url=`pwd`/$url_arg |
---|
58 | else |
---|
59 | url=$url_arg |
---|
60 | fi |
---|
61 | ;; |
---|
62 | esac |
---|
63 | |
---|
64 | # Quote commas in the URL; they won't work with OpenUrl(). |
---|
65 | url=`echo "$url" | sed 's/,/%2C/g'` |
---|
66 | |
---|
67 | # If $DISPLAY is not set, just start lynx |
---|
68 | case "$DISPLAY" in |
---|
69 | "") |
---|
70 | if [ $cert_required = true ]; then |
---|
71 | echo "$0: Could not find or start any WWW browser that supports " \ |
---|
72 | "personal certificates while opening $url" >&2 |
---|
73 | exit 1 |
---|
74 | else |
---|
75 | exec /bin/athena/attachandrun infoagents lynx lynx "$url" |
---|
76 | fi |
---|
77 | ;; |
---|
78 | esac |
---|
79 | |
---|
80 | # Try to display the URL with the user's preferred viewer. |
---|
81 | /usr/athena/bin/gurlview "$url" && exit 0 |
---|
82 | if [ $cert_required = true ]; then |
---|
83 | echo "$0: Could not find or start any WWW browser that supports " \ |
---|
84 | "personal certificates while opening $url" >&2 |
---|
85 | exit 1 |
---|
86 | else |
---|
87 | echo "$0: Could not run gurlview. Will try Lynx." >&2 |
---|
88 | |
---|
89 | # Start Lynx |
---|
90 | /bin/athena/attachandrun infoagents lynx lynx $lynx_flags "$url" && exit 0 |
---|
91 | fi |
---|
92 | |
---|
93 | echo "$0: Could not find or start any WWW browser." >&2 |
---|
94 | exit 1 |
---|