Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/bin/dash | 1 #!/bin/dash |
| 2 # Copyright (c) 2009-2010 The Chromium OS Authors. All rights reserved. | 2 # Copyright (c) 2009-2010 The Chromium OS Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 TRY_BASH=1 | 6 TRY_BASH=1 |
| 7 if echo "$@" | grep -q -- "--dash"; then | 7 if echo "$@" | grep -q -- "--dash"; then |
| 8 TRY_BASH=0 | 8 TRY_BASH=0 |
| 9 fi | 9 fi |
| 10 | 10 |
| 11 # NOTE: This script *almost* works in dash. Unfortunately, dash is missing | 11 # NOTE: This script *almost* works in dash. Unfortunately, dash is missing |
| 12 # the 'history' builtin and readline support is missing from the 'read' | 12 # the 'history' builtin and readline support is missing from the 'read' |
| 13 # builtin. | 13 # builtin. |
| 14 # | 14 # |
| 15 # Please test that any changes continue to work in dash by running | 15 # Please test that any changes continue to work in dash by running |
| 16 # '/build/board-name/bin/dash crosh --dash' before checking them in. | 16 # '/build/board-name/bin/dash crosh --dash' before checking them in. |
| 17 | 17 |
| 18 if type "history" 2>/dev/null | grep -q "shell builtin"; then | 18 if type "history" 2>/dev/null | grep -q "shell builtin"; then |
| 19 IS_BASH=1 | 19 IS_BASH=1 |
| 20 else | 20 else |
| 21 IS_BASH=0 | 21 IS_BASH=0 |
| 22 fi | 22 fi |
| 23 | 23 |
| 24 # The terminal seems to come up with a bogus notion of its geometry. Calling | |
| 25 # reset works around the problem. | |
| 26 reset | |
|
Daniel Erat
2011/01/28 22:36:53
This shouldn't be needed now that we're using rxvt
rginda
2011/02/02 23:07:43
Cool, that reset took forever.
| |
| 27 | |
| 28 if [ "$TRY_BASH" = "1" -a "$IS_BASH" != "1" -a -x "/bin/bash" ]; then | 24 if [ "$TRY_BASH" = "1" -a "$IS_BASH" != "1" -a -x "/bin/bash" ]; then |
| 29 # Relaunch in bash if we can. | 25 # Relaunch in bash if we can. |
| 30 exec /bin/bash $0 "$@" | 26 exec /bin/bash $0 "$@" |
| 31 fi | 27 fi |
| 32 | 28 |
| 33 # | 29 # |
| 34 # Please keep the help text in alphabetical order! | 30 # Please keep the help text in alphabetical order! |
| 35 # | 31 # |
| 36 HELP=' | 32 HELP=' |
| 37 enterprise_ca_approve [--allow-self-signed] <url> | 33 enterprise_ca_approve [--allow-self-signed] <url> |
| 38 Approve an enterprise certificate authority. The <url> option should be | 34 Approve an enterprise certificate authority. The <url> option should be |
| 39 an http or https url to your enterprise Certificate Authority in PEM | 35 an http or https url to your enterprise Certificate Authority in PEM |
| 40 format. This CA will be used to validate the signature of an enterprise | 36 format. This CA will be used to validate the signature of an enterprise |
| 41 policy extension. | 37 policy extension. |
| 42 | 38 |
| 43 If the --allow-self-signed option is provided, then you may provide a self | 39 If the --allow-self-signed option is provided, then you may provide a self |
| 44 signed CA. Use this only if you are certain of the source of the CA. | 40 signed CA. Use this only if you are certain of the source of the CA. |
| 45 | 41 |
| 46 enterprise_ca_disapprove | 42 enterprise_ca_disapprove |
| 47 Remove a previously approved enterprise certificate authority. | 43 Remove a previously approved enterprise certificate authority. |
| 48 | 44 |
| 49 exit | 45 exit |
| 50 Exit crosh. | 46 Exit crosh. |
| 51 | 47 |
| 52 ff_debug [<tag_expr>] [--help] [--list_valid_tags] [--reset] | 48 ff_debug [<tag_expr>] [--help] [--list_valid_tags] [--reset] |
| 53 Add and remove flimflam debugging tags. | 49 Add and remove flimflam debugging tags. |
| 54 | 50 |
| 55 help | 51 help |
| 56 Display this help. | 52 Display this help. |
| 57 | 53 |
| 58 modem <command> [args...] | 54 modem <command> [args...] |
| 59 Interact with the 3G modem. Run "modem help" for detailed help. | 55 Interact with the 3G modem. Run "modem help" for detailed help. |
| 60 | 56 |
| 61 network_logging <wifi | cellular | ethernet> | 57 network_logging <wifi | cellular | ethernet> |
| 62 A function that enables a predefined set of tags useful for | 58 A function that enables a predefined set of tags useful for |
| 63 debugging the specified device. | 59 debugging the specified device. |
| 64 | 60 |
| 65 network_diag | 61 network_diag |
| 66 A function that performs a suite of network diagnostics. Saves a copy | 62 A function that performs a suite of network diagnostics. Saves a copy |
| 67 of the output to your download directory. | 63 of the output to your download directory. |
| 68 | 64 |
| 69 ping [-c count] [-i interval] [-n] [-s packet-size] [-W wait-time] <destination > | 65 ping [-c count] [-i interval] [-n] [-s packet-size] [-W wait-time] <destination > |
| 70 Send ICMP ECHO_REQUEST packets to a network host. If <destination> is "gw" | 66 Send ICMP ECHO_REQUEST packets to a network host. If <destination> is "gw" |
| 71 then the next hop gateway for the default route is used. | 67 then the next hop gateway for the default route is used. |
| 72 | 68 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 169 echo "Missing required parameter: user" | 165 echo "Missing required parameter: user" |
| 170 return | 166 return |
| 171 elif ! check_username "$user"; then | 167 elif ! check_username "$user"; then |
| 172 echo "Invalid user: $user" | 168 echo "Invalid user: $user" |
| 173 return | 169 return |
| 174 fi | 170 fi |
| 175 | 171 |
| 176 if [ -z "$host" ]; then | 172 if [ -z "$host" ]; then |
| 177 echo "Missing required parameter: host" | 173 echo "Missing required parameter: host" |
| 178 return | 174 return |
| 179 elif ! check_hostname "$host"; then | 175 elif ! check_hostname "$host" && ! check_ipv6 "$host"; then |
| 180 echo "Invalid host: $host" | 176 echo "Invalid host: $host" |
| 181 return | 177 return |
| 182 fi | 178 fi |
| 183 | 179 |
| 184 if [ ! -z "$port" ]; then | 180 if [ ! -z "$port" ]; then |
| 185 if ! check_digits "$port"; then | 181 if ! check_digits "$port"; then |
| 186 echo "Invalid port: $port" | 182 echo "Invalid port: $port" |
| 187 return | 183 return |
| 188 fi | 184 fi |
| 189 fi | 185 fi |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 278 } | 274 } |
| 279 | 275 |
| 280 cmd_network_logging(){ | 276 cmd_network_logging(){ |
| 281 if [ -n "$1" ]; then | 277 if [ -n "$1" ]; then |
| 282 case "$1" in | 278 case "$1" in |
| 283 "wifi") | 279 "wifi") |
| 284 echo; /usr/bin/ff_debug service+wifi+inet+device+manager | 280 echo; /usr/bin/ff_debug service+wifi+inet+device+manager |
| 285 echo; /usr/bin/wpa_debug msgdump | 281 echo; /usr/bin/wpa_debug msgdump |
| 286 ;; | 282 ;; |
| 287 "cellular") | 283 "cellular") |
| 288 echo; /usr/bin/ff_debug service+modem+device+manager | 284 echo; /usr/bin/ff_debug service+modem+device+manager |
| 289 echo; /usr/bin/wpa_debug info | 285 echo; /usr/bin/wpa_debug info |
| 290 ;; | 286 ;; |
| 291 "ethernet") | 287 "ethernet") |
| 292 echo; /usr/bin/ff_debug service+ethernet+device+manager | 288 echo; /usr/bin/ff_debug service+ethernet+device+manager |
| 293 echo; /usr/bin/wpa_debug info | 289 echo; /usr/bin/wpa_debug info |
| 294 ;; | 290 ;; |
| 295 "--help") | 291 "--help") |
| 296 echo "Usage: network_logging <wifi | cellular | ethernet>" | 292 echo "Usage: network_logging <wifi | cellular | ethernet>" |
| 297 ;; | 293 ;; |
| 298 *) | 294 *) |
| 299 echo "Invalid parameter $1" | 295 echo "Invalid parameter $1" |
| 300 ;; | 296 ;; |
| 301 esac | 297 esac |
| 302 else | 298 else |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 444 fi | 440 fi |
| 445 | 441 |
| 446 if ! type "cmd_$command" 2>/dev/null | head -1 | grep -q "function"; then | 442 if ! type "cmd_$command" 2>/dev/null | head -1 | grep -q "function"; then |
| 447 echo "Unknown command: '$command'" | 443 echo "Unknown command: '$command'" |
| 448 else | 444 else |
| 449 command="cmd_$command" | 445 command="cmd_$command" |
| 450 $command $params | 446 $command $params |
| 451 fi | 447 fi |
| 452 } | 448 } |
| 453 | 449 |
| 454 # Checks that a given string starts with an alphanumeric, and contains only | 450 # Checks that a given string looks like a hostname or IPv4 address (starts |
| 455 # alphanumeric, '.' or '-' characters | 451 # with an alphanumeric and contains only alphanumeric, '.', or '-' |
| 452 # characters). | |
| 456 check_hostname() { | 453 check_hostname() { |
| 457 expr "$1" : '^[[:alnum:]][[:alnum:].\-]*$' > /dev/null | 454 expr "$1" : '^[[:alnum:]][-[:alnum:].]*$' > /dev/null |
| 455 } | |
| 456 | |
| 457 # Checks that a given string could plausibly be an IPv6 address | |
| 458 # (hexadecimal, ':', and '.' characters only, followed by an optional zone | |
| 459 # index consisting of a '%' and a device name). | |
| 460 check_ipv6() { | |
| 461 echo "$1" | /bin/grep -E -q '^[0-9a-fA-F:.]+(%[a-z0-9]+)?$' | |
|
Daniel Erat
2011/01/28 22:36:53
I finally gave up on expr's poorly-documented regu
| |
| 458 } | 462 } |
| 459 | 463 |
| 460 # Checks that a given string starts with an alphanumeric, and contains only | 464 # Checks that a given string starts with an alphanumeric, and contains only |
| 461 # alphanumeric and zero or more of ":.~%$^\-" | 465 # alphanumeric and zero or more of ":.~%$^\-" |
| 462 check_username() { | 466 check_username() { |
| 463 expr "$1" : '^[[:alnum:]][[:alnum:]:.~%$^\-]*$' > /dev/null | 467 expr "$1" : '^[[:alnum:]][[:alnum:]:.~%$^\-]*$' > /dev/null |
| 464 } | 468 } |
| 465 | 469 |
| 466 check_digits() { | 470 check_digits() { |
| 467 expr "$1" : '^[[:digit:]]*$' > /dev/null | 471 expr "$1" : '^[[:digit:]]*$' > /dev/null |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 487 done | 491 done |
| 488 } | 492 } |
| 489 | 493 |
| 490 INPUTRC="$(dirname "$0")/inputrc.crosh" | 494 INPUTRC="$(dirname "$0")/inputrc.crosh" |
| 491 HISTFILE="$HOME/.crosh_history" | 495 HISTFILE="$HOME/.crosh_history" |
| 492 shell_history -r $HISTFILE | 496 shell_history -r $HISTFILE |
| 493 | 497 |
| 494 repl | 498 repl |
| 495 | 499 |
| 496 shell_history -w $HISTFILE | 500 shell_history -w $HISTFILE |
| OLD | NEW |