Ken Mixter | 689b9ee | 2010-01-07 18:23:52 -0800 | [diff] [blame^] | 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 |
| 3 | # found in the LICENSE file. |
| 4 | |
| 5 | # Library for setting up remote access and running remote commands. |
| 6 | |
| 7 | DEFAULT_PRIVATE_KEY="$SRC_ROOT/platform/testing/testing_rsa" |
| 8 | |
| 9 | DEFINE_string remote "" "remote hostname/IP of running Chromium OS instance" |
| 10 | DEFINE_string private_key "$DEFAULT_PRIVATE_KEY" \ |
| 11 | "Private key of root account on remote host" |
| 12 | |
| 13 | function remote_sh() { |
| 14 | # Disable strict host checking so that we don't prompt the user when |
| 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]} |
| 19 | } |
| 20 | |
| 21 | function remote_sh_allow_changed_host_key() { |
| 22 | rm -f $TMP_KNOWN_HOSTS |
| 23 | remote_sh "$@" |
| 24 | } |
| 25 | |
| 26 | function set_up_remote_access() { |
| 27 | if [ -z "$SSH_AGENT_PID" ]; then |
| 28 | eval `ssh-agent` |
| 29 | fi |
| 30 | cp $FLAGS_private_key $TMP_PRIVATE_KEY |
| 31 | chmod 0400 $TMP_PRIVATE_KEY |
| 32 | ssh-add $TMP_PRIVATE_KEY |
| 33 | |
| 34 | # Verify the client is reachable before continuing |
| 35 | echo "Initiating first contact with remote host" |
| 36 | remote_sh "true" |
| 37 | echo "Connection OK" |
| 38 | } |
| 39 | |
| 40 | function remote_access_init() { |
| 41 | TMP_PRIVATE_KEY=$TMP/private_key |
| 42 | TMP_KNOWN_HOSTS=$TMP/known_hosts |
| 43 | if [ -z "$FLAGS_remote" ]; then |
| 44 | echo "Please specify --remote=<IP-or-hostname> of the Chromium OS instance" |
| 45 | exit 1 |
| 46 | fi |
| 47 | set_up_remote_access |
| 48 | } |