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="${GCLIENT_ROOT}/src/scripts/mod_for_test_scripts/\ | 7 DEFAULT_PRIVATE_KEY="${GCLIENT_ROOT}/src/scripts/mod_for_test_scripts/\ |
8 ssh_keys/testing_rsa" | 8 ssh_keys/testing_rsa" |
9 | 9 |
10 DEFINE_string remote "" "remote hostname/IP of running Chromium OS instance" | 10 DEFINE_string remote "" "remote hostname/IP of running Chromium OS instance" |
11 DEFINE_string private_key "$DEFAULT_PRIVATE_KEY" \ | 11 DEFINE_string private_key "$DEFAULT_PRIVATE_KEY" \ |
12 "Private key of root account on remote host" | 12 "Private key of root account on remote host" |
13 DEFINE_integer ssh_port 22 \ | 13 DEFINE_integer ssh_port 22 \ |
14 "SSH port of the remote machine running Chromium OS instance" | 14 "SSH port of the remote machine running Chromium OS instance" |
15 | 15 |
16 # Copies $1 to $2 on remote host | 16 # Copies $1 to $2 on remote host |
17 function remote_cp_to() { | 17 function remote_cp_to() { |
18 REMOTE_OUT=$(scp -P ${FLAGS_ssh_port} -o StrictHostKeyChecking=no -o \ | 18 REMOTE_OUT=$(scp -P ${FLAGS_ssh_port} -o StrictHostKeyChecking=no \ |
19 UserKnownHostsFile=$TMP_KNOWN_HOSTS $1 root@$FLAGS_remote:$2) | 19 -o UserKnownHostsFile=$TMP_KNOWN_HOSTS -i $TMP_PRIVATE_KEY $1 \ |
| 20 root@$FLAGS_remote:$2) |
20 return ${PIPESTATUS[0]} | 21 return ${PIPESTATUS[0]} |
21 } | 22 } |
22 | 23 |
23 # Copies a list of remote files specified in file $1 to local location | 24 # Copies a list of remote files specified in file $1 to local location |
24 # $2. Directory paths in $1 are collapsed into $2. | 25 # $2. Directory paths in $1 are collapsed into $2. |
25 function remote_rsync_from() { | 26 function remote_rsync_from() { |
26 rsync -e "ssh -p ${FLAGS_ssh_port} -o StrictHostKeyChecking=no -o \ | 27 rsync -e "ssh -p ${FLAGS_ssh_port} -o StrictHostKeyChecking=no \ |
27 UserKnownHostsFile=$TMP_KNOWN_HOSTS" --no-R \ | 28 -o UserKnownHostsFile=$TMP_KNOWN_HOSTS -i $TMP_PRIVATE_KEY" \ |
28 --files-from=$1 root@${FLAGS_remote}:/ $2 | 29 --no-R --files-from=$1 root@${FLAGS_remote}:/ $2 |
29 } | 30 } |
30 | 31 |
31 function remote_sh() { | 32 function remote_sh() { |
32 REMOTE_OUT=$(ssh -p ${FLAGS_ssh_port} -o StrictHostKeyChecking=no -o \ | 33 REMOTE_OUT=$(ssh -p ${FLAGS_ssh_port} -o StrictHostKeyChecking=no \ |
33 UserKnownHostsFile=$TMP_KNOWN_HOSTS root@$FLAGS_remote "$@") | 34 -o UserKnownHostsFile=$TMP_KNOWN_HOSTS -i $TMP_PRIVATE_KEY \ |
| 35 root@$FLAGS_remote "$@") |
34 return ${PIPESTATUS[0]} | 36 return ${PIPESTATUS[0]} |
35 } | 37 } |
36 | 38 |
37 function remote_sh_allow_changed_host_key() { | 39 function remote_sh_allow_changed_host_key() { |
38 rm -f $TMP_KNOWN_HOSTS | 40 rm -f $TMP_KNOWN_HOSTS |
39 remote_sh "$@" | 41 remote_sh "$@" |
40 } | 42 } |
41 | 43 |
42 function set_up_remote_access() { | 44 function set_up_remote_access() { |
43 if [ -z "$SSH_AGENT_PID" ]; then | |
44 eval $(ssh-agent) | |
45 OWN_SSH_AGENT=1 | |
46 else | |
47 OWN_SSH_AGENT=0 | |
48 fi | |
49 cp $FLAGS_private_key $TMP_PRIVATE_KEY | 45 cp $FLAGS_private_key $TMP_PRIVATE_KEY |
50 chmod 0400 $TMP_PRIVATE_KEY | 46 chmod 0400 $TMP_PRIVATE_KEY |
51 ssh-add $TMP_PRIVATE_KEY | |
52 | 47 |
53 # Verify the client is reachable before continuing | 48 # Verify the client is reachable before continuing |
54 echo "Initiating first contact with remote host" | 49 echo "Initiating first contact with remote host" |
55 remote_sh "true" | 50 remote_sh "true" |
56 echo "Connection OK" | 51 echo "Connection OK" |
57 } | 52 } |
58 | 53 |
59 # Ask the target what board it is | 54 # Ask the target what board it is |
60 function learn_board() { | 55 function learn_board() { |
61 [ -n "${FLAGS_board}" ] && return | 56 [ -n "${FLAGS_board}" ] && return |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 | 101 |
107 function remote_access_init() { | 102 function remote_access_init() { |
108 TMP_PRIVATE_KEY=$TMP/private_key | 103 TMP_PRIVATE_KEY=$TMP/private_key |
109 TMP_KNOWN_HOSTS=$TMP/known_hosts | 104 TMP_KNOWN_HOSTS=$TMP/known_hosts |
110 if [ -z "$FLAGS_remote" ]; then | 105 if [ -z "$FLAGS_remote" ]; then |
111 echo "Please specify --remote=<IP-or-hostname> of the Chromium OS instance" | 106 echo "Please specify --remote=<IP-or-hostname> of the Chromium OS instance" |
112 exit 1 | 107 exit 1 |
113 fi | 108 fi |
114 set_up_remote_access | 109 set_up_remote_access |
115 } | 110 } |
OLD | NEW |