1#!/bin/bash
2#
3# Copyright (C) 2007 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9#     http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17# Set up prog to be the path of this script, including following symlinks,
18# and set up progdir to be the fully-qualified pathname of its directory.
19
20prog="$0"
21while [ -h "${prog}" ]; do
22    fullprog=`/bin/ls -ld "${prog}"`
23    fullprog=`expr "${fullprog}" : ".* -> \(.*\)$"`
24    if expr "x${fullprog}" : 'x/' >/dev/null; then
25        prog="${fullprog}"
26    else
27        progdir=`dirname "${prog}"`
28        prog="${progdir}/${fullprog}"
29    fi
30done
31
32oldwd=`pwd`
33progdir=`dirname "${prog}"`
34cd "${progdir}"
35progdir=`pwd`
36prog="${progdir}"/`basename "${prog}"`
37cd "${oldwd}"
38
39jarfile=`basename "${prog}"`.jar
40jardir="${progdir}"
41
42if [ ! -r "${jardir}/${jarfile}" ]; then
43    jardir=`dirname "${progdir}"`/framework
44fi
45
46if [ ! -r "${jardir}/${jarfile}" ]; then
47    echo `basename "${prog}"`": can't find ${jarfile}"
48    exit 1
49fi
50
51declare -a javaOpts=()
52while expr "x$1" : 'x-J' >/dev/null; do
53    opt=`expr "$1" : '-J-\{0,1\}\(.*\)'`
54    javaOpts+=("-${opt}")
55    shift
56done
57
58exec java "${javaOpts[@]}" -jar ${jardir}/${jarfile} "$@"
59