2 # ***** BEGIN LICENSE BLOCK *****
3 # Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 # The contents of this file are subject to the Mozilla Public License Version
6 # 1.1 (the "License"); you may not use this file except in compliance with
7 # the License. You may obtain a copy of the License at
8 # http://www.mozilla.org/MPL/
10 # Software distributed under the License is distributed on an "AS IS" basis,
11 # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 # for the specific language governing rights and limitations under the
15 # The Original Code is [Open Source Virtual Machine.].
17 # The Initial Developer of the Original Code is
18 # Adobe System Incorporated.
19 # Portions created by the Initial Developer are Copyright (C) 2010
20 # the Initial Developer. All Rights Reserved.
25 # Alternatively, the contents of this file may be used under the terms of
26 # either the GNU General Public License Version 2 or later (the "GPL"), or
27 # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 # in which case the provisions of the GPL or the LGPL are applicable instead
29 # of those above. If you wish to allow use of your version of this file only
30 # under the terms of either the GPL or the LGPL, and not to allow others to
31 # use your version of this file under the terms of the MPL, indicate your
32 # decision by deleting the provisions above and replace them with the notice
33 # and other provisions required by the GPL or the LGPL. If you do not delete
34 # the provisions above, a recipient may use your version of this file under
35 # the terms of any one of the MPL, the GPL or the LGPL.
37 # ***** END LICENSE BLOCK ***** */
38 # acts as a proxy to remotely run abc files via a ssh call to the remote machine
39 # usage: ./ssh_shell.sh <vmargs> file.abc
40 # assumes the shell is deployed to $SSH_SHELL_REMOTE_DIR/avmshell
43 if [ "$SSH_SHELL_REMOTE_USER" = "" ] ||
44 [ "$SSH_SHELL_REMOTE_HOST" = "" ] ||
45 [ "$SSH_SHELL_REMOTE_DIR" = "" ];
47 echo "missing environment variable: "
48 echo "SSH_SHELL_REMOTE_USER" = "$SSH_SHELL_REMOTE_USER"
49 echo "SSH_SHELL_REMOTE_HOST" = "$SSH_SHELL_REMOTE_HOST"
50 echo "SSH_SHELL_REMOTE_DIR" = "$SSH_SHELL_REMOTE_DIR"
61 function try_command
() {
63 while [ $count -le $MAX_RETRIES ]
65 # run the passed in command - not that "$@" (quoted) is used since that
66 # is the only form that will work with quoted arguments containing spaces
67 # see http://www.tldp.org/LDP/abs/html/internalvariables.html#APPREF2
71 if [ "$ec" -eq "$expectedExitCode" ]; then
72 # command ran with no errors
75 echo "Command Failed: $*"
77 echo "Try $count of $MAX_RETRIES"
82 # command failed SSH_RETRIES times, report failure and exit
83 echo "Reached max tries, exiting with exit code $ec ..."
90 # running the shell with no args prints the help and exits with exitcode 1
92 try_command
ssh $SSH_SHELL_REMOTE_USER@
$SSH_SHELL_REMOTE_HOST "cd $SSH_SHELL_REMOTE_DIR;./avmshell"
94 # Note that testfiles are copied to the SSH_SHELL_REMOTE_DIR directly and
95 # run one at a time. No dir structure is preserved when copying the files.
99 # look for an .abc file
100 echo "$a" |
grep ".*\.abc" > /dev
/null
105 flatfile
=`basename $a`
106 # check to see if flatfile is already in filelist
107 echo "$filelist" |
grep "$flatfile" > /dev
/null
109 if [ "$res" = "1" ]; then
110 # flatfile is not in filelist; add it
111 filelist
="$filelist $flatfile"
112 # copy file to device
113 try_command scp
$file $SSH_SHELL_REMOTE_USER@
$SSH_SHELL_REMOTE_HOST:$SSH_SHELL_REMOTE_DIR/$flatfile > /dev
/null
115 # even if flatfile is already in filelist, add to args
116 args
="$args $flatfile"
121 # workaround for not returning exit code, run a shell script and print exit code to stdout
122 try_command
ssh $SSH_SHELL_REMOTE_USER@
$SSH_SHELL_REMOTE_HOST "cd $SSH_SHELL_REMOTE_DIR;./ssh-shell-runner.sh $args" > .
/stdout
123 ret
=`cat ./stdout | grep "EXITCODE=" | awk -F= '{printf("%d",$2)}'`
124 # clean up copied over files
127 try_command
ssh $SSH_SHELL_REMOTE_USER@
$SSH_SHELL_REMOTE_HOST "cd $SSH_SHELL_REMOTE_DIR;rm $a"
129 # remove the EXITCODE from the stdout before returning it so that exact output matching will be fine
130 cat .
/stdout |
sed 's/^EXITCODE=[0-9][0-9]*$//g' > .
/stdout_clean
132 rm -f .
/stdout .
/stdout_clean