blob: 55151b50b1bc8a698c684544506d6166807a47de [file] [log] [blame]
#!/bin/sh
# Copyright 2018 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 the Wake on LAN behavior.
FLAGS_HELP="Usage:
$(basename "$0")
$(basename "$0") [true | false]
Enable or disable Wake on LAN for Ethernet devices. This command takes
effect after re-connecting to Ethernet and is not persistent across system
restarts."
. /usr/share/misc/shflags
FLIMFLAM=org.chromium.flimflam
IMANAGER="${FLIMFLAM}.Manager"
PROPERTY_NAME=WakeOnLanEnabled
PROPERTY_DESC="Wake on LAN"
usage() {
echo "Invalid invocation: $*"
echo
flags_help
exit 1
}
dbus () {
local obj="$1"
local meth="$2"
shift 2
dbus-send --system --print-reply --fixed --dest="${FLIMFLAM}" "${obj}" "${meth}" "$@"
}
get_manager_property () {
dbus / "${IMANAGER}.GetProperties" | sed -n "/$1/s/.* //p"
}
display_value () {
local value
value="$(get_manager_property "${PROPERTY_NAME}")"
if [ -n "${value}" ] ; then
echo "Current ${PROPERTY_DESC} setting: ${value}"
exit 0
fi
echo "This connection manager instance does not support ${PROPERTY_DESC}"
exit 0
}
FLAGS "$@" || exit 1
eval set -- "${FLAGS_ARGV}"
if [ $# -lt 1 ]; then
display_value
fi
set_value="$1"
if [ "${set_value}" != "false" ] && [ "${set_value}" != "true" ] ; then
usage "Argument must be 'true' or 'false'"
fi
dbus / "${IMANAGER}.SetProperty" string:"${PROPERTY_NAME}" "variant:boolean:${set_value}"