jw项目windows环境软件安装
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.8 KiB

1 year ago
  1. #!/bin/bash
  2. set -e -o pipefail
  3. # Allow environment variables to be set by creating a file with the
  4. # contents, and setting an environment variable with the suffix _FILE to
  5. # point to it. This can be used to provide secrets to a container, without
  6. # the values being specified explicitly when running the container.
  7. #
  8. # Note that only supported environment variables are processed, in order
  9. # to avoid unexpected failures when an environment sets a "*_FILE" variable
  10. # that doesn't contain a filename.
  11. #
  12. # This script is intended to be sourced, not executed, and modifies the
  13. # environment.
  14. for VAR_NAME_FILE in ELASTIC_PASSWORD_FILE KEYSTORE_PASSWORD_FILE ; do
  15. if [[ -n "${!VAR_NAME_FILE}" ]]; then
  16. VAR_NAME="${VAR_NAME_FILE%_FILE}"
  17. if env | grep "^${VAR_NAME}="; then
  18. echo "ERROR: Both $VAR_NAME_FILE and $VAR_NAME are set. These are mutually exclusive." >&2
  19. exit 1
  20. fi
  21. if [[ ! -e "${!VAR_NAME_FILE}" ]]; then
  22. echo "ERROR: File ${!VAR_NAME_FILE} from $VAR_NAME_FILE does not exist" >&2
  23. exit 1
  24. fi
  25. FILE_PERMS="$(stat -L -c '%a' ${!VAR_NAME_FILE})"
  26. if [[ "$FILE_PERMS" != "400" && "$FILE_PERMS" != "600" ]]; then
  27. if [[ -h "${!VAR_NAME_FILE}" ]]; then
  28. echo "ERROR: File $(readlink "${!VAR_NAME_FILE}") (target of symlink ${!VAR_NAME_FILE} from $VAR_NAME_FILE) must have file permissions 400 or 600, but actually has: $FILE_PERMS" >&2
  29. else
  30. echo "ERROR: File ${!VAR_NAME_FILE} from $VAR_NAME_FILE must have file permissions 400 or 600, but actually has: $FILE_PERMS" >&2
  31. fi
  32. exit 1
  33. fi
  34. echo "Setting $VAR_NAME from $VAR_NAME_FILE at ${!VAR_NAME_FILE}" >&2
  35. export "$VAR_NAME"="$(cat ${!VAR_NAME_FILE})"
  36. unset VAR_NAME
  37. # Unset the suffixed environment variable
  38. unset "$VAR_NAME_FILE"
  39. fi
  40. done