wireguard.sh 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/bin/bash
  2. version=1.0
  3. function print_centered {
  4. [[ $# == 0 ]] && return 1
  5. declare -i TERM_COLS="$(tput cols)"
  6. declare -i str_len="${#1}"
  7. [[ $str_len -ge $TERM_COLS ]] && {
  8. echo "$1";
  9. return 0;
  10. }
  11. declare -i filler_len="$(( (TERM_COLS - str_len) / 2 ))"
  12. [[ $# -ge 2 ]] && ch="${2:0:1}" || ch=" "
  13. filler=""
  14. for (( i = 0; i < filler_len; i++ )); do
  15. filler="${filler}${ch}"
  16. done
  17. printf "%s%s%s" "$filler" "$1" "$filler"
  18. [[ $(( (TERM_COLS - str_len) % 2 )) -ne 0 ]] && printf "%s" "${ch}"
  19. printf "\n"
  20. return 0
  21. }
  22. function intro_ {
  23. export TERM=xterm-256color
  24. print_centered "$(tput setaf 2)"
  25. print_centered " _ _ _ _ _ "
  26. print_centered "| | | |_|___ ___ ___ _ _ ___ ___ _| |"
  27. print_centered "| | | | | _| -_| . | | | .'| _| . |"
  28. print_centered "|_____|_|_| |___|_ |___|__,|_| |___|"
  29. print_centered " |___| "
  30. echo -n "$(tput sgr0)"
  31. print_centered "Wireguard VPN serveur v$version"
  32. print_centered ""
  33. sleep 5
  34. }
  35. function install_ {
  36. if grep "#net.ipv4.ip_forward=1" /etc/sysctl.conf >/dev/null
  37. then
  38. cp /etc/sysctl.conf /tmp/
  39. chmod 777 /tmp/sysctl.conf
  40. sed -i "s/#net.ipv4.ip_forward=1/net.ipv4.ip_forward=1/g" /tmp/sysctl.conf
  41. chmod 600 /tmp/sysctl.conf
  42. sudo cp /tmp/sysctl.conf /etc/sysctl.conf
  43. print_centered "Install sysctl.conf : [ OK ]"
  44. fi
  45. sudo apt install wireguard -y
  46. echo ""
  47. print_centered "Install soft : [ OK ]"
  48. sudo cp /Cloud/wireguard.tar.xz /
  49. cd /
  50. sudo tar xfJ wireguard.tar.xz
  51. sudo rm wireguard.tar.xz
  52. print_centered "Install config : [ OK ]"
  53. sudo systemctl enable wg-quick@wg0.service
  54. sudo systemctl start wg-quick@wg0.service
  55. print_centered "Start software : [ OK ]"
  56. }
  57. intro_
  58. install_