1- #! /bin/bash
1+ #! /bin/bash
2+
3+ _lazy_connect_config_dir=~ /.config/lazy-connect
4+ _lazy_connect_project_dir=~ /.lazy-connect
25
36function _lazy_connect_init() {
4- config_dir=~ /.config/lazy-connect
57 echo -n " Secret Key: "
68 read -s secret_key
79 echo " **********"
8- echo $secret_key > $config_dir /secret
10+ echo $secret_key > $_lazy_connect_config_dir /secret
11+ _lazy_connect_vpn_refresh
12+ }
913
14+ function _lazy_connect_vpn_refresh() {
15+ local backup_file=/tmp/lazy-connect-vpns-` date +%-H-%M-%S-%F`
16+ [ -f $_lazy_connect_config_dir /vpns ] && cp $_lazy_connect_config_dir /vpns $backup_file
1017 osascript << EOF |
1118 tell application "System Events"
1219 tell process "SystemUIServer"
@@ -27,10 +34,11 @@ function _lazy_connect_init() {
2734 end tell
2835 end tell
2936EOF
30- tr , ' \n' | sed ' s/ Connect/Connect /g' > $config_dir /vpns
37+ tr ' , ' ' \n' | sed ' s/^[[:space:]]/ /g' > $_lazy_connect_config_dir /vpns
3138
32- echo " VPN List:"
33- cat $config_dir /vpns | nl
39+ [ -f $backup_file ] && echo -e " \nDiff:\n$( diff -y $backup_file $_lazy_connect_config_dir /vpns) "
40+ echo -e " \nVPN List:"
41+ cat $_lazy_connect_config_dir /vpns | nl
3442}
3543
3644function _lazy_connect_usage() {
@@ -44,6 +52,7 @@ lazy-connect - Shell function to fuzzy search an IPSec VPN by name
4452-i - Initialize lazy-connect.
4553 Stores the secret and VPN list to ~/.config/lazy-connect/
4654-u - Update lazy-connect
55+ -r - Refresh vpn list in ~/.config/lazy-connect
4756-h - Show this help
4857EOF
4958}
7887}
7988
8089function _lazy_connect_update() {
81- lazy_connect_dir=~ /.lazy-connect
82- git -C $lazy_connect_dir pull origin master
90+ git -C $_lazy_connect_project_dir pull origin master
8391 echo -e " \n\nRun the below command or restart your shell."
84- echo " $ source $lazy_connect_dir /lazy-connect.sh"
92+ echo " $ source $_lazy_connect_project_dir /lazy-connect.sh"
8593}
8694
8795function lazy-connect() {
8896 local OPTIND
89- config_dir=~ /.config/lazy-connect
90- mkdir -p $config_dir
97+ mkdir -p $_lazy_connect_config_dir
9198
92- while getopts " ihu " opt; do
99+ while getopts " iruh " opt; do
93100 case $opt in
94101 h)
95102 _lazy_connect_usage
@@ -99,6 +106,11 @@ function lazy-connect() {
99106 _lazy_connect_init
100107 return 0
101108 ;;
109+ r)
110+ echo " Refreshing VPN list..."
111+ _lazy_connect_vpn_refresh
112+ return 0
113+ ;;
102114 u)
103115 _lazy_connect_update
104116 return 0
@@ -116,8 +128,8 @@ function lazy-connect() {
116128 esac
117129 done
118130
119- secret=$( cat $config_dir /secret)
120- vpn_name=$( cat $config_dir /vpns \
131+ secret=$( cat $_lazy_connect_config_dir /secret)
132+ vpn_name=$( cat $_lazy_connect_config_dir /vpns \
121133 | fzf --height=10 --ansi --reverse)
122134 [ -z " $vpn_name " ] || _lazy_connect " $vpn_name " " $secret "
123- }
135+ }
0 commit comments