1*b1cdbd2cSJim Jagielski#!/bin/sh 2*b1cdbd2cSJim Jagielski# ************************************************************* 3*b1cdbd2cSJim Jagielski# 4*b1cdbd2cSJim Jagielski# Licensed to the Apache Software Foundation (ASF) under one 5*b1cdbd2cSJim Jagielski# or more contributor license agreements. See the NOTICE file 6*b1cdbd2cSJim Jagielski# distributed with this work for additional information 7*b1cdbd2cSJim Jagielski# regarding copyright ownership. The ASF licenses this file 8*b1cdbd2cSJim Jagielski# to you under the Apache License, Version 2.0 (the 9*b1cdbd2cSJim Jagielski# "License"); you may not use this file except in compliance 10*b1cdbd2cSJim Jagielski# with the License. You may obtain a copy of the License at 11*b1cdbd2cSJim Jagielski# 12*b1cdbd2cSJim Jagielski# http://www.apache.org/licenses/LICENSE-2.0 13*b1cdbd2cSJim Jagielski# 14*b1cdbd2cSJim Jagielski# Unless required by applicable law or agreed to in writing, 15*b1cdbd2cSJim Jagielski# software distributed under the License is distributed on an 16*b1cdbd2cSJim Jagielski# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17*b1cdbd2cSJim Jagielski# KIND, either express or implied. See the License for the 18*b1cdbd2cSJim Jagielski# specific language governing permissions and limitations 19*b1cdbd2cSJim Jagielski# under the License. 20*b1cdbd2cSJim Jagielski# 21*b1cdbd2cSJim Jagielski# ************************************************************* 22*b1cdbd2cSJim Jagielski 23*b1cdbd2cSJim Jagielski# tries to locate the executable specified 24*b1cdbd2cSJim Jagielski# as first parameter in the user's path. 25*b1cdbd2cSJim Jagielskiwhich() { 26*b1cdbd2cSJim Jagielski if [ ! -z "$1" ]; then 27*b1cdbd2cSJim Jagielski for i in `echo $PATH | sed -e 's/^:/.:/g' -e 's/:$/:./g' -e 's/::/:.:/g' -e 's/:/ /g'`; do 28*b1cdbd2cSJim Jagielski if [ -x "$i/$1" -a ! -d "$i/$1" ]; then 29*b1cdbd2cSJim Jagielski echo "$i/$1" 30*b1cdbd2cSJim Jagielski break; 31*b1cdbd2cSJim Jagielski fi 32*b1cdbd2cSJim Jagielski done 33*b1cdbd2cSJim Jagielski fi 34*b1cdbd2cSJim Jagielski} 35*b1cdbd2cSJim Jagielski 36*b1cdbd2cSJim Jagielski# checks for the original mozilla start script(s) 37*b1cdbd2cSJim Jagielski# and restrict the "-remote" semantics to those. 38*b1cdbd2cSJim Jagielskirun_mozilla() { 39*b1cdbd2cSJim Jagielski if file "$1" | grep "script" > /dev/null && grep "NPL" "$1" > /dev/null; then 40*b1cdbd2cSJim Jagielski "$1" -remote 'ping()' 2>/dev/null >/dev/null 41*b1cdbd2cSJim Jagielski if [ $? -eq 2 ]; then 42*b1cdbd2cSJim Jagielski "$1" "$2" & 43*b1cdbd2cSJim Jagielski else 44*b1cdbd2cSJim Jagielski "$1" -remote "openURL($2, new-window)" & 45*b1cdbd2cSJim Jagielski fi 46*b1cdbd2cSJim Jagielski else 47*b1cdbd2cSJim Jagielski "$1" "$2" & 48*b1cdbd2cSJim Jagielski fi 49*b1cdbd2cSJim Jagielski} 50*b1cdbd2cSJim Jagielski 51*b1cdbd2cSJim Jagielski# checks the browser value for a %s as defined in 52*b1cdbd2cSJim Jagielski# http://www.catb.org/~esr/BROWSER/index.html 53*b1cdbd2cSJim Jagielskirun_browser() { 54*b1cdbd2cSJim Jagielski echo "$1|$2" | awk ' 55*b1cdbd2cSJim Jagielski{ 56*b1cdbd2cSJim Jagielski FS="|"; 57*b1cdbd2cSJim Jagielski $syscmd=""; 58*b1cdbd2cSJim Jagielski if (index($1,"%s") > 0) { 59*b1cdbd2cSJim Jagielski $syscmd=sprintf($1,$2); 60*b1cdbd2cSJim Jagielski } else { 61*b1cdbd2cSJim Jagielski $syscmd=sprintf("%s \"%s\"",$1,$2); 62*b1cdbd2cSJim Jagielski } 63*b1cdbd2cSJim Jagielski system($syscmd " &"); 64*b1cdbd2cSJim Jagielski}' > /dev/null 65*b1cdbd2cSJim Jagielski} 66*b1cdbd2cSJim Jagielski 67*b1cdbd2cSJim Jagielski# special handling for mailto: uris 68*b1cdbd2cSJim Jagielskiif echo $1 | grep '^mailto:' > /dev/null; then 69*b1cdbd2cSJim Jagielski # check for xdg-email 70*b1cdbd2cSJim Jagielski mailer=`which xdg-email` 71*b1cdbd2cSJim Jagielski if [ ! -z "$mailer" ]; then 72*b1cdbd2cSJim Jagielski $mailer "$1" & 73*b1cdbd2cSJim Jagielski exit 0 74*b1cdbd2cSJim Jagielski fi 75*b1cdbd2cSJim Jagielski # check $MAILER variable 76*b1cdbd2cSJim Jagielski if [ ! -z "$MAILER" ]; then 77*b1cdbd2cSJim Jagielski $MAILER "$1" & 78*b1cdbd2cSJim Jagielski exit 0 79*b1cdbd2cSJim Jagielski fi 80*b1cdbd2cSJim Jagielski # mozilla derivates may need -remote semantics 81*b1cdbd2cSJim Jagielski for i in thunderbird mozilla netscape; do 82*b1cdbd2cSJim Jagielski mailer=`which $i` 83*b1cdbd2cSJim Jagielski if [ ! -z "$mailer" ]; then 84*b1cdbd2cSJim Jagielski run_mozilla "$mailer" "$1" 85*b1cdbd2cSJim Jagielski exit 0 86*b1cdbd2cSJim Jagielski fi 87*b1cdbd2cSJim Jagielski done 88*b1cdbd2cSJim Jagielski # handle all non mozilla mail clients below 89*b1cdbd2cSJim Jagielski # .. 90*b1cdbd2cSJim Jagielskielse 91*b1cdbd2cSJim Jagielski # check for xdg-open 92*b1cdbd2cSJim Jagielski browser=`which xdg-open` 93*b1cdbd2cSJim Jagielski if [ ! -z "$browser" ]; then 94*b1cdbd2cSJim Jagielski $browser "$1" & 95*b1cdbd2cSJim Jagielski exit 0 96*b1cdbd2cSJim Jagielski fi 97*b1cdbd2cSJim Jagielski # check $BROWSER variable 98*b1cdbd2cSJim Jagielski if [ ! -z "$BROWSER" ]; then 99*b1cdbd2cSJim Jagielski $BROWSER "$1" & 100*b1cdbd2cSJim Jagielski exit 0 101*b1cdbd2cSJim Jagielski fi 102*b1cdbd2cSJim Jagielski # mozilla derivates may need -remote semantics 103*b1cdbd2cSJim Jagielski for i in firefox mozilla netscape; do 104*b1cdbd2cSJim Jagielski browser=`which $i` 105*b1cdbd2cSJim Jagielski if [ ! -z "$browser" ]; then 106*b1cdbd2cSJim Jagielski run_mozilla "$browser" "$1" 107*b1cdbd2cSJim Jagielski exit 0 108*b1cdbd2cSJim Jagielski fi 109*b1cdbd2cSJim Jagielski done 110*b1cdbd2cSJim Jagielski # handle all non mozilla browers below 111*b1cdbd2cSJim Jagielski # .. 112*b1cdbd2cSJim Jagielskifi 113*b1cdbd2cSJim Jagielskiexit 1 114