• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2#
3# Copyright (C) 2014 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9#      http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#
17#
18# Set the Wake on LAN behavior.
19
20FLAGS_HELP="Usage:
21
22  $(basename $0)
23
24or
25
26  $(basename $0) [true | false] "
27
28FLIMFLAM=org.chromium.flimflam
29IMANAGER="${FLIMFLAM}.Manager"
30PROPERTY_NAME=WakeOnLanEnabled
31PROPERTY_DESC="Wake on LAN"
32
33usage() {
34  echo "Invalid invocation: $*"
35  echo
36  echo $FLAGS_HELP
37  exit 1
38}
39
40dbus () {
41  local obj="$1"
42  local meth="$2"
43  shift 2
44
45  dbus-send --system --print-reply --fixed --dest="${FLIMFLAM}" "${obj}" "${meth}" "$@"
46}
47
48get_manager_property () {
49  dbus / "${IMANAGER}.GetProperties" | sed -n "/$1/s/.* //p"
50}
51
52display_value () {
53  local value=$(get_manager_property "${PROPERTY_NAME}")
54
55  if [ -n "${value}" ] ; then
56    echo "Current ${PROPERTY_DESC} setting: " $value
57    exit 0
58  fi
59
60  echo "This connection manager instance does not support ${PROPERTY_DESC}"
61  exit 0
62}
63
64if [ $# -lt 1 ]; then
65    display_value
66fi
67
68set_value="$1"
69
70if [ "${set_value}" != "false" -a "${set_value}" != "true" ] ; then
71    usage "Argument must be 'true' or 'false'"
72fi
73
74dbus / "${IMANAGER}.SetProperty" string:"${PROPERTY_NAME}" "variant:boolean:${set_value}"
75