Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(177)

Side by Side Diff: remote_access.sh

Issue 3276002: Script to generate post mortem of all crashes on device (Closed) Base URL: http://git.chromium.org/git/crosutils.git
Patch Set: Respond to reviews Created 10 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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() { 17 function remote_cp_to() {
18 REMOTE_OUT=$(scp -o StrictHostKeyChecking=no -o \ 18 REMOTE_OUT=$(scp -o StrictHostKeyChecking=no -o \
19 UserKnownHostsFile=$TMP_KNOWN_HOSTS $1 root@$FLAGS_remote:$2) 19 UserKnownHostsFile=$TMP_KNOWN_HOSTS $1 root@$FLAGS_remote:$2)
20 return ${PIPESTATUS[0]} 20 return ${PIPESTATUS[0]}
21 } 21 }
22 22
23 # Copies a list of remote files specified in file $1 to local location
24 # $2. Directory paths in $1 are collapsed into $2.
25 function remote_rsync_from() {
26 rsync -e "ssh -o StrictHostKeyChecking=no -o \
27 UserKnownHostsFile=$TMP_KNOWN_HOSTS" --no-R \
28 --files-from=$1 root@${FLAGS_remote}:/ $2
29 }
30
23 function remote_sh() { 31 function remote_sh() {
24 REMOTE_OUT=$(ssh -p ${FLAGS_ssh_port} -o StrictHostKeyChecking=no -o \ 32 REMOTE_OUT=$(ssh -p ${FLAGS_ssh_port} -o StrictHostKeyChecking=no -o \
25 UserKnownHostsFile=$TMP_KNOWN_HOSTS root@$FLAGS_remote "$@") 33 UserKnownHostsFile=$TMP_KNOWN_HOSTS root@$FLAGS_remote "$@")
26 return ${PIPESTATUS[0]} 34 return ${PIPESTATUS[0]}
27 } 35 }
28 36
29 function remote_sh_allow_changed_host_key() { 37 function remote_sh_allow_changed_host_key() {
30 rm -f $TMP_KNOWN_HOSTS 38 rm -f $TMP_KNOWN_HOSTS
31 remote_sh "$@" 39 remote_sh "$@"
32 } 40 }
33 41
34 function set_up_remote_access() { 42 function set_up_remote_access() {
35 if [ -z "$SSH_AGENT_PID" ]; then 43 if [ -z "$SSH_AGENT_PID" ]; then
36 eval $(ssh-agent) 44 eval $(ssh-agent)
37 OWN_SSH_AGENT=1 45 OWN_SSH_AGENT=1
38 else 46 else
39 OWN_SSH_AGENT=0 47 OWN_SSH_AGENT=0
40 fi 48 fi
41 cp $FLAGS_private_key $TMP_PRIVATE_KEY 49 cp $FLAGS_private_key $TMP_PRIVATE_KEY
42 chmod 0400 $TMP_PRIVATE_KEY 50 chmod 0400 $TMP_PRIVATE_KEY
43 ssh-add $TMP_PRIVATE_KEY 51 ssh-add $TMP_PRIVATE_KEY
44 52
45 # Verify the client is reachable before continuing 53 # Verify the client is reachable before continuing
46 echo "Initiating first contact with remote host" 54 echo "Initiating first contact with remote host"
47 remote_sh "true" 55 remote_sh "true"
48 echo "Connection OK" 56 echo "Connection OK"
49 } 57 }
50 58
59 # Ask the target what board it is
60 function learn_board() {
61 [ -n "${FLAGS_board}" ] && return
62 remote_sh grep CHROMEOS_RELEASE_BOARD /etc/lsb-release
63 FLAGS_board=$(echo "${REMOTE_OUT}" | cut -d '=' -f 2)
64 if [ -z "${FLAGS_board}" ]; then
65 error "Board required"
66 exit 1
67 fi
68 info "Target reports board is ${FLAGS_board}"
69 }
70
51 function cleanup_remote_access() { 71 function cleanup_remote_access() {
52 # Call this function from the exit trap of the main script. 72 # Call this function from the exit trap of the main script.
53 # Iff we started ssh-agent, be nice and clean it up. 73 # Iff we started ssh-agent, be nice and clean it up.
54 # Note, only works if called from the main script - no subshells. 74 # Note, only works if called from the main script - no subshells.
55 if [[ 1 -eq ${OWN_SSH_AGENT} ]] 75 if [[ 1 -eq ${OWN_SSH_AGENT} ]]
56 then 76 then
57 kill ${SSH_AGENT_PID} 2>/dev/null 77 kill ${SSH_AGENT_PID} 2>/dev/null
58 unset SSH_AGENT_PID SSH_AUTH_SOCK 78 unset SSH_AGENT_PID SSH_AUTH_SOCK
59 fi 79 fi
60 } 80 }
61 81
62 function remote_access_init() { 82 function remote_access_init() {
63 TMP_PRIVATE_KEY=$TMP/private_key 83 TMP_PRIVATE_KEY=$TMP/private_key
64 TMP_KNOWN_HOSTS=$TMP/known_hosts 84 TMP_KNOWN_HOSTS=$TMP/known_hosts
65 if [ -z "$FLAGS_remote" ]; then 85 if [ -z "$FLAGS_remote" ]; then
66 echo "Please specify --remote=<IP-or-hostname> of the Chromium OS instance" 86 echo "Please specify --remote=<IP-or-hostname> of the Chromium OS instance"
67 exit 1 87 exit 1
68 fi 88 fi
69 set_up_remote_access 89 set_up_remote_access
70 } 90 }
OLDNEW
« cros_show_stacks ('K') | « image_to_live.sh ('k') | run_remote_tests.sh » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698