| #!/bin/sh |
| # |
| # Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| set -e |
| |
| # Only run this script on test machines that run in the lab. |
| # See autotest/server/hosts/site_host.py for more information. |
| if [ ! -f /mnt/stateful_partition/.labmachine ]; then |
| exit 0 |
| fi |
| |
| NON_ETHERNET_DRIVERS="cdc_ether" |
| |
| # Returns 0 if $1 is a non-Ethernet driver, or 1 otherwise. |
| is_non_ethernet_driver() { |
| local driver="$1" |
| local non_ethernet_driver |
| |
| for non_ethernet_driver in ${NON_ETHERNET_DRIVERS}; do |
| if [ "${driver}" = "${non_ethernet_driver}" ]; then |
| return 0 |
| fi |
| done |
| return 1 |
| } |
| |
| # Shows the list of Ethernet interfaces found on the system. |
| find_ethernet_interfaces() { |
| local device_path |
| local driver_path |
| local driver |
| |
| for device_path in /sys/class/net/eth*; do |
| driver_path="${device_path}/device/driver" |
| if [ -e "${driver_path}" ]; then |
| driver=$(basename $(readlink -f "${driver_path}")) |
| if ! is_non_ethernet_driver "${driver}"; then |
| basename "${device_path}" |
| fi |
| fi |
| done |
| } |
| |
| for eth in $(find_ethernet_interfaces); do |
| # Ping itself doesn't work on test images in a VM. |
| PING="curl --interface ${eth} -o /dev/null www.google.com" |
| |
| if ${PING}; then |
| exit 0 |
| fi |
| |
| ifconfig ${eth} down |
| ifconfig ${eth} up |
| sleep 5 |
| |
| if ${PING}; then |
| echo "Reconfigured using ifconfig down/up." |
| exit 1 |
| fi |
| |
| initctl stop flimflam || echo "Flimflam was not running." |
| initctl start flimflam |
| |
| sleep 5 |
| |
| if ${PING}; then |
| exit 1 |
| fi |
| done |
| |
| # Last chance - reboot if we can't get any connectivity. |
| echo "All efforts to recover ethernet have been exhausted. Rebooting." |
| (sleep 5 && reboot) & |
| exit 1 |