Skip to content

Instantly share code, notes, and snippets.

@nilox94
Last active August 10, 2023 19:16
Show Gist options
  • Save nilox94/3bb16165bc1fbcb89e7661ba494e395e to your computer and use it in GitHub Desktop.
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
#!/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