wireguard.sh 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. print_centered "$(tput setaf 2)"
  24. print_centered " _ _ _ _ _ "
  25. print_centered "| | | |_|___ ___ ___ _ _ ___ ___ _| |"
  26. print_centered "| | | | | _| -_| . | | | .'| _| . |"
  27. print_centered "|_____|_|_| |___|_ |___|__,|_| |___|"
  28. print_centered " |___| "
  29. echo -n "$(tput sgr0)"
  30. print_centered "Wireguard VPN serveur v$version"
  31. print_centered ""
  32. sleep 5
  33. }
  34. function install_ {
  35. if grep "#net.ipv4.ip_forward=1" /etc/sysctl.conf >/dev/null
  36. then
  37. cp /etc/sysctl.conf /tmp/
  38. chmod 777 /tmp/sysctl.conf
  39. sed -i "s/#net.ipv4.ip_forward=1/net.ipv4.ip_forward=1/g" /tmp/sysctl.conf
  40. chmod 600 /tmp/sysctl.conf
  41. sudo cp /tmp/sysctl.conf /etc/sysctl.conf
  42. print_centered "Install sysctl.conf : [ OK ]"
  43. fi
  44. sudo apt install wireguard -y
  45. echo ""
  46. print_centered "Install soft : [ OK ]"
  47. sudo cp /Cloud/wireguard.tar.xz /
  48. cd /
  49. sudo tar xfJ wireguard.tar.xz
  50. sudo rm wireguard.tar.xz
  51. print_centered "Install config : [ OK ]"
  52. sudo systemctl enable wg-quick@wg0.service
  53. sudo systemctl start wg-quick@wg0.service
  54. print_centered "Start software : [ OK ]"
  55. }
  56. intro_
  57. install_