svn-gvsig-desktop / branches / v2_0_0_prep / dist-utils / izpack_4.2.0 / bin / start.sh @ 28393
History | View | Annotate | Download (2.85 KB)
1 |
#!/usr/bin/env bash |
---|---|
2 |
|
3 |
# ShellScript |
4 |
# - to detect a desktop and their native |
5 |
# File/WebBrowser such as Konqueror (KDE) or Nautilus/Epiphany (Gnome) |
6 |
# Or |
7 |
# - to detect a browser from the mozilla family |
8 |
# The first prefered one will open the given $1 document |
9 |
# which should be a web url (http://host.domain.com/path/index.html) or a |
10 |
# local file like file:///local/folder/document.html |
11 |
# Note: Tested on SuSE, Fedora an Mandriva Linux and Solaris 9 with kde, gnome or a mozilla installed |
12 |
# |
13 |
# This is licensed as part of |
14 |
# IzPack - Copyright 2001-2005 Julien Ponge, All Rights Reserved. |
15 |
# |
16 |
# http://izpack.org/ |
17 |
# http://izpack.codehaus.org/ |
18 |
# |
19 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
20 |
# you may not use this file except in compliance with the License. |
21 |
# You may obtain a copy of the License at |
22 |
# |
23 |
# http://www.apache.org/licenses/LICENSE-2.0 |
24 |
# |
25 |
# Unless required by applicable law or agreed to in writing, software |
26 |
# distributed under the License is distributed on an "AS IS" BASIS, |
27 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
28 |
# See the License for the specific language governing permissions and |
29 |
# limitations under the License. |
30 |
# |
31 |
# Usage: |
32 |
# |
33 |
# ./start.sh http://izpack.org/ |
34 |
# |
35 |
# author marc.eppelmann@gmx.de |
36 |
# $Id: start.sh 2116 2008-04-19 13:00:24Z jponge $ |
37 |
# |
38 |
|
39 |
function detectDesktop() { |
40 |
if [[ "$DISPLAY" = "" ]]; then |
41 |
return 1 |
42 |
fi |
43 |
|
44 |
local LC_ALL=C |
45 |
local clients |
46 |
if ! clients=`xlsclients`; then |
47 |
# TODO: should we fall back to using ps? |
48 |
return 1 |
49 |
fi |
50 |
|
51 |
if echo "$clients" | grep -qE '(gnome-panel|nautilus|metacity)'; then |
52 |
echo gnome |
53 |
elif echo "$clients" | grep -qE '(kicker|slicker|karamba|kwin)'; then |
54 |
echo kde |
55 |
else |
56 |
echo other |
57 |
fi |
58 |
return 1 |
59 |
} |
60 |
|
61 |
function lookForRunningGecko(){ |
62 |
if command -v firefox &>/dev/null; then |
63 |
tempfile=`mktemp` |
64 |
|
65 |
firefox -remote "ping()" 2> $tempfile |
66 |
|
67 |
if [ -s $tempfile ]; then |
68 |
rm $tempfile |
69 |
echo "none" # is not running :-) |
70 |
return 1 |
71 |
else |
72 |
rm $tempfile |
73 |
echo firefox # is running :-) |
74 |
return 0 |
75 |
fi |
76 |
fi # firefox "$1" |
77 |
if command -v mozilla &>/dev/null; then |
78 |
#if mozilla -remote "ping()" |
79 |
if command mozilla -remote "ping()" &>/dev/null; then |
80 |
echo mozilla # is running :-) |
81 |
return 0 |
82 |
fi |
83 |
fi |
84 |
echo "none" |
85 |
|
86 |
return 1 |
87 |
} |
88 |
|
89 |
desktop=`detectDesktop` |
90 |
gecko=`lookForRunningGecko` |
91 |
|
92 |
echo "found Desktop: $desktop" |
93 |
echo "found Gecko: $gecko" |
94 |
|
95 |
if [[ "$gecko" = "none" ]]; then # try open a new instance if found: |
96 |
if command -v firefox &>/dev/null; then |
97 |
firefox "$1" & |
98 |
elif command -v mozilla &>/dev/null; then |
99 |
mozilla "$1" & |
100 |
elif [[ "$desktop" = "gnome" ]] && command -v gnome-open &>/dev/null; then |
101 |
gnome-open "$1" & |
102 |
elif [[ "$desktop" = "kde" ]]; then |
103 |
kfmclient exec "$1" & |
104 |
else |
105 |
exit 1 |
106 |
fi |
107 |
else |
108 |
echo "Launching: $gecko" |
109 |
$gecko -remote "openurl($1)" & |
110 |
fi |
111 |
|
112 |
|