dotfiles

*nix config files
git clone git://git.pyratebeard.net/dotfiles.git
Log | Files | Refs | README

commit 1be405d2a46d8269e34fb462b3d260920497cbca
parent 2c1170883d03dabac896719dccee24ce659d25ef
Author: pyratebeard <root@pyratebeard.net>
Date:   Fri, 11 Oct 2019 23:54:42 +0100

connect scripts

connect and disconnect scripts for wifi. remove 'connect' alias

Diffstat:
Abin/bin/connect | 51+++++++++++++++++++++++++++++++++++++++++++++++++++
Abin/bin/disconnect | 15+++++++++++++++
Mzsh/.zsh/aliases.zsh | 1-
3 files changed, 66 insertions(+), 1 deletion(-)

diff --git a/bin/bin/connect b/bin/bin/connect @@ -0,0 +1,51 @@ +#!/usr/bin/env bash + +# vars +WIFI_DEV="wlp3s0" +CONNECTION_FILE=$1 +CONNECTION=$(echo ${CONNECTION_FILE} | awk -F\/ '{print $NF}') + +if [ ! $1 ] ; then + echo "specify a connection file" + exit 1 +elif [ ! -f ${CONNECTION_FILE} ] ; then + echo "${CONNECTION_FILE} does not exist" + exit 1 +fi + +# disconnect +echo "disconnecting any running connection" +$HOME/bin/disconnect + +# bring dev up +if $(ip link show up | grep ${WIFI_DEV} >/dev/null) ; then + echo "${WIFI_DEV} is already up" +else + echo "bringing ${WIFI_DEV} up" + sudo ip link set ${WIFI_DEV} up >/dev/null +fi + +# connect using specified config +if [ -f ${CONNECTION_FILE} ] ; then + echo "connecting to ${CONNECTION}" + sudo wpa_supplicant -B -q -i ${WIFI_DEV} -c ${CONNECTION_FILE} >/dev/null 2>&1 +fi + +# get an ip +echo "starting dhcpcd" +sudo dhcpcd ${WIFI_DEV} >/dev/null 2>&1 + +# when remote bring ip vpn +if [ ${CONNECTION} != "home" ] ; then + echo "not at home, starting vpn" + sudo openvpn --config lib/key/wht-rht-obj.ovpn --daemon >/dev/null 2>&1 + sudo systemd-tty-ask-password-agent >/dev/null + sleep 5 + ping -q -c1 fortkickass >/dev/null + if [ $? -eq 0 ] ; then + echo "vpn is up" + else + echo "vpn is not up... disconnecting now" + $HOME/bin/disconnect + fi +fi diff --git a/bin/bin/disconnect b/bin/bin/disconnect @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + +WIFI_DEV="wlp3s0" + +killit() { + if $(pidof ${1} >/dev/null) ; then + echo "killing $1" + sudo kill -9 $(pidof ${1}) + fi +} + +sudo ip link set ${WIFI_DEV} down +killit wpa_supplicant +killit dhcpcd +killit openvpn diff --git a/zsh/.zsh/aliases.zsh b/zsh/.zsh/aliases.zsh @@ -42,7 +42,6 @@ alias disks='echo "╓───── m o u n t . p o i n t s"; echo "╙── alias record="ffmpeg -f x11grab -s 1366x768 -an -r 16 -loglevel quiet -i :0.0 -b:v 5M -y" #pass a filename alias gifview="gifview -a" alias reboot="sudo reboot" -alias connect="sudo wpa_supplicant -B -i wlp3s0 -c" alias vh="nc vhbin.net 9999" alias kb="keybase" alias dd="dd status=progress"