Skip to content
Open
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
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ None (:
Works only on Ubuntu(apt-get package) and Fedora (dnf package) related systems right now.
You need to run the script with root access(sudo).


**QUICK INSTALL**
```
wget -qO- 'https://raw.githubusercontent.com/mukulhase/AutoVPN/master/autovpn.sh' | sudo bash /dev/stdin email password
```

*Pull requests and suggestions for improvement are most welcome.*

Expand Down
63 changes: 25 additions & 38 deletions autovpn.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,21 @@ passwd=$2;
cd;
command -v openvpn >/dev/null 2>&1 || {
if command -v apt-get 2&>1; then # Ubuntu based distros
apt-get update; apt-get install openvpn;
apt-get update; apt-get install -y openvpn;
elif command -v dnf 2&>1; then # Fedora based distros
dnf install -y openvpn
fi
}
command -v expect >/dev/null 2>&1 || {
if command -v apt-get 2&>1; then # Ubuntu based distros
apt-get update; apt-get install expect;
elif command -v dnf 2&>1; then # Fedora based distros
dnf install -y expect
fi
}

if grep -q "nameserver 10.4.20.204" "/etc/resolv.conf";
then
sed -i '/nameserver 10.4.20.204/d' /etc/resolv.conf
fi
#apt-get update;


# if command -v apt-get 2&>1; then # Ubuntu based distros
# if [ $(dpkg-query -W -f='${Status}' openresolv 2>/dev/null | grep -c "ok installed") -eq 0 ];
# then
# apt-get -y install openresolv;
# fi
# elif command -v dnf 2&>1; then
# if ! rpm -qa | grep -qw openresolv; then
# dnf install -y openresolv
# fi # Fedora based distros
# fi

cd /etc/openvpn;
if [ ! -e "ca.crt" ];
Expand All @@ -57,37 +52,29 @@ chmod 600 all.iiit.ac.in.key;
if [ ! -e "linux_client.conf" ];
then
wget https://vpn.iiit.ac.in/linux_client.conf
echo 'auth-user-pass auth.txt' >> linux_client.conf
echo 'script-security 2' >> linux_client.conf
echo 'up "/etc/openvpn/update-resolv-conf.sh"' >> linux_client.conf
echo 'down "/etc/openvpn/update-resolv-conf.sh"' >> linux_client.conf
fi

if [ ! -e "update-resolv-conf.sh" ];
then
wget https://raw.githubusercontent.com/masterkorp/openvpn-update-resolv-conf/master/update-resolv-conf.sh
fi
chmod +x update-resolv-conf.sh

# Escape dollars in usr and passwd for expect's send
usr=$(echo "$usr"| sed 's/\$/\\\$/g')
passwd=$(echo "$passwd"| sed 's/\$/\\\$/g')
echo "$usr" > auth.txt
echo "$passwd" >> auth.txt
chmod 700 auth.txt

echo 'alias vpn="cd /etc/openvpn;sudo openvpn --config linux_client.conf"' >> ~/.bash_aliases

expect <<- DONE

spawn openvpn --config linux_client.conf;

expect "Enter Auth Username:" { send "$usr\r" }

expect "Enter Auth Password:" { send "$passwd\r" }

expect "Initialization Sequence Completed"


interact;
DONE

sleep 12;
if grep -q "nameserver 10.4.20.204" "/etc/resolv.conf";
then
echo "Nameserver already set. No need for further setting up";
else
sed -i '1i\'"nameserver 10.4.20.204" /etc/resolv.conf;
fi
openvpn --config linux_client.conf

sleep 3;
#num=`history | tail -n 2 | head -n 1 | tr -s ' ' | cut -d ' ' -f 2`;

#history -c;
Expand Down