blob: 5b9c5cacae2fb5bbe0b867d5d38a03863570b7e4 [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 and connects 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 exist at:
# - /usr/local/etc/wifi_creds/wifi_cred
# 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. The 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 wifi_cred file:
# 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_creds/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.
ssid="$(sed -n 1p "${WIFI_CRED}")"
logger -t "${UPSTART_JOB}" "WiFi ssid: ${ssid}"
# Read the second line of $WIFI_CRED as WiFi password if it exists.
if [ "${lines}" -gt 1 ]; then
set -- "${ssid}" "$(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 configure "$@" 2>&1 \
| logger -t "${UPSTART_JOB}"
/usr/local/autotest/cros/scripts/wifi connect_with_props \
"${ssid}" "60" "SecurityClass=psk" 2>&1 | logger -t "${UPSTART_JOB}"
fi
end script