start.sh 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #/bin/sh
  2. if [ ! -f /usr/share/nginx/html/conf/config.js ]; then
  3. cp /app/conf/config.js /usr/share/nginx/html/conf
  4. fi
  5. if [ $API_URL ]; then
  6. echo "当前 API 地址为: $API_URL"
  7. sed -i "s#http://127.0.0.1:25500#$API_URL#g" /usr/share/nginx/html/conf/config.js
  8. else
  9. echo "当前为默认本地 API 地址: http://127.0.0.1:25500"
  10. echo "如需修改请在容器启动时使用 -e API_URL='https://sub.ops.ci' 传递环境变量"
  11. fi
  12. if [ $SHORT_URL ]; then
  13. echo "当前短链接地址为: $SHORT_URL"
  14. sed -i "s#https://s.ops.ci#$SHORT_URL#g" /usr/share/nginx/html/conf/config.js
  15. fi
  16. if [ $SITE_NAME ]; then
  17. sed -i "s#Subconverter Web#$SITE_NAME#g" /usr/share/nginx/html/conf/config.js
  18. fi
  19. nohup /base/subconverter & echo "启动成功"
  20. init_nginx (){
  21. sed -i '$d' /etc/nginx/conf.d/default.conf
  22. sed -i '$d' /etc/nginx/conf.d/default.conf
  23. sed -i '$d' /etc/nginx/conf.d/default.conf
  24. cat >> /etc/nginx/conf.d/default.conf <<EOF
  25. location ~* /(sub|render|getruleset|surge2clash|getprofile) {
  26. proxy_redirect off;
  27. proxy_pass http://127.0.0.1:25500;
  28. }
  29. }
  30. EOF
  31. }
  32. if [[ ! $(cat /etc/nginx/conf.d/default.conf | grep 25500) ]]; then
  33. init_nginx
  34. fi
  35. nginx -g "daemon off;"