config.sh 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #!/usr/bin/env bash
  2. shopt -s nullglob
  3. ###
  4. # Check if current user is root
  5. #
  6. ##
  7. function rootCheck() {
  8. # Root check
  9. if [ "$(/usr/bin/whoami)" != "root" ]; then
  10. echo "[ERROR] $* must be run as root"
  11. exit 1
  12. fi
  13. }
  14. ###
  15. # Create /docker.stdout and /docker.stderr
  16. #
  17. ##
  18. function createDockerStdoutStderr() {
  19. # link stdout from docker
  20. if [[ -n "$LOG_STDOUT" ]]; then
  21. echo "Log stdout redirected to $LOG_STDOUT"
  22. else
  23. LOG_STDOUT="/proc/$$/fd/1"
  24. fi
  25. if [[ -n "$LOG_STDERR" ]]; then
  26. echo "Log stderr redirected to $LOG_STDERR"
  27. else
  28. LOG_STDERR="/proc/$$/fd/2"
  29. fi
  30. ln -f -s "$LOG_STDOUT" /docker.stdout
  31. ln -f -s "$LOG_STDERR" /docker.stderr
  32. }
  33. ###
  34. # Include script directory text inside a file
  35. #
  36. # $1 -> path
  37. #
  38. ##
  39. function includeScriptDir() {
  40. if [[ -d "$1" ]]; then
  41. for FILE in "$1"/*.sh; do
  42. echo "-> Executing ${FILE}"
  43. # run custom scripts, only once
  44. . "$FILE"
  45. done
  46. fi
  47. }
  48. ###
  49. # Show deprecation notice
  50. #
  51. ##
  52. function deprecationNotice() {
  53. echo ""
  54. echo "###############################################################################"
  55. echo "### THIS CALL IS DEPRECATED AND WILL BE REMOVED IN THE FUTURE"
  56. echo "###"
  57. echo "### $*"
  58. echo "###"
  59. echo "###############################################################################"
  60. echo ""
  61. }
  62. ###
  63. # Run "entrypoint" scripts
  64. ##
  65. function runEntrypoints() {
  66. ###############
  67. # Try to find entrypoint
  68. ###############
  69. ENTRYPOINT_SCRIPT="/opt/docker/bin/entrypoint.d/${TASK}.sh"
  70. if [ -f "$ENTRYPOINT_SCRIPT" ]; then
  71. . "$ENTRYPOINT_SCRIPT"
  72. fi
  73. ###############
  74. # Run default
  75. ###############
  76. if [ -f "/opt/docker/bin/entrypoint.d/default.sh" ]; then
  77. . /opt/docker/bin/entrypoint.d/default.sh
  78. fi
  79. exit 1
  80. }
  81. # Run "entrypoint" provisioning
  82. ##
  83. function runProvisionEntrypoint() {
  84. includeScriptDir "/opt/docker/provision/entrypoint.d"
  85. includeScriptDir "/entrypoint.d"
  86. }
  87. ###
  88. # List environment variables (based on prefix)
  89. ##
  90. function envListVars() {
  91. if [[ $# -eq 1 ]]; then
  92. env | grep "^${1}" | cut -d= -f1
  93. else
  94. env | cut -d= -f1
  95. fi
  96. }
  97. ###
  98. # Get environment variable (even with dots in name)
  99. #
  100. ##
  101. function envGetValue() {
  102. awk "BEGIN {print ENVIRON[\"$1\"]}"
  103. }