docker_entrypoint.sh 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/bin/sh
  2. USER="admin"
  3. MM=$(pwgen -1s)
  4. CREATE_USER=1
  5. CONFIG_FILE='/app/conf/server.toml'
  6. if [ $CREATE_USER -eq 1 ]; then
  7. if [ ! -e $CREATE_USER ]; then
  8. MM=$(pwgen -1s)
  9. touch $CREATE_USER
  10. bash /app/generate-certs.sh
  11. cd /app/conf/ && cp *.crt /usr/local/share/ca-certificates/
  12. update-ca-certificates --fresh
  13. userpass=$(/app/anylink -passwd "${MM}"| cut -d : -f2)
  14. echo "${userpass}"
  15. jwttoken=$(/app/anylink -secret | cut -d : -f2)
  16. echo "-- First container startup --user:${USER} pwd:${MM}"
  17. sed -i "s/admin/${USER}/g" /app/server-example.toml
  18. sed -i "s/123456/${MM}/g" /app/server-example.toml
  19. sed -i "s#usertoken#${userpass}#g" /app/server-example.toml
  20. sed -i "s/jwttoken/${jwttoken}/g" /app/server-example.toml
  21. else
  22. echo "-- Not first container startup --"
  23. fi
  24. else
  25. echo "user switch not create"
  26. fi
  27. if [ ! -f $CONFIG_FILE ]; then
  28. echo "#####Generating configuration file#####"
  29. cp /app/server-example.toml /app/conf/server.toml
  30. else
  31. echo "#####Configuration file already exists#####"
  32. fi
  33. rtaddr=$(grep "cidr" /app/conf/server.toml |awk -F \" '{print $2}')
  34. sysctl -w net.ipv4.ip_forward=1
  35. iptables -t nat -A POSTROUTING -s "${rtaddr}" -o eth0+ -j MASQUERADE
  36. /app/anylink -conf="/app/conf/server.toml"