#!/bin/sh
# tlp-rdw - enable/disable RDW
#
# Copyright (c) 2024 Thomas Koch <linrunner at gmx.net> and others.
# SPDX-License-Identifier: GPL-2.0-or-later

# --- 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" || exit 70
done

# --- MAIN
# shellcheck disable=SC2034
_bgtask=1

carg1="$1"
if [ "$carg1" = "--version" ]; then
    print_version
    exit 0
fi

# read configuration: quit on error, trace allowed
read_config 1 0
parse_args4config "$@"
cprintf_init

case $carg1 in
    "")
        if check_run_flag "$RDW_KILL"; then
            echo "tlp-rdw: disabled."
        else
            echo "tlp-rdw: enabled."
        fi
        ;;

    enable)
        check_root
        reset_run_flag "$RDW_KILL"
        echo "tlp-rdw: enabled."
        ;;

    disable)
        check_root
        set_run_flag "$RDW_KILL"
        echo "tlp-rdw: disabled."
        ;;

    *)
        echo "Usage: tlp-rdw [ enable | disable ]"
        do_exit 3

esac

do_exit 0
