/izpack-dist/src/main/resources/bin/start.sh

https://github.com/maslovalex/izpack · Shell · 125 lines · 72 code · 15 blank · 38 comment · 12 complexity · 36e173b031a5aa8d011920a24d51289d MD5 · raw file

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