Last active
August 10, 2023 19:16
-
-
Save nilox94/3bb16165bc1fbcb89e7661ba494e395e to your computer and use it in GitHub Desktop.
Executes `openvpn` with some known `.ovpn` files and prepares a route for your local network while `openvpn` is running
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
################################################################################ | |
# Matrix | |
# ====== | |
# | |
# `Matrix` executes `openvpn` with some known `.ovpn` files located in a given | |
# directory and sends a notification via `notify-osd` when vpn connection drops | |
# | |
################################################################################ | |
OVPN_DIR=~/Scripts/ovpn | |
MATRIX_ICON=/usr/share/notify-osd/icons/hicolor/scalable/status/notification-network-wireless.svg | |
function matrix() { | |
# run openvpn | |
sudo openvpn --config $OVPN_DIR/$1.ovpn ${@:2} | |
notify-send -i $MATRIX_ICON -c network.error matrix "$1 is down" | |
} | |
# bash completion | |
_matrix() | |
{ | |
local cur prev words cword | |
_init_completion || return | |
local files=`ls -l $OVPN_DIR/*.ovpn | awk -F '[. /]' '{print $(NF-1)}'` | |
COMPREPLY=( $( compgen -W "$files" -- "$cur" ) ) | |
return 0 | |
} && | |
complete -F _matrix matrix | |
# ex: ts=4 sw=4 et filetype=sh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment