SHARE
TWEET

Untitled

a guest Jul 12th, 2019 134 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. latest="v4.28-9669-beta-2018.09.11"
  4. lateststable="v4.25-9656-rtm-2018.01.15"
  5. #Release Date: 2013-08-30
  6. initfile="vpnserver"
  7.  
  8. echo "--------------------------------------------------------------------"
  9. echo "SoftEther VPN Server Install script"
  10. echo "By Ammar"
  11. echo "https://thenoobstribe.ga"
  12. echo "In case of any problem, email Ammar at: ammar@thenoobstribe.ga"
  13. echo "--------------------------------------------------------------------"
  14. echo "--------------------------------------------------------------------"
  15. echo
  16. echo "Select Architecture"
  17. echo
  18. echo " 1. Arm EABI (32bit)"
  19. echo " 2. Intel x86 (32bit)"
  20. echo " 3. Intel x64/AMD64 (64bit)"
  21. echo
  22. echo "Please choose architecture: "
  23. read tmp
  24. echo
  25.  
  26. if test "$tmp" = "3"
  27. then
  28.     arch="64bit_-_Intel_x64_or_AMD64"
  29.     arch2="x64-64bit"
  30.     echo "Selected : 3 " $arch
  31. elif test "$tmp" = "2"
  32. then
  33.     arch="32bit_-_Intel_x86"
  34.     arch2="x86-32bit"
  35.     echo "Selected : 2 " $arch
  36. elif test "$tmp" = "1"
  37. then
  38.     arch="32bit_-_ARM_EABI"
  39.     arch2="arm_eabi-32bit"
  40.     echo "Selected : 3 " $arch
  41. else #default if non selected
  42.     arch="32bit_-_Intel_x86"
  43.     arch2="x86-32bit"
  44.     echo "Selected : 1 " $arch
  45. fi
  46.  
  47. echo "--------------------------------------------------------------------"
  48. echo
  49. echo "Select OS"
  50. echo
  51. echo " 1. Debian/Ubuntu"
  52. echo " 2. CentOS/Fedora"
  53. echo
  54. echo "Please choose OS: "
  55. read tmp
  56. echo
  57.  
  58. if test "$tmp" = "2"
  59. then
  60.     os="cent"
  61.     echo "Selected : 2 CentOS/Fedora"
  62. else
  63.     os="deb"
  64.     echo "Selected : 1 Debian/Ubuntu"
  65. fi
  66.  
  67. echo "--------------------------------------------------------------------"
  68. echo
  69. echo "Select build"
  70. echo
  71. echo " 1. latest(might include beta/rc)"
  72. echo " 2. latest stable"
  73. echo
  74. echo "Please choose build: "
  75. read tmp
  76. echo
  77.  
  78. if test "$tmp" = "2"
  79. then
  80.     version="$lateststable"
  81.     echo "Latest stable selected: 2 "$lateststable
  82. else
  83.     version="$latest"
  84.     echo "Latest build(stable/beta) selected: 1 "$latest
  85. fi
  86.  
  87. file="softether-vpnserver-"$version"-linux-"$arch2".tar.gz"
  88. link="http://www.softether-download.com/files/softether/"$version"-tree/Linux/SoftEther_VPN_Server/"$arch"/"$file
  89.  
  90. if [ ! -s "$file" ]||[ ! -r "$file" ];then
  91.     #remove and redownload empty or unreadable file
  92.     rm -f "$link"
  93.     wget "$link"
  94. elif [ ! -f "file" ];then
  95.     #download if not exist
  96.     wget "$file"
  97. fi
  98.  
  99. if [ -f "$file" ];then
  100.     tar xzf "$file"
  101.     dir=$(pwd)
  102.     echo "current dir " $dir
  103.     cd vpnserver
  104.     dir=$(pwd)
  105.     echo "changed to dir " $dir
  106. else
  107.     echo "Archive not found. Please rerun this script or check permission."
  108.     break
  109. fi
  110.  
  111. if [ "$os" -eq "cent" ];then
  112.     yum upgrade
  113.     yum groupinstall "Development Tools" gcc
  114. else
  115.     apt-get update && apt-get upgrade -y && apt-get dist-upgrade -y
  116.     apt-get install htop nload -y
  117.     apt-get install whiptail -y
  118.     apt-get install build-essential -y
  119. fi
  120.  
  121. # making the executeable and pressing '1' a few times to accept the license agreement.
  122. printf '1\n1\n1\n' | make
  123. cd ..
  124. mv vpnserver /usr/local
  125. dir=$(pwd)
  126. echo "current dir " $dir
  127. cd /usr/local/vpnserver/
  128. dir=$(pwd)
  129. echo "changed to dir " $dir
  130. chmod 600 *
  131. chmod 700 vpnserver
  132. chmod 700 vpncmd
  133.  
  134. mkdir /var/lock/subsys
  135.  
  136. touch /etc/init.d/"$initfile"
  137. #need to cat two time to pass varible($initfile) value inside
  138. cat > /etc/init.d/"$initfile" <<EOF
  139. #!/bin/sh
  140. # chkconfig: 2345 99 01
  141. # description: SoftEther VPN Server
  142. DAEMON=/usr/local/vpnserver/$initfile
  143. LOCK=/var/lock/subsys/$initfile
  144. EOF
  145.  
  146. cat >> /etc/init.d/"$initfile" <<'EOF'
  147. test -x $DAEMON || exit 0
  148. case "$1" in
  149. start)
  150. $DAEMON start
  151. touch $LOCK
  152. ;;
  153. stop)
  154. $DAEMON stop
  155. rm $LOCK
  156. ;;
  157. restart)
  158. $DAEMON stop
  159. sleep 3
  160. $DAEMON start
  161. ;;
  162. *)
  163. echo "Usage: $0 {start|stop|restart}"
  164. exit 1
  165. esac
  166. exit 0
  167. EOF
  168.  
  169. chmod 755 /etc/init.d/"$initfile"
  170. if [ "$os" -eq "cent" ];then
  171.     chkconfig --add "$initfile"
  172.     /etc/init.d/"$initfile" start
  173. else
  174.     update-rc.d "$initfile" defaults
  175.     /etc/init.d/"$initfile" start
  176. fi
  177.  
  178. echo "How do you want to configure your VPN server?"
  179. echo
  180. echo " 1. No configuration as I will do it manually"
  181. echo " 2. vNAT and vDHCP (SecureNAT)"
  182. echo " 3. Local Bridge (dnsmasq as our DHCP server and our own NAT using POSTROUTE/IPTABLES)"
  183. echo
  184. echo "Please choose your configuration: "
  185. read tmp
  186. echo
  187.  
  188. if test "$tmp" = "1"
  189. then
  190. echo "--------------------------------------------------------------------"
  191. echo "--------------------------------------------------------------------"
  192. echo "Installation done. Hurray!"
  193. echo "Now you may want to change VPN server password."
  194. echo "Run in terminal:"
  195. echo "./vpncmd"
  196. echo "Press 1 to select \"Management of VPN Server or VPN Bridge\","
  197. echo "then press Enter without typing anything to connect to the "
  198. echo "localhost server, and again press Enter without inputting "
  199. echo "anything to connect to server by server admin mode."
  200. echo "Then use command below to change admin password:"
  201. echo "ServerPasswordSet"
  202. echo "Done...."
  203.     echo "Selected : 1 "
  204. elif test "$tmp" = "2"
  205. then
  206. echo "Waiting for 5 seconds to make sure everything has started and is ready to be configured..."
  207. sleep 5
  208. # Most important stuff. This huge ass line creates the Hubs, sets the passwords and whatever. Don't edit it unless you know what you're doing!
  209. printf '1\n127.0.0.1\n\nServerPasswordSet PASSWORD\nHubCreate VPN /PASSWORD:PASSWORD\nHub VPN\nUserCreate VPN\n\n\n\nUserPasswordSet VPN /PASSWORD:PASSWORD\nIPsecEnable\nyes\nyes\nyes\nvpn\nVPN\nSecureNatEnable\nDhcpSet /start:192.168.30.10 /end:192.168.30.200 /mask:255.255.255.0 /expire:7200 /gw:192.168.30.1 /dns:188.165.43.132 /dns2:162.248.164.44 /domain=thenoobstribe.ga /log:yes\nHubDelete DEFAULT' | ./vpncmd
  210. echo "Waiting for 5 seconds to make sure everything has started and is ready to be configured..."
  211. sleep 5
  212. /etc/init.d/vpnserver restart
  213. echo "The installation script -should- be completed without errors. I didn't add any error reporting so uh... should b good (scroll up and check for errors to be sure)!"
  214. echo "Here is the info that you need to connect: "
  215. echo "Admin password: PASSWORD "
  216. echo "Client username: VPN "
  217. echo "Client password: PASSWORD "
  218. echo "DHCP range: 192.168.30.10 - 192.168.30.200 "
  219. echo "DNS servers: 188.165.43.132 and 162.248.164.44 "
  220. echo "All options mentioned above can be changed in the SoftEther VPN Server Manager"
  221. echo "In case of any problem, email Ammar at: ammar@thenoobstribe.ga"
  222.     echo "Selected : 2 "
  223. elif test "$tmp" = "3"
  224. then
  225. #INTERFACE is the outgoing network interface. On OpenVZ it's usually venet0:0, but on KVM/Xen/whatever it's eth0.
  226. INTERFACE=eth0
  227. # some stuff to fetch the IP address of an interface
  228. IP="$(/sbin/ifconfig $INTERFACE | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}')"
  229. cd /usr/local/vpnserver
  230.  
  231. echo "Waiting for 5 seconds to make sure everything has started and is ready to be configured..."
  232. sleep 5
  233. # Most important stuff. This huge ass line creates the Hubs, sets the passwords and whatever. Don't edit it unless you know what you're doing!
  234. printf '1\n127.0.0.1\n\nServerPasswordSet PASSWORD\nHubCreate VPN /PASSWORD:PASSWORD\nHub VPN\nUserCreate VPN\n\n\n\nUserPasswordSet VPN /PASSWORD:PASSWORD\nIPsecEnable\nyes\nyes\nyes\nvpn\nVPN\nBridgeCreate VPN /TAP:yes\nsoft\nSecureNatEnable\nDhcpSet /start:192.168.7.100 /end:192.168.7.200 /mask:255.255.255.0 /expire:7200 /gw:192.168.7.1 /dns:188.165.43.132 /dns2:162.248.164.44 /domain=thenoobstribe.ga /log:yes\nNatDisable\nHubDelete DEFAULT' | ./vpncmd
  235. #/etc/init.d/vpnserver restart
  236. # Stuff for localbridge, to make the transfer speeds faster.
  237. echo "net.ipv4.ip_forward = 1" > /etc/sysctl.d/ipv4_forwarding.conf
  238. sysctl --system
  239. iptables -t nat -A POSTROUTING -s 192.168.7.0/24 -j SNAT --to-source $IP
  240. whiptail --msgbox "Due to a bug, you need to press yes twice at the following prompt. Please press any key to continue." 10 100
  241. apt-get install iptables-persistent -y
  242.  
  243. echo '#!/bin/sh
  244. ### BEGIN INIT INFO
  245. # Provides:          vpnserver
  246. # Required-Start:    $remote_fs $syslog
  247. # Required-Stop:     $remote_fs $syslog
  248. # Default-Start:     2 3 4 5
  249. # Default-Stop:      0 1 6
  250. # Short-Description: Start daemon at boot time
  251. # Description:       Enable Softether by daemon.
  252. ### END INIT INFO
  253. DAEMON=/usr/local/vpnserver/vpnserver
  254. LOCK=/var/lock/subsys/vpnserver
  255. TAP_ADDR=192.168.7.1
  256.  
  257. test -x $DAEMON || exit 0
  258. case "$1" in
  259. start)
  260. $DAEMON start
  261. touch $LOCK
  262. sleep 1
  263. /sbin/ifconfig tap_soft $TAP_ADDR
  264. ;;
  265. stop)
  266. $DAEMON stop
  267. rm $LOCK
  268. ;;
  269. restart)
  270. $DAEMON stop
  271. sleep 3
  272. $DAEMON start
  273. sleep 1
  274. /sbin/ifconfig tap_soft $TAP_ADDR
  275. ;;
  276. *)
  277. echo "Usage: $0 {start|stop|restart}"
  278. exit 1
  279. esac
  280. exit 0' > /etc/init.d/vpnserver
  281. chmod 755 /etc/init.d/vpnserver && /etc/init.d/vpnserver restart
  282.  
  283. clear
  284. echo "The installation script -should- be completed without errors. I didn't add any error reporting so uh... should b good (scroll up and check for errors to be sure)!"
  285. echo "Here is the info that you need to connect: "
  286. echo "IP address: $IP"
  287. echo "Admin password: PASSWORD "
  288. echo "Client username: VPN "
  289. echo "Client password: PASSWORD "
  290. echo "DHCP range: 192.168.7.100 - 192.168.7.200 "
  291. echo "DNS servers: 188.165.43.132 and 162.248.164.44 "
  292. echo "All options mentioned above can be changed in the SoftEther VPN Server Manager"
  293. echo "In case of any problem, email Ammar at: ammar@thenoobstribe.ga"
  294.     echo "Selected : 3 "
  295. else #default if non selected
  296. echo "--------------------------------------------------------------------"
  297. echo "--------------------------------------------------------------------"
  298. echo "Installation done. Hurray!"
  299. echo "Now you may want to change VPN server password."
  300. echo "Run in terminal:"
  301. echo "./vpncmd"
  302. echo "Press 1 to select \"Management of VPN Server or VPN Bridge\","
  303. echo "then press Enter without typing anything to connect to the "
  304. echo "localhost server, and again press Enter without inputting "
  305. echo "anything to connect to server by server admin mode."
  306. echo "Then use command below to change admin password:"
  307. echo "ServerPasswordSet"
  308. echo "Done...."
  309.     echo "Selected : 1 "
  310. fi
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top