Commit 58210e9b8aa4
Changed files (1)
nix
packages
my
scripts
bin
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