ipsecvpnserver.sh 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #!/usr/bin/env bash
  2. while true;do ls | grep -q dockerbunker.sh;if [[ $? == 0 ]];then BASE_DIR=$PWD;break;else cd ../;fi;done
  3. PROPER_NAME="IPsec VPN Server"
  4. SERVICE_NAME="$(echo -e "${PROPER_NAME,,}" | tr -d '[:space:]')"
  5. declare -a environment=( "data/env/dockerbunker.env" "data/include/init.sh" )
  6. for env in "${environment[@]}";do
  7. [[ -f "${BASE_DIR}"/$env ]] && source "${BASE_DIR}"/$env
  8. done
  9. declare -a containers=( "${SERVICE_NAME}-service-dockerbunker" )
  10. declare -A IMAGES=( [service]="hwdsl2/ipsec-vpn-server" )
  11. declare -A volumes=( [${SERVICE_NAME}-data-vol-1]="/lib/modules" )
  12. [[ -z $1 ]] && options_menu
  13. configure() {
  14. pre_configure_routine
  15. echo -e "\n# \e[4mIPsec VPN Server Settings\e[0m"
  16. if [ -z "$VPN_USER" ]; then
  17. read -p "VPN Username: " -ei "vpnuser" VPN_USER
  18. else
  19. read -p "VPN Username: " -ei "${VPN_USER}" VPN_USER
  20. fi
  21. if [ -z "$VPN_PASSWORD" ]; then
  22. stty_orig=`stty -g`
  23. stty -echo
  24. read -p "VPN Password: " -ei "" VPN_PASSWORD
  25. stty $stty_orig
  26. echo ""
  27. fi
  28. # avoid tr illegal byte sequence in macOS when generating random strings
  29. if [[ $OSTYPE =~ "darwin" ]];then
  30. if [[ $LC_ALL ]];then
  31. oldLC_ALL=$LC_ALL
  32. export LC_ALL=C
  33. else
  34. export LC_ALL=C
  35. fi
  36. fi
  37. cat <<-EOF >> "${SERVICE_ENV}"
  38. # Please use long, random alphanumeric strings (A-Za-z0-9)
  39. VPN_IPSEC_PSK=$(tr -dc 'a-zA-Z0-9' < /dev/urandom | head -c 64)
  40. # ------------------------------
  41. # User configuration
  42. # ------------------------------
  43. VPN_USER=${VPN_USER}
  44. VPN_PASSWORD="${VPN_PASSWORD}"
  45. EOF
  46. if [[ $OSTYPE =~ "darwin" ]];then
  47. unset LC_ALL
  48. fi
  49. post_configure_routine
  50. }
  51. setup() {
  52. initial_setup_routine
  53. if ! lsmod | grep -q af_key;then
  54. echo -en "\e[1mLoading the IPsec NETKEY kernel module on the Docker host\e[0m"
  55. modprobe af_key
  56. exit_response
  57. [[ ! $(grep ^af_key$ /etc/modules) ]] && echo af_key >> /etc/modules
  58. fi
  59. docker_run_all
  60. post_setup_routine
  61. }
  62. $1