From 481aaeee5db783e7c0f40b679ccc10af39781354 Mon Sep 17 00:00:00 2001 From: Mukul Hase Date: Wed, 30 Nov 2016 10:58:19 +0530 Subject: [PATCH 1/5] Removed expect script, Added -y to automate ubuntu installations --- autovpn.sh | 59 ++++++++++++++++++++---------------------------------- 1 file changed, 22 insertions(+), 37 deletions(-) diff --git a/autovpn.sh b/autovpn.sh index ec03752..a331fd1 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 +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 -} - -if grep -q "nameserver 10.4.20.204" "/etc/resolv.conf"; -then -sed -i '/nameserver 10.4.20.204/d' /etc/resolv.conf +elif command -v dnf 2&>1; then + if ! rpm -qa | grep -qw openresolv; then + dnf install -y openresolv + fi # Fedora based distros fi -#apt-get update; - - cd /etc/openvpn; if [ ! -e "ca.crt" ]; @@ -59,35 +54,25 @@ then wget https://vpn.iiit.ac.in/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 '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 +openvpn --config linux_client.conf -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 - -sleep 3; #num=`history | tail -n 2 | head -n 1 | tr -s ' ' | cut -d ' ' -f 2`; #history -c; From 11a6cdfa1a44b75455ab8c4efefc4584bbb3237a Mon Sep 17 00:00:00 2001 From: Mukul Hase Date: Wed, 30 Nov 2016 14:52:23 +0530 Subject: [PATCH 2/5] Added neat little alias --- README.md | 5 ++++- autovpn.sh | 10 ++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) 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 a331fd1..672b1c3 100755 --- a/autovpn.sh +++ b/autovpn.sh @@ -52,6 +52,10 @@ 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" ]; @@ -66,10 +70,8 @@ passwd=$(echo "$passwd"| sed 's/\$/\\\$/g') echo "$usr" > auth.txt echo "$passwd" >> auth.txt chmod 700 auth.txt -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 + +echo 'alias vpn="cd /etc/openvpn;sudo openvpn --config linux_client.conf"' >> ~/.bash_aliases openvpn --config linux_client.conf From 7e0667856886ed6c50ed09e4c0d0a8561099b9cf Mon Sep 17 00:00:00 2001 From: Mukul Hase Date: Wed, 30 Nov 2016 15:38:43 +0530 Subject: [PATCH 3/5] Changed update script --- autovpn.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autovpn.sh b/autovpn.sh index 672b1c3..5f8d784 100755 --- a/autovpn.sh +++ b/autovpn.sh @@ -60,7 +60,7 @@ fi if [ ! -e "update-resolv-conf.sh" ]; then - wget https://raw.githubusercontent.com/masterkorp/openvpn-update-resolv-conf/master/update-resolv-conf.sh + wget https://raw.githubusercontent.com/mukulhase/openvpn-update-resolv-conf/master/update-resolv-conf.sh fi chmod +x update-resolv-conf.sh From d6bf67b93122d062ad24e0db072119b2eba39fd1 Mon Sep 17 00:00:00 2001 From: Mukul Hase Date: Wed, 30 Nov 2016 16:26:15 +0530 Subject: [PATCH 4/5] Changed update script --- autovpn.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autovpn.sh b/autovpn.sh index 5f8d784..672b1c3 100755 --- a/autovpn.sh +++ b/autovpn.sh @@ -60,7 +60,7 @@ fi if [ ! -e "update-resolv-conf.sh" ]; then - wget https://raw.githubusercontent.com/mukulhase/openvpn-update-resolv-conf/master/update-resolv-conf.sh + wget https://raw.githubusercontent.com/masterkorp/openvpn-update-resolv-conf/master/update-resolv-conf.sh fi chmod +x update-resolv-conf.sh From eae34136b693ca2ba6a662869e38a8237111a0e2 Mon Sep 17 00:00:00 2001 From: Mukul Hase Date: Fri, 24 Mar 2017 15:03:21 +0530 Subject: [PATCH 5/5] fix --- autovpn.sh | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/autovpn.sh b/autovpn.sh index 672b1c3..51d7417 100755 --- a/autovpn.sh +++ b/autovpn.sh @@ -22,16 +22,16 @@ command -v openvpn >/dev/null 2>&1 || { dnf install -y openvpn fi } -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 +# 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" ];