From 14abc878285d961a90f9e56b85c15a091531f6e5 Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Sat, 26 Sep 2026 09:03:26 +0200 Subject: Add bluetooth and vms example tools Read-only: bluetoothctl show/devices/info and virsh list, domstate, dominfo and domifaddr. Connecting devices and handling VMs are phase 2. The DHCP lease source is empty for bridged guests, so the VM's IP comes from ARP or the guest agent. Co-Authored-By: Claude Opus 5.5 --- examples/tools/bluetooth.sh | 46 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100755 examples/tools/bluetooth.sh (limited to 'examples/tools/bluetooth.sh') diff --git a/examples/tools/bluetooth.sh b/examples/tools/bluetooth.sh new file mode 100755 index 0000000..a3af0f9 --- /dev/null +++ b/examples/tools/bluetooth.sh @@ -0,0 +1,46 @@ +#!/bin/bash +# desktop-assistant tool: bluetooth status (read-only). +# Copyright (C) 2026 Danilo M. +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License version 2 as published +# by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +# Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# +# bluetooth.sh: whether bluetooth is on, the connected devices with their +# kind (BlueZ icon name) and battery when the device reports one, and the +# paired devices that are not connected. Only show, devices and info run +# here: nothing connects, pairs or scans. + +set -uo pipefail + +power=$(bluetoothctl show | sed -n 's/^\tPowered: //p') +[ -n "$power" ] || { echo "no bluetooth controller" >&2; exit 1; } +[ "$power" = yes ] || { echo "bluetooth is off"; exit 0; } +echo "bluetooth on" + +connected=0 +others=() +while read -r _ mac _; do + info=$(bluetoothctl info "$mac") + alias=$(sed -n 's/^\tAlias: //p' <<<"$info") + if grep -q $'^\tConnected: yes' <<<"$info"; then + kind=$(sed -n 's/^\tIcon: //p' <<<"$info") + battery=$(sed -n 's/^\tBattery Percentage: .*(\([0-9]*\))$/\1/p' <<<"$info") + echo "connected: $alias (${kind:-unknown kind}${battery:+, battery $battery%})" + connected=$((connected + 1)) + else + others+=("$alias") + fi +done < <(bluetoothctl devices Paired) + +[ "$connected" -gt 0 ] || echo "no device connected" +[ "${#others[@]}" -eq 0 ] || { printf 'paired, not connected: '; (IFS=,; echo "${others[*]}" | sed 's/,/, /g'); } -- cgit v1.2.3