Files
sxmo-utils/scripts/core/sxmo_bluetoothtoggle.sh
Willow Barraco ce59e6b014 bluetoothtoogle: behave correctly when partially blocked
If the devices are partially blocked, the config menu should display a
ton icon, and toggeling should block all remainings.
2024-05-09 18:03:28 +02:00

52 lines
817 B
Bash
Executable File

#!/bin/sh
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2022 Sxmo Contributors
# Must be run as root
# shellcheck source=scripts/core/sxmo_common.sh
. sxmo_common.sh
on() {
rfkill unblock bluetooth
case "$SXMO_OS" in
alpine|postmarketos)
rc-service bluetooth start
rc-update add bluetooth
;;
arch|archarm|nixos|debian)
systemctl start bluetooth
systemctl enable bluetooth
;;
esac
}
off() {
case "$SXMO_OS" in
alpine|postmarketos)
rc-service bluetooth stop
rc-update del bluetooth
;;
arch|archarm|nixos|debian)
systemctl stop bluetooth
systemctl disable bluetooth
;;
esac
rfkill block bluetooth
}
case "$1" in
on)
on
;;
off)
off
;;
*) #toggle
if rfkill list bluetooth -no ID,SOFT,HARD | grep -vq " blocked"; then
off
else
on
fi
esac