#!/bin/sh choices=$(mktemp --suffix=network_ops) # This assumes only 1 BT controller on the system ctrl_pow=$(bluetoothctl show|awk '/^\s+Powered:\s/ {print $2}') [ "$ctrl_pow" = "yes" ] && { bdevs=$(bluetoothctl devices|awk '{print $2}') for dev in $bdevs; do dev_name=$(bluetoothctl info $dev|awk -F ':' '/^\s+Name:/ {print $2}') dev_connected=$(bluetoothctl info $dev|awk '/^\s+Connected:/ {print $2}') #printf "dev_name = %s\n" "$dev_name" #printf "dev_connected = %s\n" "$dev_connected" [ "$dev_connected" = "yes" ] && { printf "disconnect %s %s\n" "$dev" "$dev_name" >> $choices } || { printf "connect %s %s\n" "$dev" "$dev_name" >> $choices } done printf "\npower off BT ctrl\n" >> $choices } || { # BT controller is powered off, this is the only sensible BT option printf "\npower on BT ctrl\n" >> $choices } apstat=$(systemctl show hostapd.service|awk -F '=' '/^ActiveS/ {print $2}') printf "apstat = %s\n" $apstat case $apstat in inactive|failed) printf "\nStart WiFi AP\n" >> $choices ;; active) printf "\nStop WiFi AP\n" >> $choices ;; esac isp_iface_state=$(ip -j addr show 'isp' |jq -cr '.[]|.operstate') case "$isp_iface_state" in "DOWN") printf "\nInternet ON\n" >> $choices ;; "UP") printf "\nInternet OFF\n" >> $choices ;; esac [ -e $HOME/vpn_commands.sh ] && { $HOME/vpn_commands.sh >> $choices } if $(systemctl --quiet is-active transmission.service) then printf "doas /usr/bin/systemctl stop transmission.service\n" >> $choices else printf "doas /usr/bin/systemctl start transmission.service\n" >> $choices fi if $(systemctl --quiet is-active tor.service) then printf "doas /usr/bin/systemctl stop tor.service\n" >> $choices else printf "doas /usr/bin/systemctl start tor.service\n" >> $choices fi choice=$(grep -Ev '^\s*$' $choices|$PICKER -p 'Network ops:') [ -z "$choice" ] && notify-send "no choice" && rm $choices && exit 1 printf "choice = %s\n" "$choice" case "$choice" in "Internet OFF") doas /usr/bin/ip l set isp down msg=$? ;; "Internet ON") doas /usr/bin/ip l set isp up msg=$? ;; "Start WiFi AP") doas /usr/bin/ip l set wlan0 down doas /usr/bin/systemctl start hostapd.service sleep 1 msg="$(systemctl status hostapd.service)" ;; "Stop WiFi AP") doas /usr/bin/systemctl stop hostapd.service doas /usr/bin/ip l set wlan0 down sleep 1 msg="$(systemctl status hostapd.service)" ;; "power on BT ctrl") msg="$(bluetoothctl power on)" ;; "power off BT ctrl") msg="$(bluetoothctl power off)" ;; connect*|disconnect*) bcmd="${choice%% *}" bdev="${choice#* }" bdev="${bdev%% *}" printf "bcmd = %s\n" $bcmd printf "bdev = %s\n" $bdev msg="$(bluetoothctl $bcmd $bdev)" ;; *) $choice msg=$? ;; esac notify-send "$msg" rm $choices