docker-entrypoint.sh 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/bin/sh
  2. #set -e
  3. export RNG=PROGRAM
  4. if [ ${mode} == "server" ]
  5. then
  6. mv /etc/openvpn/server.conf /etc/openvpn/ovpn.conf
  7. echo -e "LegacySigningMDs md2 md5\nMinimumDHBits 512\n" >> /etc/pki/tls/legacy-settings
  8. if [[ ${net} ]]
  9. then
  10. echo "push \"route ${net} 255.255.255.0\"" >> /etc/openvpn/ovpn.conf
  11. fi
  12. if [[ ${dev} && ${ip} ]]
  13. then
  14. if [ -z ${client_net} ]
  15. then
  16. client_net="10.10.20.0/24"
  17. fi
  18. trap cleanup SIGTERM EXIT
  19. cleanup()
  20. {
  21. ip addr del ${ip}/24 dev ${dev}:ovpn
  22. iptables -D FORWARD -m state --state NEW -s ${client_net} -o external -j DROP
  23. }
  24. ip addr add ${ip}/24 brd + dev ${dev} label ${dev}:ovpn
  25. iptables -I FORWARD 1 -m state --state NEW -s ${client_net} -o external -j DROP
  26. exec "/usr/sbin/openvpn" "--config" "/etc/openvpn/ovpn.conf" "$@" &
  27. wait
  28. else
  29. exec "/usr/sbin/openvpn" "--config" "/etc/openvpn/ovpn.conf" "$@"
  30. fi
  31. fi
  32. if [ ${mode} == "client" ]
  33. then
  34. mv /etc/openvpn/client.conf /etc/openvpn/ovpn.conf
  35. echo "remote ${server}" >> /etc/openvpn/ovpn.conf
  36. echo -e "LegacySigningMDs md2 md5\nMinimumDHBits 512\n" >> /etc/pki/tls/legacy-settings
  37. exec "/usr/sbin/openvpn" "--config" "/etc/openvpn/ovpn.conf" "$@"
  38. fi
  39. if [ ${mode} == "keygen" ]
  40. then
  41. echo "$SSHKEY" > /tmp/keyfile
  42. chmod 0400 /tmp/keyfile
  43. exec "$@"
  44. fi