llvm.org GIT mirror llvm / a266b5f
Helper script to use bugpoint with a remote target. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@75669 91177308-0d34-0410-b5e6-96231b3b80d8 Viktor Kutuzov 11 years ago
1 changed file(s) with 108 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 #!/bin/sh
1 #
2 # Program: RemoteRunSafely.sh
3 #
4 # Synopsis: This script simply runs another program remotely using rsh.
5 # It always returns the another program exit code.
6 #
7 # (?) only exit statuses that indicates that the program could not be executed
8 # normally is considered to indicate a test failure.
9 #
10 # Syntax:
11 #
12 # RemoteRunSafely.sh [-l ] [-p ]
13 #
14 #
15 # where:
16 # is the remote host to execute the program,
17 # is the username on the remote host,
18 # is the port used by the remote client,
19 # is the path to the program to run,
20 # are the arguments to pass to the program.
21 #
22
23 printUsageAndExit()
24 {
25 echo "Usage:"
26 echo "./RemoteRunSafely.sh [-l ] [-p ] " \
27 "[cd ] "
28 exit 1
29 }
30
31 moreArgsExpected()
32 {
33 # $1 - remaining number of arguments
34 # $2 - number of arguments to shift
35 if [ $1 -lt $2 ]
36 then
37 echo "Error: Wrong number of argumants."
38 printUsageAndExit
39 fi
40 }
41
42 # Save a copy of the original arguments in a string before we
43 # clobber them with the shift command.
44 ORIG_ARGS="$*"
45 #DEBUG: echo 'GOT: '$ORIG_ARGS
46
47 moreArgsExpected $# 1
48 RHOST=$1
49 shift 1
50
51 RUSER=`id -un`
52 RCLIENT=ssh
53 RPORT=
54 WORKING_DIR=
55
56 moreArgsExpected $# 1
57 if [ $1 = "-l" ]; then
58 moreArgsExpected $# 2
59 RUSER=$2
60 shift 2
61 fi
62 moreArgsExpected $# 1
63 if [ $1 = "-p" ]; then
64 moreArgsExpected $# 2
65 RPORT="-p $2"
66 shift 2
67 fi
68
69 moreArgsExpected $# 1
70 PROGRAM=$(basename $1)
71 WORKING_DIR=$(dirname $1)
72 shift 1
73
74 #DEBUG: echo 'DIR='${0%%`basename $0`}
75 #DEBUG: echo 'RHOST='$RHOST
76 #DEBUG: echo 'RUSER='$RUSER
77 #DEBUG: echo 'PROGRAM='$PROGRAM
78 #DEBUG: echo 'WORKING_DIR='$WORKING_DIR
79 #DEBUG: echo 'ARGS='$*
80
81 # Sanity check
82 if [ "$RHOST" = "" -o "$PROGRAM" = "" ]; then
83 printUsageAndExit
84 fi
85
86 # Local program file must exist and be execuatble
87 local_program=$WORKING_DIR"/"$PROGRAM
88 if [ ! -x "$local_program" ]; then
89 echo "File "$local_program" does not exist or is not an executable.."
90 exit 2
91 fi
92
93 connection=$RUSER'@'$RHOST
94 remote="./"$PROGRAM
95 (
96 cat $local_program | \
97 $RCLIENT $connection $RPORT \
98 'rm -f '$remote' ; ' \
99 'cat > '$remote' ; chmod +x '$remote' ; '$remote' '$*' ; ' \
100 'echo exit $? ; ' \
101 'rm -f '$remote
102 )
103
104 #DEBUG: err=$?
105 #DEBUG: echo script exit $err
106 #DEBUG: exit $err
107