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

# --- Constants
readonly LIBDIR="/usr/share/tlp-pm"
readonly LIBS="tlp-functions tlp-rf-func"

# --- Source libraries
for lib in $LIBS; do
    if [ ! -f $LIBDIR/$lib ]; then
        echo "Error: missing function library \'$LIBDIR/$lib\'." 1>&2
        exit 1
    fi
    . $LIBDIR/$lib
done

# --- MAIN
read_defaults
add_sbin2path
self=${0##*/}

case $self in
    bluetooth|wifi|wwan)
        case $1 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
