Skip to content

Disable update prompt with env, refresh vpn list without updating secret #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ lazy-connect - Shell function to fuzzy search an IPSec VPN by name

-i - Initialize lazy-connect.
Stores the secret and VPN list to ~/.config/lazy-connect/
-r - refresh vpn list in ~/.config/lazy-connect
-h - Show this help
```

Expand Down
42 changes: 27 additions & 15 deletions lazy-connect.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
#! /bin/bash
#!/bin/bash

_lazy_connect_config_dir=~/.config/lazy-connect
_lazy_connect_project_dir=~/.lazy-connect

function _lazy_connect_init() {
config_dir=~/.config/lazy-connect
echo -n "Secret Key: "
read -s secret_key
echo "**********"
echo $secret_key > $config_dir/secret
echo $secret_key > $_lazy_connect_config_dir/secret
_lazy_connect_vpn_refresh
}

function _lazy_connect_vpn_refresh() {
local backup_file=/tmp/lazy-connect-vpns-`date +%-H-%M-%S-%F`
[ -f $_lazy_connect_config_dir/vpns ] && cp $_lazy_connect_config_dir/vpns $backup_file
osascript <<EOF |
tell application "System Events"
tell process "SystemUIServer"
Expand All @@ -27,10 +34,11 @@ function _lazy_connect_init() {
end tell
end tell
EOF
tr , '\n' | sed 's/ Connect/Connect/g' > $config_dir/vpns
tr ',' '\n' | sed 's/^[[:space:]]//g' > $_lazy_connect_config_dir/vpns

echo "VPN List:"
cat $config_dir/vpns | nl
[ -f $backup_file ] && echo -e "\nDiff:\n$(diff -y $backup_file $_lazy_connect_config_dir/vpns)"
echo -e "\nVPN List:"
cat $_lazy_connect_config_dir/vpns | nl
}

function _lazy_connect_usage() {
Expand All @@ -44,6 +52,7 @@ lazy-connect - Shell function to fuzzy search an IPSec VPN by name
-i - Initialize lazy-connect.
Stores the secret and VPN list to ~/.config/lazy-connect/
-u - Update lazy-connect
-r - Refresh vpn list in ~/.config/lazy-connect
-h - Show this help
EOF
}
Expand Down Expand Up @@ -78,18 +87,16 @@ EOF
}

function _lazy_connect_update() {
lazy_connect_dir=~/.lazy-connect
git -C $lazy_connect_dir pull origin master
git -C $_lazy_connect_project_dir pull origin master
echo -e "\n\nRun the below command or restart your shell."
echo "$ source $lazy_connect_dir/lazy-connect.sh"
echo "$ source $_lazy_connect_project_dir/lazy-connect.sh"
}

function lazy-connect() {
local OPTIND
config_dir=~/.config/lazy-connect
mkdir -p $config_dir
mkdir -p $_lazy_connect_config_dir

while getopts "ihu" opt; do
while getopts "iruh" opt; do
case $opt in
h)
_lazy_connect_usage
Expand All @@ -99,6 +106,11 @@ function lazy-connect() {
_lazy_connect_init
return 0
;;
r)
echo "Refreshing VPN list..."
_lazy_connect_vpn_refresh
return 0
;;
u)
_lazy_connect_update
return 0
Expand All @@ -116,8 +128,8 @@ function lazy-connect() {
esac
done

secret=$(cat $config_dir/secret)
vpn_name=$(cat $config_dir/vpns \
secret=$(cat $_lazy_connect_config_dir/secret)
vpn_name=$(cat $_lazy_connect_config_dir/vpns \
| fzf --height=10 --ansi --reverse)
[ -z "$vpn_name" ] || _lazy_connect "$vpn_name" "$secret"
}
}