xref: /illumos-gate/usr/src/contrib/ast/src/cmd/INIT/execrate.sh (revision b30d193948be5a7794d7ae3ba0ed9c2f72c88e0f)
1########################################################################
2#                                                                      #
3#               This software is part of the ast package               #
4#          Copyright (c) 1994-2011 AT&T Intellectual Property          #
5#                      and is licensed under the                       #
6#                 Eclipse Public License, Version 1.0                  #
7#                    by AT&T Intellectual Property                     #
8#                                                                      #
9#                A copy of the License is available at                 #
10#          http://www.eclipse.org/org/documents/epl-v10.html           #
11#         (with md5 checksum b35adb5213ca9657e911e9befb180842)         #
12#                                                                      #
13#              Information and Software Systems Research               #
14#                            AT&T Research                             #
15#                           Florham Park NJ                            #
16#                                                                      #
17#                 Glenn Fowler <gsf@research.att.com>                  #
18#                                                                      #
19########################################################################
20: wrapper for .exe challenged win32 systems/commands
21
22command=execrate
23
24bins='/bin /usr/bin /usr/sbin'
25
26case `(getopts '[-][123:xyz]' opt --xyz; echo 0$opt) 2>/dev/null` in
270123)	ARGV0="-a $command"
28	USAGE=$'
29[-?
30@(#)$Id: execrate (AT&T Labs Research) 2002-02-02 $
31]
32'$USAGE_LICENSE$'
33[+NAME?execrate - wrapper for .exe challenged commands]
34[+DESCRIPTION?\bexecrate\b runs \acommand\a after checking the \afile\a
35	operands for standard semantics with respect to \bwin32\b \b.exe\b
36	suffix conventions. This command is only needed on \bwin32\b
37	systems that inconsistently handle \b.exe\b across library and
38	command interfaces. \acommand\a may be one of \bcat\b(1), \bchmod\b(1),
39	\bcmp\b(1), \bcp\b(1), \bln\b(1), \bmv\b(1), or \brm\b(1).
40	Only the 2 argument forms of \bcp\b, \bln\b and \bmv\b are handled.
41	Unsupported commands and commands requiring no change are
42	silently executed.]
43[+?With no arguments \bexecrate\b exits with status 0 if the current system
44	is \b.exe\b challenged, 1 if the current system is normal.]
45[n:show?Show the underlying commands but do not execute.]
46
47command [ option ... ] file ...
48
49[+SEE ALSO?\bwebster\b(1)]
50'
51	usage()
52	{
53		OPTIND=0
54		getopts $ARGV0 "$USAGE" OPT '-?'
55		exit 2
56	}
57	exec=1
58	while	getopts $ARGV0 "$USAGE" OPT
59	do	case $OPT in
60		n)	exec=0 ;;
61		*)	usage ;;
62		esac
63	done
64	shift `expr $OPTIND - 1`
65	;;
66*)	usage()
67	{
68		echo "Usage: execrate [ -n ] [ command [ option ... ] file ... ]" >&2
69		exit 2
70	}
71	exec=1
72	while	:
73	do	case $1 in
74		-n)	exec=0 ;;
75		-*)	usage ;;
76		*)	break ;;
77		esac
78		shift
79	done
80	;;
81esac
82case $# in
830)	if	test ! -x /bin/cat.exe
84	then	exit 1 # normal
85	fi
86	if	/bin/cat /bin/cat >/dev/null 2>&1
87	then	exit 1 # normal
88	fi
89	exit 0 # challenged
90	;;
911)	usage
92	;;
93esac
94case $1 in
95*cat|*rm)
96	NUM=0
97	;;
98*chgrp|*chmod)
99	NUM=1
100	;;
101*cmp|*cp|*ln|*mv)
102	NUM=2
103	;;
104*)	case $exec in
105	0)	echo "$@" ;;
106	*)	"$@" ;;
107	esac
108	exit
109	;;
110esac
111CMD=$1
112shift
113case $CMD in
114*/*)	;;
115*)	for d in $bins
116	do	if	test -x $d/$1 -o -x $d/$1.exe
117		then	CMD=$d/$1
118			break
119		fi
120	done
121	;;
122esac
123while	:
124do	case $1 in
125	-*)	CMD="$CMD $1" ;;
126	*)	break ;;
127	esac
128	shift
129done
130case $exec in
1310)	CMD="echo $CMD" ;;
132esac
133case $NUM:$# in
134*:0)	;;
1351:*)	CMD="$CMD $1"
136	NUM=0
137	shift
138	;;
139esac
140case $NUM:$# in
1410:*)	status=0
142	for f
143	do	if	test "$f" -ef "$f".exe
144		then	f=$f.exe
145		fi
146		$CMD "$f"
147		case $? in
148		0)	;;
149		*)	status=$? ;;
150		esac
151	done
152	exit $status
153	;;
1542:2)	f=$1
155	case $f in
156	*.exe)	;;
157	*)	if	test "$f" -ef "$f".exe
158		then	f=$f.exe
159		fi
160		;;
161	esac
162	case $f in
163	*.exe)	if	test -d "$2"
164		then	t=$2/$f
165		else	t=$2
166		fi
167		case $t in
168		*/*)	b=`basename "$t"` ;;
169		*)	b=$t ;;
170		esac
171		case $b in
172		*.*)	$CMD "$f" "$t"; exit ;;
173		*)	$CMD "$f" "$t".exe; exit ;;
174		esac
175		;;
176	esac
177	;;
178esac
179$CMD "$@"
180