-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtranslator
More file actions
54 lines (41 loc) · 1.64 KB
/
Copy pathtranslator
File metadata and controls
54 lines (41 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/bash
# bash script to execute ./lib/${CS_ARCH}/${CMD} where
# CS_ARCH is to be determined, hopefully macos or cats
# CMD is the basename of this script
# script checks we are on a 64-bit system before doing anything else
# check we on a 64-bit OS
test `getconf LONG_BIT` != "64" && echo "Sorry, this only runs on a 64-bit operating system!" && exit -1
# break open a pathname to our command - the original must include '/' somewhere
complete_fullpath()
{
original="${1}"
architecture="${2}"
# executable's name - drop everything up to the last /
command="${original##*/}"
# parent directory's path - drop everything after the last /
fullpath="${original%/*}"
# fullpath must be shorter than original if it contained a directory, ie /
if [ "${fullpath}" == "${original}" ] ; then
echo "Cannot find the architecture specific version of ${original}"
echo "A directory name must be included in the pathname used to execute it"
exit -1
fi
# work out full path to command's directory using cd and pwd in a sub-shell
fullpath=$( (cd "${fullpath}" && pwd) )
# construct final path
fullpath="${fullpath}/lib/${architecture}/${command}"
# check that it is executable
if [ ! -x "${fullpath}" ] ; then
echo "Cannot find the architecture specific version of ${original}"
echo "Have you run make?"
exit -1
fi
}
# if on a Mac architecture is macos, otherwise cats
if test -x /usr/bin/uname && test `/usr/bin/uname -s` == "Darwin" ; then
architecture="macos"
else
architecture="cats"
fi
complete_fullpath "${0}" "${architecture}"
exec "${fullpath}" "${@}"