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 | |
Sean O'Connor | a6db82e | 2010-01-27 12:11:08 -0800 | [diff] [blame^] | 7 | DEFAULT_PRIVATE_KEY="${GCLIENT_ROOT}/src/scripts/mod_for_test_scripts/\ |
| 8 | ssh_keys/testing_rsa" |
Ken Mixter | 689b9ee | 2010-01-07 18:23:52 -0800 | [diff] [blame] | 9 | |
| 10 | DEFINE_string remote "" "remote hostname/IP of running Chromium OS instance" |
| 11 | DEFINE_string private_key "$DEFAULT_PRIVATE_KEY" \ |
| 12 | "Private key of root account on remote host" |
| 13 | |
| 14 | function remote_sh() { |
Sean O'Connor | a6db82e | 2010-01-27 12:11:08 -0800 | [diff] [blame^] | 15 | REMOTE_OUT=$(ssh -o StrictHostKeyChecking=no -o \ |
Ken Mixter | 689b9ee | 2010-01-07 18:23:52 -0800 | [diff] [blame] | 16 | UserKnownHostsFile=$TMP_KNOWN_HOSTS root@$FLAGS_remote "$@") |
| 17 | return ${PIPESTATUS[0]} |
| 18 | } |
| 19 | |
| 20 | function remote_sh_allow_changed_host_key() { |
| 21 | rm -f $TMP_KNOWN_HOSTS |
| 22 | remote_sh "$@" |
| 23 | } |
| 24 | |
| 25 | function set_up_remote_access() { |
| 26 | if [ -z "$SSH_AGENT_PID" ]; then |
Sean O'Connor | a6db82e | 2010-01-27 12:11:08 -0800 | [diff] [blame^] | 27 | eval $(ssh-agent) |
Ken Mixter | 689b9ee | 2010-01-07 18:23:52 -0800 | [diff] [blame] | 28 | fi |
| 29 | cp $FLAGS_private_key $TMP_PRIVATE_KEY |
| 30 | chmod 0400 $TMP_PRIVATE_KEY |
| 31 | ssh-add $TMP_PRIVATE_KEY |
| 32 | |
| 33 | # Verify the client is reachable before continuing |
| 34 | echo "Initiating first contact with remote host" |
| 35 | remote_sh "true" |
| 36 | echo "Connection OK" |
| 37 | } |
| 38 | |
| 39 | function remote_access_init() { |
| 40 | TMP_PRIVATE_KEY=$TMP/private_key |
| 41 | TMP_KNOWN_HOSTS=$TMP/known_hosts |
| 42 | if [ -z "$FLAGS_remote" ]; then |
| 43 | echo "Please specify --remote=<IP-or-hostname> of the Chromium OS instance" |
| 44 | exit 1 |
| 45 | fi |
| 46 | set_up_remote_access |
| 47 | } |