Script to configure NordVPN using OpenVPN on DD-WRT
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
#!/usr/bin/env bash | |
# Script to initialize OpenVPN on DD-WRT firmware | |
TUN=tun0 | |
ROUTER_USER=root | |
ROUTER_HOST=192.168.1.1 | |
ROUTER_SSH=$ROUTER_USER@$ROUTER_HOST | |
CONFIG_URL=https://nordvpn.com/api/files/zip | |
# Pipe input to a file on the router | |
function pipeFile() { | |
ssh -q $ROUTER_SSH "cat > $1" | |
} | |
# Clean up configuration stuff | |
function cleanUp() { | |
rv=$? | |
rm -rf $server_config_home | |
exit $rv | |
} | |
read -p "Enter server: " server_prefix | |
server_config_home=`mktemp -d` | |
server_config_zip=$server_config_home/config.zip | |
server_config=$server_config_home/${server_prefix}.ovpn | |
trap cleanUp INT TERM EXIT | |
echo Downloading configuration... | |
wget -q --show-progress -O $server_config_zip $CONFIG_URL | |
unzip -p $server_config_zip ${server_prefix}.nordvpn.com.udp1194.ovpn > $server_config | |
if [ ! -f $server_config ]; then | |
echo Server does not exist | |
exit 1 | |
fi | |
read -p "Enter username: " username | |
read -s -p "Enter password: " password | |
echo -e "\n" | |
echo Copying files... | |
echo -e "$username\n$password" | pipeFile openvpn_auth.txt | |
echo -e "#!/bin/sh \n iptables -t nat -I POSTROUTING -o $TUN -j MASQUERADE" | pipeFile route-up.sh | |
echo -e "#!/bin/sh \n iptables -t nat -D POSTROUTING -o $TUN -j MASQUERADE" | pipeFile route-down.sh | |
echo -e '#!/bin/sh \n killall openvpn ; openvpn --config nordvpn.ovpn --route-up `pwd`/route-up.sh --route-pre-down `pwd`/route-down.sh --script-security 2' | pipeFile vpn.sh | |
< $server_config sed -E "s/^(auth-user-pass)/\1 openvpn_auth.txt/" | pipeFile nordvpn.ovpn | |
echo Starting... | |
ssh -q $ROUTER_SSH " | |
if [ \`nvram get openvpncl_enable\` != 0 ]; then | |
echo Disabling OpenVPN UI; nvram set openvpncl_enable=0 | |
nvram commit | |
sleep 10 | |
fi | |
chmod 600 openvpn_auth.txt nordvpn.ovpn | |
chmod 700 route-up.sh route-down.sh vpn.sh | |
nohup ./vpn.sh < /dev/null > openvpn.log 2>&1 & | |
" | |
echo Done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment