1*344a7f5eSAndroid Build Coastguard Worker#!/bin/bash 2*344a7f5eSAndroid Build Coastguard Worker# 3*344a7f5eSAndroid Build Coastguard Worker# Copyright (C) 2016 The Android Open Source Project 4*344a7f5eSAndroid Build Coastguard Worker# 5*344a7f5eSAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License"); 6*344a7f5eSAndroid Build Coastguard Worker# you may not use this file except in compliance with the License. 7*344a7f5eSAndroid Build Coastguard Worker# You may obtain a copy of the License at 8*344a7f5eSAndroid Build Coastguard Worker# 9*344a7f5eSAndroid Build Coastguard Worker# http://www.apache.org/licenses/LICENSE-2.0 10*344a7f5eSAndroid Build Coastguard Worker# 11*344a7f5eSAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software 12*344a7f5eSAndroid Build Coastguard Worker# distributed under the License is distributed on an "AS IS" BASIS, 13*344a7f5eSAndroid Build Coastguard Worker# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14*344a7f5eSAndroid Build Coastguard Worker# See the License for the specific language governing permissions and 15*344a7f5eSAndroid Build Coastguard Worker# limitations under the License. 16*344a7f5eSAndroid Build Coastguard Worker 17*344a7f5eSAndroid Build Coastguard Worker# Set up prog to be the path of this script, including following symlinks, 18*344a7f5eSAndroid Build Coastguard Worker# and set up progdir to be the fully-qualified pathname of its directory. 19*344a7f5eSAndroid Build Coastguard Workerprog="$0" 20*344a7f5eSAndroid Build Coastguard Workerwhile [ -h "${prog}" ]; do 21*344a7f5eSAndroid Build Coastguard Worker newProg=`/bin/ls -ld "${prog}"` 22*344a7f5eSAndroid Build Coastguard Worker newProg=`expr "${newProg}" : ".* -> \(.*\)$"` 23*344a7f5eSAndroid Build Coastguard Worker if expr "x${newProg}" : 'x/' >/dev/null; then 24*344a7f5eSAndroid Build Coastguard Worker prog="${newProg}" 25*344a7f5eSAndroid Build Coastguard Worker else 26*344a7f5eSAndroid Build Coastguard Worker progdir=`dirname "${prog}"` 27*344a7f5eSAndroid Build Coastguard Worker prog="${progdir}/${newProg}" 28*344a7f5eSAndroid Build Coastguard Worker fi 29*344a7f5eSAndroid Build Coastguard Workerdone 30*344a7f5eSAndroid Build Coastguard Workeroldwd=`pwd` 31*344a7f5eSAndroid Build Coastguard Workerprogdir=`dirname "${prog}"` 32*344a7f5eSAndroid Build Coastguard Workercd "${progdir}" 33*344a7f5eSAndroid Build Coastguard Workerprogdir=`pwd` 34*344a7f5eSAndroid Build Coastguard Workerprog="${progdir}"/`basename "${prog}"` 35*344a7f5eSAndroid Build Coastguard Workercd "${oldwd}" 36*344a7f5eSAndroid Build Coastguard Worker 37*344a7f5eSAndroid Build Coastguard Workerjarfile=apksigner.jar 38*344a7f5eSAndroid Build Coastguard Workerlibdir="$progdir" 39*344a7f5eSAndroid Build Coastguard Worker 40*344a7f5eSAndroid Build Coastguard Workerif [ ! -r "$libdir/$jarfile" ]; then 41*344a7f5eSAndroid Build Coastguard Worker # set apksigner.jar location for the SDK case 42*344a7f5eSAndroid Build Coastguard Worker libdir="$libdir/lib" 43*344a7f5eSAndroid Build Coastguard Workerfi 44*344a7f5eSAndroid Build Coastguard Worker 45*344a7f5eSAndroid Build Coastguard Worker 46*344a7f5eSAndroid Build Coastguard Workerif [ ! -r "$libdir/$jarfile" ]; then 47*344a7f5eSAndroid Build Coastguard Worker # set apksigner.jar location for the Android tree case 48*344a7f5eSAndroid Build Coastguard Worker libdir=`dirname "$progdir"`/framework 49*344a7f5eSAndroid Build Coastguard Worker # also include the library directory for any provider native libraries 50*344a7f5eSAndroid Build Coastguard Worker providerLibdir=`dirname "$progdir"`/lib64 51*344a7f5eSAndroid Build Coastguard Workerfi 52*344a7f5eSAndroid Build Coastguard Worker 53*344a7f5eSAndroid Build Coastguard Workerif [ ! -r "$libdir/$jarfile" ]; then 54*344a7f5eSAndroid Build Coastguard Worker echo `basename "$prog"`": can't find $jarfile" 55*344a7f5eSAndroid Build Coastguard Worker exit 1 56*344a7f5eSAndroid Build Coastguard Workerfi 57*344a7f5eSAndroid Build Coastguard Worker 58*344a7f5eSAndroid Build Coastguard Worker# By default, give apksigner a max heap size of 1 gig. This can be overridden 59*344a7f5eSAndroid Build Coastguard Worker# by using a "-J" option (see below). 60*344a7f5eSAndroid Build Coastguard WorkerdefaultMx="-Xmx1024M" 61*344a7f5eSAndroid Build Coastguard Worker 62*344a7f5eSAndroid Build Coastguard Worker# The following will extract any initial parameters of the form 63*344a7f5eSAndroid Build Coastguard Worker# "-J<stuff>" from the command line and pass them to the Java 64*344a7f5eSAndroid Build Coastguard Worker# invocation (instead of to apksigner). This makes it possible for you to add 65*344a7f5eSAndroid Build Coastguard Worker# a command-line parameter such as "-JXmx256M" in your scripts, for 66*344a7f5eSAndroid Build Coastguard Worker# example. "java" (with no args) and "java -X" give a summary of 67*344a7f5eSAndroid Build Coastguard Worker# available options. 68*344a7f5eSAndroid Build Coastguard Worker 69*344a7f5eSAndroid Build Coastguard WorkerjavaOpts="" 70*344a7f5eSAndroid Build Coastguard Worker 71*344a7f5eSAndroid Build Coastguard Workerwhile expr "x$1" : 'x-J' >/dev/null; do 72*344a7f5eSAndroid Build Coastguard Worker opt=`expr "x$1" : 'x-J\(.*\)'` 73*344a7f5eSAndroid Build Coastguard Worker javaOpts="${javaOpts} -${opt}" 74*344a7f5eSAndroid Build Coastguard Worker if expr "x${opt}" : "xXmx[0-9]" >/dev/null; then 75*344a7f5eSAndroid Build Coastguard Worker defaultMx="no" 76*344a7f5eSAndroid Build Coastguard Worker elif expr "x${opt}" : "xDjava.library.path=" >/dev/null; then 77*344a7f5eSAndroid Build Coastguard Worker defaultLibdir="no" 78*344a7f5eSAndroid Build Coastguard Worker fi 79*344a7f5eSAndroid Build Coastguard Worker shift 80*344a7f5eSAndroid Build Coastguard Workerdone 81*344a7f5eSAndroid Build Coastguard Worker 82*344a7f5eSAndroid Build Coastguard Workerif [ "${defaultMx}" != "no" ]; then 83*344a7f5eSAndroid Build Coastguard Worker javaOpts="${javaOpts} ${defaultMx}" 84*344a7f5eSAndroid Build Coastguard Workerfi 85*344a7f5eSAndroid Build Coastguard Worker 86*344a7f5eSAndroid Build Coastguard Workerif [ "${defaultLibdir}" != "no" ] && [ -n $providerLibdir ]; then 87*344a7f5eSAndroid Build Coastguard Worker javaOpts="${javaOpts} -Djava.library.path=$providerLibdir" 88*344a7f5eSAndroid Build Coastguard Workerfi 89*344a7f5eSAndroid Build Coastguard Worker 90*344a7f5eSAndroid Build Coastguard Workerif [ "$OSTYPE" = "cygwin" ]; then 91*344a7f5eSAndroid Build Coastguard Worker # For Cygwin, convert the jarfile path into native Windows style. 92*344a7f5eSAndroid Build Coastguard Worker jarpath=`cygpath -w "$libdir/$jarfile"` 93*344a7f5eSAndroid Build Coastguard Workerelse 94*344a7f5eSAndroid Build Coastguard Worker jarpath="$libdir/$jarfile" 95*344a7f5eSAndroid Build Coastguard Workerfi 96*344a7f5eSAndroid Build Coastguard Worker 97*344a7f5eSAndroid Build Coastguard Workerexec java $javaOpts -jar "$jarpath" "$@" 98