wireguard.sh 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #!/bin/bash
  2. clear
  3. if [[ "$EUID" -ne 0 ]]; then
  4. echo -e "\033[1;31mScript need to be run as root!\033[0m"; exit 1
  5. fi
  6. echo "deb http://deb.debian.org/debian buster-backports main" | tee /etc/apt/sources.list.d/buster-backports.list
  7. apt-get -qq update
  8. apt-get -y -qq install wireguard
  9. apt-get -y -qq install wireguard-tools
  10. apt-get -y -qq install wireguard-dkms
  11. apt-get -y -qq install linux-headers-$(uname -r)
  12. apt-get -y -qq install qrencode
  13. if [[ ! -d /etc/wireguard/clients ]]; then
  14. mkdir -p /etc/wireguard/clients
  15. mkdir -p /etc/wireguard/clients/aidanvpn
  16. touch /etc/wireguard/clients/.accounts
  17. fi
  18. alamat_ip=$(wget -qO- ipv4.icanhazip.com)
  19. alamat_hos=$(cat /etc/environment | grep -w 'DOMAIN' | cut -d '=' -f 2)
  20. server_private_key=$(wg genkey)
  21. server_public_key=$(echo "$server_private_key" | wg pubkey)
  22. client_private_key=$(wg genkey)
  23. client_public_key=$(echo "$client_private_key" | wg pubkey)
  24. preshared_key=$(wg genpsk)
  25. peer_port=$(shuf -i1024-65535 -n1)
  26. nama_pengguna=$(cat /etc/environment | grep -w 'USERNAME' | cut -d '=' -f 2)
  27. cat > /etc/wireguard/wg0.conf <<EOF
  28. [Interface]
  29. Address = 10.80.0.0/24
  30. ListenPort = 51820
  31. PrivateKey = $server_private_key
  32. PostUp = iptables -A FORWARD -i wg0 -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE;
  33. PostDown = iptables -D FORWARD -i wg0 -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE;
  34. SaveConfig = false
  35. # $nama_pengguna start
  36. [Peer]
  37. PublicKey = $client_public_key
  38. PresharedKey = $preshared_key
  39. AllowedIPs = 10.80.0.1/32
  40. # $nama_pengguna end
  41. EOF
  42. cat >> /etc/wireguard/clients/$nama_pengguna/$nama_pengguna.conf <<EOF
  43. # $nama_pengguna
  44. [Interface]
  45. Address = 10.80.0.1/32
  46. DNS = 8.8.8.8,8.8.4.4
  47. ListenPort = $peer_port
  48. MTU = 1280
  49. PrivateKey = $client_private_key
  50. [Peer]
  51. AllowedIPs = 0.0.0.0/0
  52. Endpoint = vpn.aidan.my:51820
  53. PersistentKeepalive = 300
  54. PresharedKey = $preshared_key
  55. PublicKey = $server_public_key
  56. EOF
  57. # Generate QR Code
  58. qrencode -m 2 -t ansiutf8 \
  59. -o "/etc/wireguard/clients/$nama_pengguna/$nama_pengguna.png" \
  60. -r "/etc/wireguard/clients/$nama_pengguna/$nama_pengguna.conf"
  61. systemctl enable wg-quick@wg0
  62. systemctl restart wg-quick@wg0
  63. echo
  64. echo -e "\033[1;32mCongratulation, We are done with the wireguard installation.\033[0m"
  65. echo
  66. echo 'Use my referral link https://m.do.co/c/a28a40414d6a'
  67. echo 'to gets $100 credit into your DigitalOcean account.'
  68. echo 'Created by Doctype, Powered by Cybertize'
  69. echo 'Copyright 2021, Allright reserved.'
  70. echo; sleep 5