blob: 8b1a733340fc00303369a67e69b799ef4c5a6fc9 [file] [log] [blame]
Ken Mixter689b9ee2010-01-07 18:23:52 -08001# 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'Connora6db82e2010-01-27 12:11:08 -08007DEFAULT_PRIVATE_KEY="${GCLIENT_ROOT}/src/scripts/mod_for_test_scripts/\
8ssh_keys/testing_rsa"
Ken Mixter689b9ee2010-01-07 18:23:52 -08009
10DEFINE_string remote "" "remote hostname/IP of running Chromium OS instance"
11DEFINE_string private_key "$DEFAULT_PRIVATE_KEY" \
12 "Private key of root account on remote host"
13
14function remote_sh() {
Sean O'Connora6db82e2010-01-27 12:11:08 -080015 REMOTE_OUT=$(ssh -o StrictHostKeyChecking=no -o \
Ken Mixter689b9ee2010-01-07 18:23:52 -080016 UserKnownHostsFile=$TMP_KNOWN_HOSTS root@$FLAGS_remote "$@")
17 return ${PIPESTATUS[0]}
18}
19
20function remote_sh_allow_changed_host_key() {
21 rm -f $TMP_KNOWN_HOSTS
22 remote_sh "$@"
23}
24
25function set_up_remote_access() {
26 if [ -z "$SSH_AGENT_PID" ]; then
Sean O'Connora6db82e2010-01-27 12:11:08 -080027 eval $(ssh-agent)
Ken Mixter689b9ee2010-01-07 18:23:52 -080028 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
39function 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}