New backup 2025-03-12 19:45:01

This commit is contained in:
Penelope Gwen 2025-03-12 19:45:01 -07:00
parent ba1a133294
commit cde6130c8d

View file

@ -1,33 +1,48 @@
#!/bin/bash
function ifstatus(){
is_wireless=false
is_ethernet=false
is_proton=false
is_homevpn=false
function btstatus(){
device_mac_list=$(bluetoothctl devices Paired | awk '{print $2}')
device_json_array=()
if nmcli -g TYPE connection show --active | grep -q "wireless";then
is_wireless='true'
fi
if nmcli -g TYPE connection show --active | grep -q "ethernet";then
is_ethernet='true'
fi
if nmcli -g TYPE,NAME connection show --active | grep -e "vpn" -e "wireguard" | grep -qi "proton";then
is_proton='true'
fi
if nmcli -g TYPE,NAME connection show --active | grep -e "vpn" -e "wireguard" | grep -qi "home";then
is_homevpn='true'
fi
echo $(jq -n --arg wifi "${is_wireless}" --arg wired "${is_ethernet}" --arg proton "${is_proton}" --arg homevpn "${is_homevpn}" '{wifi: $wifi, wired: $wired, proton: $proton, homevpn: $homevpn}')
for m in ${device_mac_list};do
device_name="$(bluetoothctl info ${m} | grep 'Name: ' | sed 's/.*Name: //')"
device_connected="$(bluetoothctl info ${m} | grep 'Connected: ' | sed 's/.*Connected: //')"
device_icon="$(bluetoothctl info ${m} | grep 'Icon: ' | sed 's/.*Icon: //')"
case "${device_icon}" in
"input-mouse")
device_icon="🖯"
;;
"phone")
device_icon=""
;;
"input-keyboard")
device_icon=""
;;
"input-gaming")
device_icon=""
;;
"audio-headphones")
device_icon=""
;;
"audio-headset")
device_icon=""
;;
"computer")
device_icon=""
;;
esac
device_json=$( jq -n --arg name "${device_name}" --arg connected "${device_connected}" --arg icon "${device_icon}" --arg address "${m}" '{name: $name, connected: $connected, icon: $icon, address: $address}')
device_json_array+=("${device_json}")
done
devices_json=$(printf '%s\n' "${device_json_array[@]}" | jq -s .)
echo ${devices_json}
}
ifstatus
btstatus
ip monitor address | {
bluetoothctl | awk '/Device.*Connected/' | {
while read -r event; do
# echo hi ${event};
ifstatus
btstatus
done;
}