1*538aa54dSGarrett D'Amore#!/usr/bin/ksh 2*538aa54dSGarrett D'Amore# 3*538aa54dSGarrett D'Amore# 4*538aa54dSGarrett D'Amore# This file and its contents are supplied under the terms of the 5*538aa54dSGarrett D'Amore# Common Development and Distribution License ("CDDL"), version 1.0. 6*538aa54dSGarrett D'Amore# You may only use this file in accordance with the terms of version 7*538aa54dSGarrett D'Amore# 1.0 of the CDDL. 8*538aa54dSGarrett D'Amore# 9*538aa54dSGarrett D'Amore# A full copy of the text of the CDDL should have accompanied this 10*538aa54dSGarrett D'Amore# source. A copy of the CDDL is also available via the Internet at 11*538aa54dSGarrett D'Amore# http://www.illumos.org/license/CDDL. 12*538aa54dSGarrett D'Amore# 13*538aa54dSGarrett D'Amore 14*538aa54dSGarrett D'Amore# 15*538aa54dSGarrett D'Amore# Copyright 2014 Garrett D'Amore <garrett@damore.org> 16*538aa54dSGarrett D'Amore# 17*538aa54dSGarrett D'Amore 18*538aa54dSGarrett D'Amore# First we set $dir to dirname $0, and $prog to basename $0 .ksh, 19*538aa54dSGarrett D'Amore# using efficient ksh builtins. 20*538aa54dSGarrett D'Amorecase $0 in 21*538aa54dSGarrett D'Amore*/*) 22*538aa54dSGarrett D'Amore dir=${0%/*} 23*538aa54dSGarrett D'Amore prog=${0##*/} 24*538aa54dSGarrett D'Amore ;; 25*538aa54dSGarrett D'Amore*) 26*538aa54dSGarrett D'Amore dir=. 27*538aa54dSGarrett D'Amore prog=${0} 28*538aa54dSGarrett D'Amore ;; 29*538aa54dSGarrett D'Amoreesac 30*538aa54dSGarrett D'Amoreprog=${prog%.ksh} 31*538aa54dSGarrett D'Amore 32*538aa54dSGarrett D'Amorefor a in $* 33*538aa54dSGarrett D'Amoredo 34*538aa54dSGarrett D'Amore if [[ $a == "-d" ]] 35*538aa54dSGarrett D'Amore then 36*538aa54dSGarrett D'Amore debug=yes 37*538aa54dSGarrett D'Amore fi 38*538aa54dSGarrett D'Amoredone 39*538aa54dSGarrett D'Amore 40*538aa54dSGarrett D'Amore# We look for architecture specific versions of the program, 41*538aa54dSGarrett D'Amore# searching in several candidate directories. We run each one as 42*538aa54dSGarrett D'Amore# we find it. 43*538aa54dSGarrett D'Amorefor f in $(/usr/bin/isainfo) 44*538aa54dSGarrett D'Amoredo 45*538aa54dSGarrett D'Amore found= 46*538aa54dSGarrett D'Amore [[ -n $debug ]] && print "Checking for arch $f:" 47*538aa54dSGarrett D'Amore for p in \ 48*538aa54dSGarrett D'Amore ${dir}/${prog}.${f} \ 49*538aa54dSGarrett D'Amore ${dir}/${f}/${prog}.${f} \ 50*538aa54dSGarrett D'Amore ${dir}/${f}/${prog} 51*538aa54dSGarrett D'Amore do 52*538aa54dSGarrett D'Amore [[ -n $found ]] && continue 53*538aa54dSGarrett D'Amore [[ -n $debug ]] && print -n " $p" 54*538aa54dSGarrett D'Amore if [[ -f $p ]]; then 55*538aa54dSGarrett D'Amore [[ -n $debug ]] && print " FOUND" 56*538aa54dSGarrett D'Amore [[ -n $debug ]] && print "Executing $p $*" 57*538aa54dSGarrett D'Amore found=yes 58*538aa54dSGarrett D'Amore $p $* || exit 1 59*538aa54dSGarrett D'Amore else 60*538aa54dSGarrett D'Amore [[ -n $debug ]] && print 61*538aa54dSGarrett D'Amore fi 62*538aa54dSGarrett D'Amore done 63*538aa54dSGarrett D'Amore [[ -z $found ]] && [[ -n $debug ]] && print "NOT PRESENT" 64*538aa54dSGarrett D'Amoredone 65*538aa54dSGarrett D'Amoreexit 0 66