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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
115 remote_sh "touch /tmp/awaiting_reboot; reboot" | 110 remote_sh "touch /tmp/awaiting_reboot; reboot" |
116 while true; do | 111 while true; do |
117 check_if_rebooted & | 112 check_if_rebooted & |
118 local pid=$! | 113 local pid=$! |
119 wait_with_timeout ${pid} 30 && break | 114 wait_with_timeout ${pid} 30 && break |
120 ! kill -9 ${pid} 2> /dev/null | 115 ! kill -9 ${pid} 2> /dev/null |
121 done | 116 done |
122 } | 117 } |
123 | 118 |
124 function cleanup_remote_access() { | 119 function cleanup_remote_access() { |
125 # Call this function from the exit trap of the main script. | 120 : |
sosa
2011/01/14 17:12:30
???
| |
126 # Iff we started ssh-agent, be nice and clean it up. | |
127 # Note, only works if called from the main script - no subshells. | |
128 if [[ 1 -eq ${OWN_SSH_AGENT} ]] | |
129 then | |
130 kill ${SSH_AGENT_PID} 2>/dev/null | |
131 unset SSH_AGENT_PID SSH_AUTH_SOCK | |
132 fi | |
133 } | 121 } |
134 | 122 |
135 function remote_access_init() { | 123 function remote_access_init() { |
136 TMP_PRIVATE_KEY=$TMP/private_key | 124 TMP_PRIVATE_KEY=$TMP/private_key |
137 TMP_KNOWN_HOSTS=$TMP/known_hosts | 125 TMP_KNOWN_HOSTS=$TMP/known_hosts |
138 if [ -z "$FLAGS_remote" ]; then | 126 if [ -z "$FLAGS_remote" ]; then |
139 echo "Please specify --remote=<IP-or-hostname> of the Chromium OS instance" | 127 echo "Please specify --remote=<IP-or-hostname> of the Chromium OS instance" |
140 exit 1 | 128 exit 1 |
141 fi | 129 fi |
142 set_up_remote_access | 130 set_up_remote_access |
143 } | 131 } |
OLD | NEW |