blob: c15e05598922812de93f4a350b147f3950b5f1c3 [file] [log] [blame]
# Copyright 2019 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.
description "Connect to WiFi if WiFi credentials exist"
author "chromium-os-dev@chromium.org"
# Read WiFi credentials at /usr/local/etc/wifi_cred and connect to WiFi network
# accordingly.
#
# The power team wants to run autotests on test devices from moblab via WiFi.
# This upstart script is an effort to enable WiFi connection between moblab and
# test Chrome devices, in addition to Ethernet connection which is already
# supported. If WiFi credentials at /usr/local/etc/wifi_cred exist, this upstart
# script connects to that WiFi after the device gets provisioned by the moblab.
# The WiFi credentials are associated with the moblab and should come from the
# moblab. /usr/local/etc/wifi_cred is in the stateful partition. During the
# provision process, moblab can write to stateful.tgz, which then replaces the
# stateful partition on a test Chrome device.
#
# TODO(mqg): consider a more robust key/value format.
# Format for /usr/local/etc/wifi_cred:
# If WiFi network has no password -
#
# ssid
#
# If WiFi network has password -
#
# ssid
# password
start on started shill
task
env WIFI_CRED=/usr/local/etc/wifi_cred
script
if [ -f "${WIFI_CRED}" ]; then
logger -t "${UPSTART_JOB}" "${WIFI_CRED} found."
lines=$(wc -l < "${WIFI_CRED}")
# Read the first line of $WIFI_CRED as WiFi ssid.
set -- "$(sed -n 1p "${WIFI_CRED}")"
logger -t "${UPSTART_JOB}" "WiFi ssid: $*"
# Read the second line of $WIFI_CRED as WiFi password if it exists.
if [ "${lines}" -gt 1 ]; then
set -- "$@" "$(sed -n 2p "${WIFI_CRED}")"
fi
# TODO(mqg): if WiFi device does not come up within wifi script retries,
# wifi script will fail. This is very unlikely, but if this becomes an issue
# after further testing, consider using dbus messages to add WiFi
# credentials to shill profile instead of using wifi script.
/usr/local/autotest/cros/scripts/wifi connect "$@" 2>&1 \
| logger -t "${UPSTART_JOB}"
fi
end script