Skip to content

Instantly share code, notes, and snippets.

@riipandi
Created November 8, 2017 18:33
Show Gist options
  • Save riipandi/336ef8d7316785865bf527d392e52997 to your computer and use it in GitHub Desktop.
Save riipandi/336ef8d7316785865bf527d392e52997 to your computer and use it in GitHub Desktop.
#!/bin/bash
#===============================================================================================
# System Required: Debian or Ubuntu (32bit/64bit)
# Description: Install PPTP VPN for Debian or Ubuntu
# Author: mikangchan <[email protected]>
# More Info: http://ovo.so
#===============================================================================================
clear
echo "#############################################################"
echo "# Install pptp vpn for Debian or Ubuntu (32bit/64bit)"
echo "#"
echo "# Author: mikangchan <[email protected]>"
echo "#"
echo "#############################################################"
echo ""
function check_sanity {
# Check whether is available to install.
if [ $(/usr/bin/id -u) != "0" ]
then
die 'Run under root user'
fi
if [ ! -f /etc/debian_version ]
then
die "You are not using a Supported Debian or Ubuntu"
fi
}
function die {
echo "ERROR: $1" > /dev/null 1>&2
exit 1
}
function installVPN(){
apt-get update
rm -rf /etc/pptpd.conf
rm -rf /etc/ppp
apt-get -y --force-yes remove ppp pptpd
apt-get -y --force-yes install ppp pptpd iptables curl crudini
echo ms-dns 208.67.220.220 >> /etc/ppp/pptpd-options
echo ms-dns 208.67.222.222 >> /etc/ppp/pptpd-options
echo localip 192.168.90.1 >> /etc/pptpd.conf
echo remoteip 192.168.90.10-32 >> /etc/pptpd.conf
IP=`curl -s checkip.dyndns.com | cut -d' ' -f 6 | cut -d'<' -f 1`
if [ -z $IP ]; then
IP=`curl -s ifconfig.me/ip`
fi
iptables -t nat -A POSTROUTING -s 192.168.90.0/24 -j SNAT --to-source $IP
sed -i 's/exit\ 0/#exit\ 0/' /etc/rc.local
echo iptables -t nat -A POSTROUTING -s 192.168.90.0/24 -j SNAT --to-source $IP >> /etc/rc.local
echo exit 0 >> /etc/rc.local
crudini --set /etc/sysctl.conf '' 'net.ipv4.ip_forward' '1'
sysctl -p
/etc/init.d/pptpd restart
}
function uninstallVPN(){
echo "begin to uninstall VPN";
apt-get -y --force-yes remove ppp pptpd
sed -i '/192.168.90.0/d' /etc/rc.local
sed -i '/net.ipv4.ip_forward/d' /etc/sysctl.conf
sysctl -p
}
function repaireVPN(){
echo "begin to repaire VPN";
mknod /dev/ppp c 108 0
/etc/init.d/pptpd restart
}
function adduser(){
echo "input username:"
read username
echo "input password:"
read userpassword
echo "${username} pptpd ${userpassword} *" >> /etc/ppp/chap-secrets
/etc/init.d/pptpd restart
}
######################### Initialization ################################################
# Make sure only root can run this script
check_sanity
action=$1
[ -z $1 ] && action=install
case "$action" in
install)
installVPN
;;
uninstall)
uninstallVPN
;;
repaire)
repaireVPN
;;
adduser)
adduser
;;
*)
echo "Arguments error! [${action} ]"
echo "Usage: `basename $0` {install|uninstall|update}"
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment