nftable-migration
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
5set -e
6
7GRAPHICS=1
8if ! [ "${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
14fi
15
16if [[ GRAPHICS -eq 0 ]]; then
17 connection="$(nmcli connection show | grep vpn | fzf)"
18else
19 connection="$(nmcli connection show | grep vpn | zenity --list --title "Red Hat VPNs" --text "Choose your VPN.." --column "Name" --width=600 --height=450)"
20fi
21NOTIFY_CMD="notify-send"
22if [[ GRAPHICS -eq 0 ]]; then
23 NOTIFY_CMD="echo"
24fi
25
26uuid=$(echo ${connection} | awk '{print $4}')
27name=$(echo ${connection} | awk '{print $1 $2 $3}')
28VPNSTATUS=$(nmcli connection show --active $uuid | wc -l)
29if [ "$VPNSTATUS" == "0" ]; then
30 key=$(authkey)
31 passfile=$(mktemp)
32
33 echo -n "vpn.secrets.password:" >$passfile
34 passage show redhat/vpn/pass | tr -d '\r\n' 2>/dev/null >>$passfile
35 # gpg --decrypt $HOME/sync/naruhodo.pass.gpg 2>/dev/null >>$passfile
36 echo -n "${key}" >>$passfile
37
38 nmcli connection up ${uuid} passwd-file $passfile
39 rm $passfile
40 $NOTIFY_CMD "VPN ${name} is connected." "You are now connected to the Red Hat VPN, let's work !"
41else
42 $NOTIFY_CMD "VPN ${name} is already connected." "You are already connected to the Red Hat VPN, let's work !"
43fi
44# Ask for kerberos password if klist returns an error (no creds)
45kinit vdemeest@IPA.REDHAT.COM <<<"$(passage show redhat/ldap/vdemeest)"
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