mozilla.sh 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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. -m|-mail|--mail ) opt_m=yes; shift ;;
  38. -v|--verbose ) opt_v=yes; shift ;;
  39. -w|--window ) opt_w=yes; shift ;;
  40. -t|--tab ) opt_t=yes; shift ;;
  41. -r|-remote|--remote ) opt_r="$2"; shift; shift ;;
  42. -* ) echo "$0:ERROR: invalid option \"$1\"" 1>&2; exit 1 ;;
  43. * ) break ;;
  44. esac
  45. done
  46. if [ $# -eq 0 ]; then
  47. set -- ""
  48. fi
  49. verbose () {
  50. if [ ".$opt_v" = .yes ]; then
  51. echo "mozilla: $*" 1>&2
  52. fi
  53. }
  54. # establish Mozilla environment
  55. MOZILLA_FIVE_HOME="$mozilla_dir"
  56. export MOZILLA_FIVE_HOME
  57. LANG=en_US.ISO8859-1
  58. export LANG
  59. # special case of direct remote option
  60. if [ ".$opt_r" != . ]; then
  61. verbose "exec: $mozilla_bin -remote \"$opt_r\""
  62. exec $mozilla_bin -remote "$opt_r"
  63. fi
  64. # special case of direct email option
  65. if [ ".$opt_m" != . ]; then
  66. $mozilla_bin -remote "ping()" >/dev/null 2>&1
  67. if [ $? -eq 0 ]; then
  68. verbose "$mozilla_bin -remote \"xfeDoCommand(openInbox)\""
  69. $mozilla_bin -remote "xfeDoCommand(openInbox)"
  70. else
  71. verbose "exec: $mozilla_bin -mail"
  72. exec $mozilla_bin -mail
  73. fi
  74. fi
  75. # determine Mozilla run-time status
  76. $mozilla_bin -remote "ping()" >/dev/null 2>&1
  77. if [ $? -eq 0 ]; then
  78. verbose "process already running (available remotely)"
  79. restart=no
  80. else
  81. verbose "process still not running (not available remotely)"
  82. restart=yes
  83. fi
  84. # open one or more URLs
  85. first=yes
  86. for url in "$@"; do
  87. # determine URL to open
  88. if [ ".`echo .$url | grep '@'`" != . ]; then
  89. # expand at-sign into X11 selection buffer
  90. xsel=`($xsel_bin --paste) 2>/dev/null`
  91. url=`echo "$url" | sed -e "s;@;$xsel;"`
  92. fi
  93. if [ ".$url" = . ]; then
  94. # expand an empty URL into the internal blank page
  95. url="about:blank"
  96. else
  97. # expand special URL constructs
  98. case "$url" in
  99. auto:* )
  100. url=`echo "$url" | sed -e 's;^auto:;;'`
  101. case "$url" in
  102. http://* | https://* | ftp://* | file://* ) ;;
  103. www.* ) url="http://$url" ;;
  104. ftp.* ) url="ftp://$url" ;;
  105. *.tar.gz | *.tgz ) url="ftpsearch:$url" ;;
  106. *" "* ) url="google:$url" ;;
  107. [0-9]* ) url="rfc:$url" ;;
  108. * ) url="leo:$url" ;;
  109. esac
  110. ;;
  111. esac
  112. case "$url" in
  113. http://* | https://* | ftp://* | file://* )
  114. : # URL is already fully qualified
  115. ;;
  116. google:* )
  117. # expand Google query
  118. url=`echo "$url" | sed -e 's;^google:;;' | tr ' ' '+'`
  119. url="http://www.google.com/search?q=$url"
  120. ;;
  121. leo:* )
  122. # expand Leo Dictionary query
  123. url=`echo "$url" | sed -e 's;^leo:;;' | tr ' ' '+'`
  124. url="http://dict.leo.org/?search=$url"
  125. ;;
  126. ftpsearch:* )
  127. # expand FTPSearch query
  128. url=`echo "$url" | sed -e 's;^ftpsearch:;;' | sed -e 's; ;%20;g'`
  129. url="http://www.alltheweb.com/search?advanced=1&cat=ftp&q=$url"
  130. ;;
  131. rfc:* )
  132. # expand Zvon.org RFC query
  133. url=`echo "$url" | sed -e 's;^rfc:;;'`
  134. url="http://zvon.org/tmRFC/RFC$url/Output/index.html"
  135. ;;
  136. whois:* )
  137. # expand Geektools.com WHOIS query
  138. url=`echo "$url" | sed -e 's;^whois:;;'`
  139. url="http://www.geektools.com/cgi-bin/proxy.cgi?query=$url"
  140. ;;
  141. jargon:* )
  142. # expand UMEC Jargon File query
  143. url=`echo "$url" | sed -e 's;^jargon:;;' | tr ' ' '+'`
  144. url="http://www.tf.hut.fi/cgi-bin/jargon?search=$url"
  145. ;;
  146. /* )
  147. # expand absolute filename into file URL
  148. url="file://$url"
  149. ;;
  150. * )
  151. # expand relative filename into file URL
  152. url="file://`pwd`/$url"
  153. ;;
  154. esac
  155. fi
  156. if [ ".$first" = .yes -a ".$restart" = .yes ]; then
  157. # handling of first URL if restarting is necessary
  158. verbose "running new process"
  159. if [ ".$url" = ".about:blank" ]; then
  160. verbose "exec: $mozilla_bin >/dev/null 2>&1 &"
  161. $mozilla_bin >/dev/null 2>&1 &
  162. else
  163. verbose "exec: $mozilla_bin \"$url\" >/dev/null 2>&1 &"
  164. $mozilla_bin "$url" >/dev/null 2>&1 &
  165. fi
  166. else
  167. # delayed waiting for process to be finally remotely available
  168. # if it was started from scratch for the handling of the first
  169. # URL. This way we wait only if necessary, i.e., if more than
  170. # one URL was given.
  171. if [ ".$first" = .no -a ".$restart" = .yes ]; then
  172. verbose "waiting for new process to be available remotely"
  173. sleep 4 # give it a little bit of time to fully startup
  174. i=0
  175. while [ $i -lt 10 ]; do
  176. $mozilla_bin -remote "ping()" >/dev/null 2>&1
  177. if [ $? -eq 0 ]; then
  178. break
  179. fi
  180. sleep 1 # give it a little bit more time to startup
  181. i=`expr $i + 1`
  182. done
  183. fi
  184. # determine remote command
  185. if [ ".$opt_w" = .yes ]; then
  186. if [ ".$url" = ".about:blank" ]; then
  187. cmd="xfeDoCommand(openBrowser)"
  188. else
  189. cmd="openURL($url, new-window)"
  190. fi
  191. elif [ ".$opt_t" = .yes ]; then
  192. cmd="openURL($url, new-tab)"
  193. else
  194. cmd="openURL($url)"
  195. fi
  196. # perform remote command
  197. verbose "sending remote command to running process"
  198. verbose "exec: $mozilla_bin -remote \"$cmd\" >/dev/null 2>&1"
  199. $mozilla_bin -remote "$cmd" >/dev/null 2>&1
  200. fi
  201. first=no
  202. done