diff --git a/README.md b/README.md index 77728a3..f7b1001 100644 --- a/README.md +++ b/README.md @@ -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.* diff --git a/autovpn.sh b/autovpn.sh index ec03752..51d7417 100755 --- a/autovpn.sh +++ b/autovpn.sh @@ -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" ]; @@ -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;