redhat-vpn (1639B)
1 #!/usr/bin/env bash 2 # Connect to RedHat VPN 3 # This will ask for which VPN to connect (using available tools) and 4 # do some magic 5 set -e 6 7 GRAPHICS=1 8 if ! [ "${XDG_CURRENT_DESKTOP}" == "sway" ]; then 9 if ! command -v xset &> /dev/null; then 10 GRAPHICS=0 11 elif ! timeout 1s xset q &>/dev/null; then 12 GRAPHICS=0 13 fi 14 fi 15 16 if [[ GRAPHICS -eq 0 ]]; then 17 connection="$(nmcli connection show | grep vpn | fzf)" 18 else 19 connection="$(nmcli connection show | grep vpn | zenity --list --title "Red Hat VPNs" --text "Choose your VPN.." --column "Name" --width=600 --height=450)" 20 fi 21 NOTIFY_CMD="notify-send" 22 if [[ GRAPHICS -eq 0 ]]; then 23 NOTIFY_CMD="echo" 24 fi 25 26 27 uuid=$(echo ${connection} | awk '{print $3}') 28 name=$(echo ${connection} | awk '{print $1 $2}') 29 VPNSTATUS=$(nmcli connection show --active $uuid | wc -l) 30 if [ "$VPNSTATUS" == "0" ] 31 then 32 key=$(authkey) 33 passfile=$(mktemp) 34 35 echo -n "vpn.secrets.password:" > $passfile 36 gpg --decrypt $HOME/sync/naruhodo.pass.gpg 2>/dev/null >>$passfile 37 echo -n "${key}" >> $passfile 38 39 nmcli connection up ${uuid} passwd-file $passfile 40 rm $passfile 41 $NOTIFY_CMD "VPN ${name} is connected." "You are now connected to the Red Hat VPN, let's work !" 42 else 43 $NOTIFY_CMD "VPN ${name} is already connected." "You are already connected to the Red Hat VPN, let's work !" 44 fi 45 # Ask for kerberos password if klist returns an error (no creds) 46 gpg --decrypt $HOME/sync/pass.gpg 2>/dev/null | kinit vdemeest@REDHAT.COM 47 # if ! [[ GRAPHICS -eq 0 ]]; then 48 # klist || { 49 # zenity --password --title="Kerberos password" | kinit vdemeest@REDHAT.COM 50 # } 51 # fi