mozilla.sh 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. #!/bin/sh
  2. ##
  3. ## mozilla -- Mozilla Browser Startup Control Utility
  4. ## Copyright (c) 2000-2003 The OpenPKG Project <http://www.openpkg.org/>
  5. ## Copyright (c) 2000-2003 Ralf S. Engelschall <rse@engelschall.com>
  6. ## Copyright (c) 2000-2003 Cable & Wireless <http://www.cw.com/>
  7. ##
  8. ## Permission to use, copy, modify, and distribute this software for
  9. ## any purpose with or without fee is hereby granted, provided that
  10. ## the above copyright notice and this permission notice appear in all
  11. ## copies.
  12. ##
  13. ## THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  14. ## WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  15. ## MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  16. ## IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
  17. ## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  18. ## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  19. ## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  20. ## USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  21. ## ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  22. ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  23. ## OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  24. ## SUCH DAMAGE.
  25. ##
  26. # configuration
  27. mozilla_dir="@l_prefix@/lib/mozilla"
  28. mozilla_bin="@l_prefix@/lib/mozilla/mozilla"
  29. xsel_bin="@l_prefix@/bin/xsel"
  30. # option parsing
  31. opt_v=no
  32. opt_w=no
  33. opt_t=no
  34. opt_r=""
  35. while [ ".$1" != . ]; do
  36. case $1 in
  37. -v|--verbose ) opt_v=yes; shift ;;
  38. -w|--window ) opt_w=yes; shift ;;
  39. -t|--tab ) opt_t=yes; shift ;;
  40. -r|-remote|--remote ) opt_r="$2"; shift; shift ;;
  41. -* ) echo "$0:ERROR: invalid option \"$1\"" 1>&2; exit 1 ;;
  42. * ) break ;;
  43. esac
  44. done
  45. if [ $# -eq 0 ]; then
  46. set -- ""
  47. fi
  48. verbose () {
  49. if [ ".$opt_v" = .yes ]; then
  50. echo "mozilla: $*" 1>&2
  51. fi
  52. }
  53. # establish Mozilla environment
  54. MOZILLA_FIVE_HOME="$mozilla_dir"
  55. export MOZILLA_FIVE_HOME
  56. LANG=en_US.ISO8859-1
  57. export LANG
  58. # special case of direct remote option
  59. if [ ".$opt_r" != . ]; then
  60. verbose "exec: $mozilla_bin -remote \"$opt_r\""
  61. exec $mozilla_bin -remote "$opt_r"
  62. fi
  63. # determine Mozilla run-time status
  64. $mozilla_bin -remote "ping()" >/dev/null 2>&1
  65. if [ $? -eq 0 ]; then
  66. verbose "process already running (available remotely)"
  67. restart=no
  68. else
  69. verbose "process still not running (not available remotely)"
  70. restart=yes
  71. fi
  72. # open one or more URLs
  73. first=yes
  74. for url in "$@"; do
  75. # determine URL to open
  76. if [ ".`echo .$url | grep '@'`" != . ]; then
  77. # expand at-sign into X11 selection buffer
  78. xsel=`($xsel_bin --paste) 2>/dev/null`
  79. url=`echo "$url" | sed -e "s;@;$xsel;"`
  80. fi
  81. if [ ".$url" = . ]; then
  82. # expand an empty URL into the internal blank page
  83. url="about:blank"
  84. else
  85. # expand special URL constructs
  86. case "$url" in
  87. auto:* )
  88. url=`echo "$url" | sed -e 's;^auto:;;'`
  89. case "$url" in
  90. http://* | https://* | ftp://* | file://* ) ;;
  91. www.* ) url="http://$url" ;;
  92. ftp.* ) url="ftp://$url" ;;
  93. *.tar.gz | *.tgz ) url="ftpsearch:$url" ;;
  94. *" "* ) url="google:$url" ;;
  95. [0-9]* ) url="rfc:$url" ;;
  96. * ) url="leo:$url" ;;
  97. esac
  98. ;;
  99. esac
  100. case "$url" in
  101. http://* | https://* | ftp://* | file://* )
  102. : # URL is already fully qualified
  103. ;;
  104. google:* )
  105. # expand Google query
  106. url=`echo "$url" | sed -e 's;^google:;;' | tr ' ' '+'`
  107. url="http://www.google.com/search?q=$url"
  108. ;;
  109. leo:* )
  110. # expand Leo Dictionary query
  111. url=`echo "$url" | sed -e 's;^leo:;;' | tr ' ' '+'`
  112. url="http://dict.leo.org/?search=$url"
  113. ;;
  114. ftpsearch:* )
  115. # expand FTPSearch query
  116. url=`echo "$url" | sed -e 's;^ftpsearch:;;' | sed -e 's; ;%20;g'`
  117. url="http://www.alltheweb.com/search?advanced=1&cat=ftp&q=$url"
  118. ;;
  119. rfc:* )
  120. # expand Zvon.org RFC query
  121. url=`echo "$url" | sed -e 's;^rfc:;;'`
  122. url="http://zvon.org/tmRFC/RFC$url/Output/index.html"
  123. ;;
  124. whois:* )
  125. # expand Geektools.com WHOIS query
  126. url=`echo "$url" | sed -e 's;^whois:;;'`
  127. url="http://www.geektools.com/cgi-bin/proxy.cgi?query=$url"
  128. ;;
  129. jargon:* )
  130. # expand UMEC Jargon File query
  131. url=`echo "$url" | sed -e 's;^jargon:;;' | tr ' ' '+'`
  132. url="http://www.tf.hut.fi/cgi-bin/jargon?search=$url"
  133. ;;
  134. /* )
  135. # expand absolute filename into file URL
  136. url="file://$url"
  137. ;;
  138. * )
  139. # expand relative filename into file URL
  140. url="file://`pwd`/$url"
  141. ;;
  142. esac
  143. fi
  144. if [ ".$first" = .yes -a ".$restart" = .yes ]; then
  145. # handling of first URL if restarting is necessary
  146. verbose "running new process"
  147. if [ ".$url" = ".about:blank" ]; then
  148. verbose "exec: $mozilla_bin >/dev/null 2>&1 &"
  149. $mozilla_bin >/dev/null 2>&1 &
  150. else
  151. verbose "exec: $mozilla_bin \"$url\" >/dev/null 2>&1 &"
  152. $mozilla_bin "$url" >/dev/null 2>&1 &
  153. fi
  154. else
  155. # delayed waiting for process to be finally remotely available
  156. # if it was started from scratch for the handling of the first
  157. # URL. This way we wait only if necessary, i.e., if more than
  158. # one URL was given.
  159. if [ ".$first" = .no -a ".$restart" = .yes ]; then
  160. verbose "waiting for new process to be available remotely"
  161. sleep 4 # give it a little bit of time to fully startup
  162. i=0
  163. while [ $i -lt 10 ]; do
  164. $mozilla_bin -remote "ping()" >/dev/null 2>&1
  165. if [ $? -eq 0 ]; then
  166. break
  167. fi
  168. sleep 1 # give it a little bit more time to startup
  169. i=`expr $i + 1`
  170. done
  171. fi
  172. # determine remote command
  173. if [ ".$opt_w" = .yes ]; then
  174. if [ ".$url" = ".about:blank" ]; then
  175. cmd="xfeDoCommand(openBrowser)"
  176. else
  177. cmd="openURL($url, new-window)"
  178. fi
  179. elif [ ".$opt_t" = .yes ]; then
  180. cmd="openURL($url, new-tab)"
  181. else
  182. cmd="openURL($url)"
  183. fi
  184. # perform remote command
  185. verbose "sending remote command to running process"
  186. verbose "exec: $mozilla_bin -remote \"$cmd\" >/dev/null 2>&1"
  187. $mozilla_bin -remote "$cmd" >/dev/null 2>&1
  188. fi
  189. first=no
  190. done