-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
labwc: enable audio controls, fix wifi status script
Enables the media keys for volume up, down, and mute toggling. Also now the wifi-signal-strength script is checked by shellcheck, all shellcheck issues are fixed, including bugs when netvm is rebooted and signal strength 0 not showing properly. Signed-off-by: Humaid Alqasimi <[email protected]>
- Loading branch information
1 parent
ae48500
commit a5a852c
Showing
5 changed files
with
147 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Copyright 2022-2024 TII (SSRC) and the Ghaf contributors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
# This is a temporary solution for volume control. | ||
# | ||
{ | ||
openssh, | ||
writeShellApplication, | ||
... | ||
}: | ||
writeShellApplication { | ||
name = "audio-ctrl"; | ||
runtimeInputs = [ | ||
openssh | ||
]; | ||
text = '' | ||
function pamixer { | ||
# Connect to audio-vm | ||
output=$(ssh -q ghaf@audio-vm \ | ||
-i /run/waypipe-ssh/id_ed25519 \ | ||
-o StrictHostKeyChecking=no \ | ||
-o UserKnownHostsFile=/dev/null \ | ||
"pamixer $1") | ||
} | ||
case "$1" in | ||
inc) | ||
pamixer "-i 5" | ||
;; | ||
dec) | ||
pamixer "-d 5" | ||
;; | ||
mut) | ||
pamixer "--get-mute" | ||
if [ "$output" = "false" ]; then | ||
pamixer "-m" | ||
else | ||
pamixer "-u" | ||
fi | ||
;; | ||
esac | ||
''; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,65 @@ | ||
# Copyright 2022-2024 TII (SSRC) and the Ghaf contributors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
{ | ||
stdenvNoCC, | ||
pkgs, | ||
networkmanager, | ||
openssh, | ||
util-linux, | ||
gawk, | ||
coreutils-full, | ||
writeShellApplication, | ||
wifiDevice, | ||
... | ||
}: let | ||
wifiSignalStrength = | ||
pkgs.writeShellScript | ||
"wifi-signal-strength" | ||
'' | ||
NETWORK_STATUS_FILE=/tmp/network-status | ||
}: | ||
writeShellApplication { | ||
name = "wifi-signal-strength"; | ||
runtimeInputs = [ | ||
networkmanager | ||
openssh | ||
gawk | ||
util-linux | ||
coreutils-full | ||
]; | ||
text = '' | ||
NETWORK_STATUS_FILE=/tmp/network-status | ||
export DBUS_SESSION_BUS_ADDRESS=unix:path=/tmp/ssh_session_dbus.sock | ||
export DBUS_SYSTEM_BUS_ADDRESS=unix:path=/tmp/ssh_system_dbus.sock | ||
export DBUS_SESSION_BUS_ADDRESS=unix:path=/tmp/ssh_session_dbus.sock | ||
export DBUS_SYSTEM_BUS_ADDRESS=unix:path=/tmp/ssh_system_dbus.sock | ||
# Lock the script to reuse | ||
LOCK_FILE=/tmp/wifi-signal.lock | ||
exec 99>"$LOCK_FILE" | ||
${pkgs.util-linux}/bin/flock -w 60 -x 99 || exit 1 | ||
# Lock the script to reuse | ||
LOCK_FILE=/tmp/wifi-signal.lock | ||
exec 99>"$LOCK_FILE" | ||
flock -w 60 -x 99 || exit 1 | ||
# Return the result as json format for waybar and use the control socket to close the ssh tunnel. | ||
trap "${pkgs.openssh}/bin/ssh -q -S /tmp/nmcli_socket -O exit ghaf@net-vm && ${pkgs.coreutils-full}/bin/cat $NETWORK_STATUS_FILE" EXIT | ||
# Return the result as json format for waybar and use the control socket to close the ssh tunnel. | ||
trap 'ssh -q -S /tmp/nmcli_socket -O exit ghaf@net-vm && cat "$NETWORK_STATUS_FILE"' EXIT | ||
# Connect to netvm | ||
${pkgs.openssh}/bin/ssh -M -S /tmp/nmcli_socket \ | ||
-f -N -q ghaf@net-vm \ | ||
-i /run/waypipe-ssh/id_ed25519 \ | ||
-o StrictHostKeyChecking=no \ | ||
-o StreamLocalBindUnlink=yes \ | ||
-o ExitOnForwardFailure=yes \ | ||
-L /tmp/ssh_session_dbus.sock:/run/user/1000/bus \ | ||
-L /tmp/ssh_system_dbus.sock:/run/dbus/system_bus_socket | ||
signal0= | ||
signal1= | ||
signal2= | ||
signal3= | ||
no_signal= | ||
# Get IP address of netvm | ||
address=$(${pkgs.networkmanager}/bin/nmcli device show ${wifiDevice} | ${pkgs.gawk}/bin/awk '{ if ($1=="IP4.ADDRESS[1]:") {print $2}}') | ||
# Get signal strength and ssid | ||
connection=($(${pkgs.networkmanager}/bin/nmcli -f IN-USE,SIGNAL,SSID dev wifi | ${pkgs.gawk}/bin/awk '/^\*/{if (NR!=1) {print $2; print $3}}')) | ||
connection[0]=$(if [ -z ''${connection[0]} ]; then echo "-1"; else echo ''${connection[0]}; fi) | ||
# Set the icon of signal level | ||
signal_level=$(if [ ''${connection[0]} -gt 80 ]; then echo $signal3; elif [ ''${connection[0]} -gt 60 ]; then echo $signal2; elif [ ''${connection[0]} -gt 30 ]; then echo $signal1; elif [ ''${connection[0]} -gt 0 ]; then echo signal0; else echo $no_signal; fi) | ||
tooltip=$(if [ -z $address ]; then echo ''${connection[0]}%; else echo $address ''${connection[0]}%; fi) | ||
text=$(if [ -z ''${connection[1]} ]; then echo "No connection"; else echo ''${connection[1]} $signal_level; fi) | ||
# Save the result in json format | ||
RESULT="{\"percentage\":\""''${connection[0]}"\", \"text\":\""$text"\", \"tooltip\":\""$tooltip"\", \"class\":\"1\"}" | ||
echo $RESULT>/tmp/network-status | ||
${pkgs.util-linux}/bin/flock -u 99 | ||
''; | ||
in | ||
stdenvNoCC.mkDerivation { | ||
name = "wifi-signal-strength"; | ||
|
||
phases = ["installPhase"]; | ||
|
||
installPhase = '' | ||
mkdir -p $out/bin | ||
cp ${wifiSignalStrength} $out/bin/wifi-signal-strength | ||
''; | ||
|
||
meta = { | ||
description = "Script to get wifi data from nmcli to show network of netvm using D-Bus over SSH on Waybar."; | ||
platforms = [ | ||
"x86_64-linux" | ||
]; | ||
}; | ||
} | ||
# Connect to netvm | ||
ssh -M -S /tmp/nmcli_socket \ | ||
-f -N -q ghaf@net-vm \ | ||
-i /run/waypipe-ssh/id_ed25519 \ | ||
-o StrictHostKeyChecking=no \ | ||
-o UserKnownHostsFile=/dev/null \ | ||
-o StreamLocalBindUnlink=yes \ | ||
-o ExitOnForwardFailure=yes \ | ||
-L /tmp/ssh_session_dbus.sock:/run/user/1000/bus \ | ||
-L /tmp/ssh_system_dbus.sock:/run/dbus/system_bus_socket | ||
signal0="\UF091F" | ||
signal1="\UF0922" | ||
signal2="\UF0925" | ||
signal3="\UF0928" | ||
no_signal="\UF092D" | ||
# Get IP address of netvm | ||
address=$(nmcli device show ${wifiDevice} | awk '{ if ($1=="IP4.ADDRESS[1]:") {print $2}}') | ||
# Get signal strength and ssi | ||
mapfile -t connection < <(nmcli -f IN-USE,SIGNAL,SSID dev wifi | awk '/^\*/{if (NR!=1) {print $2; print $3}}') | ||
connection[0]=$(if [ -z "''${connection[0]}" ]; then echo "-1"; else echo "''${connection[0]}"; fi) | ||
# Set the icon of signal level | ||
signal_level=$(if [ "''${connection[0]}" -gt 80 ]; then echo "''${signal3}"; elif [ "''${connection[0]}" -gt 60 ]; then echo "''${signal2}"; elif [ "''${connection[0]}" -gt 30 ]; then echo "''${signal1}"; elif [ "''${connection[0]}" -gt 0 ]; then echo "''${signal0};" else echo "''${no_signal}"; fi) | ||
tooltip=$(if [ -z "''${address}" ]; then echo "''${connection[0]}%"; else echo "''${address} ''${connection[0]}%"; fi) | ||
text=$(if [ -z "''${connection[1]}" ]; then echo "No connection"; else echo "''${connection[1]} $signal_level"; fi) | ||
# Save the result in json format | ||
RESULT="{\"percentage\":\"''${connection[0]}\", \"text\":\"''${text}\", \"tooltip\":\"''${tooltip}\", \"class\":\"1\"}" | ||
echo -e "$RESULT">/tmp/network-status | ||
flock -u 99 | ||
''; | ||
} |