#!/bin/sh
# tlp - switch bluetooth/wifi/wwan on/off
#
# Copyright (c) 2019 Thomas Koch <linrunner at gmx.net> and others.
# This software is licensed under the GPL v2 or later.

# shellcheck disable=SC2086,SC2154

# --- Source libraries

for lib in /usr/share/tlp/tlp-func-base /usr/share/tlp/func.d/25-tlp-func-rf /usr/share/tlp/func.d/30-tlp-func-rf-sw; do
    # shellcheck disable=SC1090
    . $lib
done

# --- MAIN

read_defaults
carg1=$1
parse_args4config "$@"
add_sbin2path
self=${0##*/}

case $self in
    bluetooth|wifi|wwan)
        case $carg1 in
            on)
                device_switch $self on
                echo_device_state $self $_devs
                ;;

            off)
                device_switch $self off
                echo_device_state $self $_devs
                ;;

            toggle)
                device_switch $self toggle
                echo_device_state $self $_devs
                ;;

            *)
                device_state $self
                echo_device_state $self $_devs
                ;;
        esac
        ;;

    *)
        echo "Error: unknown device type \"$self\"." 1>&2
        exit 1
        ;;
esac

exit 0
