From 4ce50aef69874832273052b6f7c696d7f1aedab6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferit=20Yi=C4=9Fit=20BALABAN?= Date: Sat, 9 Mar 2024 21:21:01 +0300 Subject: [PATCH] Add wireless control script MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ferit Yiğit BALABAN --- wireless.sh | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100755 wireless.sh diff --git a/wireless.sh b/wireless.sh new file mode 100755 index 0000000..7ed378e --- /dev/null +++ b/wireless.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env bash +# +# Yigid BALABAN, +# + +control() { + local device="$1" + local subcommand="$2" + + case "$subcommand" in + off) + rfkill block "$device" && + + case $device in + bluetooth) bluetoothctl power off ;; + wifi) nmcli radio wifi off ;; + esac + ;; + on) + + rfkill unblock "$device" && sleep 1 && + + case $device in + bluetooth) bluetoothctl power on ;; + wifi) nmcli radio wifi on ;; + esac + ;; + *) + # shellcheck disable=SC2154 + echo "$command: subcommand '$subcommand' is not a valid argument." >&2 + return 1 + esac +} + +if [[ $# -ne 2 ]]; then + echo "Usage: $0 " >&2 + echo "Valid devices: bluetooth, wifi" >&2 + echo "Valid subcommands: on, off" >&2 + exit 1 +fi + +control "$1" "$2"