#!/bin/bash # # pptpd automatic provisioning # - code by Jioh L. Jung (ziozzang@gmail.com) # SERVICE_PORT=${SERVICE_PORT:-"1723"} KEY_SIZE=${KEY_SIZE:-"1024"} USER_ID=${USER_ID:-"ziozzang"} E_MAIL=${E_MAIL:-"ziozzang@gmail.com"} USER_PW=${USER_PW:-"loginme"} # ================================================== [[ "$(id -u)" -eq 0 ]] || (echo "FATAL: Root privilege is required."; exit 1) LOCAL_IP=`ifconfig eth0 | grep -m 1 'inet addr:' | cut -d: -f2 | awk '{print $1}'` apt-get update -fy apt-get install -fy pptpd IPF=`cat /etc/pptpd.conf | grep "^localip" | wc -l` if [[ "$IPF" -eq "0" ]]; then cat >> /etc/pptpd.conf << EOF localip ${LOCAL_IP} remoteip 10.244.0.10-240 netmask 255.255.255.0 EOF fi IPF=`cat /etc/ppp/chap-secrets | grep "${USER_ID}" | grep "pptpd" | wc -l` if [[ "$IPF" -eq "0" ]]; then cat >> /etc/ppp/chap-secrets << EOF ${USER_ID} pptpd ${USER_PW} * EOF chown root:root /etc/ppp/chap-secrets chmod 740 /etc/ppp/chap-secrets fi IPF=`cat /etc/ppp/pptpd-options | grep "^ms-dns" | wc -l` if [[ "$IPF" -eq "0" ]]; then cat >> /etc/ppp/pptpd-options << EOF ms-dns 8.8.8.8 ms-dns 8.8.4.4 EOF fi IPF=`cat /etc/sysctl.conf | grep "^net.ipv4.ip_forward" | wc -l` if [[ "$IPF" -eq "0" ]]; then echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf fi echo 1 > /proc/sys/net/ipv4/ip_forward IPF=`iptables-save | grep "10.244.0.0" | wc -l` if [[ "$IPF" -eq "0" ]]; then iptables -t nat -A POSTROUTING -s 10.244.0.0/24 -o eth0 -j MASQUERADE fi wget -qO- https://raw.github.com/ziozzang/home-server/master/vpn/install-preserve-iptables-ubuntu | bash ufw allow ${SERVICE_PORT}/tcp service pptpd restart update-rc.d pptpd defaults echo "AUTOSTART=\"pptpd\"" >> /etc/default/pptpd