functions 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/usr/bin/env bash
  2. set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
  3. source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
  4. source "$PLUGIN_AVAILABLE_PATH/nginx-vhosts/functions"
  5. robots_txt_build_config() {
  6. local APP="$1"; verify_app_name "$APP"
  7. local NGINX_TEMPLATE="$PLUGIN_AVAILABLE_PATH/robots.txt/templates/robots-txt.conf.sigil"
  8. local ROBOTS_TXT_TEMPLATE="$PLUGIN_AVAILABLE_PATH/robots.txt/templates/robots.txt.sigil"
  9. local TMP_WORK_DIR=$(mktemp -d /tmp/dokku_robots.txt.XXXXX)
  10. local NGINX_CONF=$(mktemp --tmpdir="${TMP_WORK_DIR}" "robots-txt.conf.XXXXXX")
  11. local ROBOTS_TXT=$(mktemp --tmpdir="${TMP_WORK_DIR}" "robots.txt.XXXXXX")
  12. # Setup
  13. mkdir -p "$DOKKU_ROOT/$APP/nginx.conf.d/"
  14. chown dokku:dokku "$DOKKU_ROOT/$APP/nginx.conf.d/"
  15. # Create Nginx conf
  16. local NGINX_SIGIL_PARAMS=(-f $NGINX_TEMPLATE APP="$APP" DOKKU_ROOT="$DOKKU_ROOT")
  17. dokku_log_info1 "Creating robots.txt Nginx conf"
  18. sigil "${NGINX_SIGIL_PARAMS[@]}" | cat -s > "$NGINX_CONF"
  19. cp "$NGINX_CONF" "$DOKKU_ROOT/$APP/nginx.conf.d/robots-txt.conf"
  20. # Create robots.txt
  21. local ROBOTS_TXT_SIGIL_PARAMS=(-f $ROBOTS_TXT_TEMPLATE APP="$APP" DOKKU_ROOT="$DOKKU_ROOT" ROBOTS_TXT_DISALLOW="$2")
  22. dokku_log_info1 "Creating robots.txt"
  23. sigil "${ROBOTS_TXT_SIGIL_PARAMS[@]}" | cat -s > "$ROBOTS_TXT"
  24. cp "$ROBOTS_TXT" "$DOKKU_ROOT/$APP/robots.txt"
  25. # Set permissions
  26. chmod +r "$DOKKU_ROOT/$APP/nginx.conf.d/robots-txt.conf"
  27. chmod +r "$DOKKU_ROOT/$APP/robots.txt"
  28. if (is_deployed "$APP"); then
  29. dokku_log_verbose "Reloading nginx"
  30. validate_nginx && restart_nginx
  31. fi
  32. dokku_log_info1 "Finished"
  33. }