wg-docker 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/bin/bash
  2. WG_DOCKER_PATH="/opt/wg-docker"
  3. cd $WG_DOCKER_PATH
  4. ls ./profiles || mkdir ./profiles
  5. # create profile
  6. [ -n $1 ] && [ -n $2 ] && \
  7. (ls ./profiles | grep $2) &&
  8. (ls ./profiles/$2/ || mkdir ./profiles/$2/) &&
  9. cp docker-compose.env.yml ./profiles/$2/ &&
  10. cp Makefile ./profiles/$2/ &&
  11. cp -r docker/ ./profiles/$2/ &&
  12. cd ./profiles/$2/ &&
  13. make $1 PROFILE="$2" ||
  14. (
  15. profile_name="test"
  16. wg_conf_path="/etc/wireguard/mullvad/mullvad-au1.conf"
  17. ssh_pubkey="$HOME/.ssh/id_rsa.pub"
  18. wg_port=52016
  19. socks_port=1116
  20. echo "
  21. usage: wg-docker [up|shell|firefox|thunderbird] [profile_name]
  22. Provide a profile name, and a valid WireGuard configuration file, and a public ssh key
  23. profile_name: Work
  24. wg_conf_path: /etc/wireguard/mullvad/mullvad-au1.conf
  25. ssh_pubkey: $HOME/.ssh/id_rsa.pub
  26. wg_port: 52000 [default]
  27. socks_port: 1100 [default]
  28. ######################
  29. "
  30. # comment out if manually entered
  31. read -p "profile_name : " profile_name
  32. read -p "wg_conf_path : " wg_conf_path
  33. read -p "ssh_pubkey : " ssh_pubkey
  34. read -p "wg_port : " wg_port
  35. read -p "socks_port : " socks_port
  36. profile_path="./profiles/${profile_name}_wg_${wg_port}_socks_${socks_port}"
  37. # Create a profile from template
  38. [ ! -d $profile_path ] && mkdir $profile_path || \
  39. touch $profile_path/.env
  40. # fill template
  41. cat << EOF >> $profile_path/.env
  42. # container wg
  43. CONTAINER_NAME=wg_${profile_name}
  44. WG_PORT=${wg_port}
  45. WG0_CONF=${wg_conf_path}
  46. # ssh socks
  47. SSH_PUBKEY=${ssh_pubkey}
  48. SOCKS_PORT=${socks_port}
  49. EOF
  50. echo "Profile enviroment created at $profile_path/.env"
  51. )