commit 58210e9b8aa4cdaa6e477f7880073c1f92ac36d0
parent 14fe84040c2f77ba6205b4a3e1cc264af6fdb947
Author: Vincent Demeester <vincent@sbr.pm>
Date: Wed, 27 Apr 2022 18:17:48 +0200
nix/packages/scripts: support no graphics for redhat-vpn
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
Diffstat:
1 file changed, 23 insertions(+), 6 deletions(-)
diff --git a/nix/packages/my/scripts/bin/redhat-vpn b/nix/packages/my/scripts/bin/redhat-vpn
@@ -3,7 +3,22 @@
# This will ask for which VPN to connect (using available tools) and
# do some magic
set -e
-connection=$(nmcli connection show | grep vpn | zenity --list --title "Red Hat VPNs" --text "Choose your VPN.." --column "Name" --width=600 --height=450)
+
+GRAPHICS=1
+if ! timeout 1s xset q &>/dev/null; then
+ GRAPHICS=0
+fi
+
+CHOOSE_CMD="zenity --list --title \"Red Hat VPNs\" --text \"Choose your VPN..\" --column \"Name\" --width=600 --height=450"
+if [[ GRAPHICS -eq 0 ]]; then
+ CHOOSE_CMD="fzf"
+fi
+NOTIFY_CMD="notify-send"
+if [[ GRAPHICS -eq 0 ]]; then
+ NOTIFY_CMD="echo"
+fi
+
+connection=$(nmcli connection show | grep vpn | $CHOOSE_CMD)
uuid=$(echo ${connection} | awk '{print $3}')
name=$(echo ${connection} | awk '{print $1 $2}')
VPNSTATUS=$(nmcli connection show --active $uuid | wc -l)
@@ -18,11 +33,13 @@ then
nmcli connection up ${uuid} passwd-file $passfile
rm $passfile
- notify-send "VPN ${name} is connected." "You are now connected to the Red Hat VPN, let's work !"
+ $NOTIFY_CMD "VPN ${name} is connected." "You are now connected to the Red Hat VPN, let's work !"
else
- notify-send "VPN ${name} is already connected." "You are already connected to the Red Hat VPN, let's work !"
+ $NOTIFY_CMD "VPN ${name} is already connected." "You are already connected to the Red Hat VPN, let's work !"
fi
# Ask for kerberos password if klist returns an error (no creds)
-klist || {
- zenity --password --title="Kerberos password" | kinit vdemeest@REDHAT.COM
-}
+if [[ GRAPHICS -eq 0 ]]; then
+ klist || {
+ zenity --password --title="Kerberos password" | kinit vdemeest@REDHAT.COM
+ }
+fi