| OLD | NEW |
| 1 # Copyright (c) 2009 The Chromium OS Authors. All rights reserved. | 1 # Copyright (c) 2009 The Chromium OS Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 # Library for setting up remote access and running remote commands. | 5 # Library for setting up remote access and running remote commands. |
| 6 | 6 |
| 7 DEFAULT_PRIVATE_KEY="$SRC_ROOT/platform/testing/testing_rsa" | 7 DEFAULT_PRIVATE_KEY="${GCLIENT_ROOT}/scripts/mod_for_test_scripts/ssh_keys/\ |
| 8 testing_rsa" |
| 8 | 9 |
| 9 DEFINE_string remote "" "remote hostname/IP of running Chromium OS instance" | 10 DEFINE_string remote "" "remote hostname/IP of running Chromium OS instance" |
| 10 DEFINE_string private_key "$DEFAULT_PRIVATE_KEY" \ | 11 DEFINE_string private_key "$DEFAULT_PRIVATE_KEY" \ |
| 11 "Private key of root account on remote host" | 12 "Private key of root account on remote host" |
| 12 | 13 |
| 13 function remote_sh() { | 14 function remote_sh() { |
| 14 # Disable strict host checking so that we don't prompt the user when | 15 REMOTE_OUT=$(ssh root@$FLAGS_remote "$@") |
| 15 # the host key file is removed and just go ahead and add it. | |
| 16 REMOTE_OUT=$(ssh -o StrictHostKeyChecking=no -o \ | |
| 17 UserKnownHostsFile=$TMP_KNOWN_HOSTS root@$FLAGS_remote "$@") | |
| 18 return ${PIPESTATUS[0]} | 16 return ${PIPESTATUS[0]} |
| 19 } | 17 } |
| 20 | 18 |
| 21 function remote_sh_allow_changed_host_key() { | 19 function remote_sh_allow_changed_host_key() { |
| 22 rm -f $TMP_KNOWN_HOSTS | 20 rm -f $TMP_KNOWN_HOSTS |
| 23 remote_sh "$@" | 21 remote_sh "$@" |
| 24 } | 22 } |
| 25 | 23 |
| 26 function set_up_remote_access() { | 24 function set_up_remote_access() { |
| 27 if [ -z "$SSH_AGENT_PID" ]; then | 25 if [ -z "$SSH_AGENT_PID" ]; then |
| 28 eval `ssh-agent` | 26 eval $(ssh-agent) |
| 29 fi | 27 fi |
| 30 cp $FLAGS_private_key $TMP_PRIVATE_KEY | 28 cp $FLAGS_private_key $TMP_PRIVATE_KEY |
| 31 chmod 0400 $TMP_PRIVATE_KEY | 29 chmod 0400 $TMP_PRIVATE_KEY |
| 32 ssh-add $TMP_PRIVATE_KEY | 30 ssh-add $TMP_PRIVATE_KEY |
| 33 | 31 |
| 34 # Verify the client is reachable before continuing | 32 # Verify the client is reachable before continuing |
| 35 echo "Initiating first contact with remote host" | 33 echo "Initiating first contact with remote host" |
| 36 remote_sh "true" | 34 remote_sh "true" |
| 37 echo "Connection OK" | 35 echo "Connection OK" |
| 38 } | 36 } |
| 39 | 37 |
| 40 function remote_access_init() { | 38 function remote_access_init() { |
| 41 TMP_PRIVATE_KEY=$TMP/private_key | 39 TMP_PRIVATE_KEY=$TMP/private_key |
| 42 TMP_KNOWN_HOSTS=$TMP/known_hosts | 40 TMP_KNOWN_HOSTS=$TMP/known_hosts |
| 43 if [ -z "$FLAGS_remote" ]; then | 41 if [ -z "$FLAGS_remote" ]; then |
| 44 echo "Please specify --remote=<IP-or-hostname> of the Chromium OS instance" | 42 echo "Please specify --remote=<IP-or-hostname> of the Chromium OS instance" |
| 45 exit 1 | 43 exit 1 |
| 46 fi | 44 fi |
| 47 set_up_remote_access | 45 set_up_remote_access |
| 48 } | 46 } |
| OLD | NEW |