The main Bubble source repository. Contains the Bubble API server, the web UI, documentation and utilities. https://getbubblenow.com
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 

132 Zeilen
4.0 KiB

  1. #!/bin/bash
  2. #
  3. # Copyright (c) 2020 Bubble, Inc. All rights reserved. For personal (non-commercial) use, see license: https://getbubblenow.com/bubble-license/
  4. #
  5. # Utility functions and standard pre-processing for many bubble CLI commands.
  6. #
  7. function die() {
  8. if [[ -z "${SCRIPT}" ]]; then
  9. echo 1>&2 "${1}"
  10. else
  11. echo 1>&2 "${SCRIPT}: ${1}"
  12. fi
  13. exit 1
  14. }
  15. function handle_help_request() {
  16. if [[ -z "${2}" ]]; then
  17. return
  18. fi
  19. if [[ ${2} == "-h" || ${2} == "--help" ]]; then
  20. while IFS='' read -r line || [[ -n "$line" ]]; do
  21. if [[ ${line} =~ ^#.* ]]; then
  22. if [[ ! ${line} =~ ^#!/bin/bash.* ]]; then
  23. echo "${line}"
  24. fi
  25. else
  26. break
  27. fi
  28. done <"${1}"
  29. exit 1
  30. fi
  31. }
  32. # Validate that argument is "hostname" or "user@hostname"
  33. # Validate that user (if present) is valid username and hostname not invalid
  34. # Does not perform a full RFC-compliant check, just some basics
  35. function validate_user_at_host() {
  36. HOST="${1}"
  37. if [[ -z "$(echo "${HOST}" | grep '@')" ]] ; then
  38. if [[ $(echo "${HOST}" | tr -cd '[:alnum:].-' | wc -c) -ne ${#HOST} ]] ; then
  39. die "Invalid host: ${HOST}"
  40. fi
  41. else
  42. USER_PART="$(echo "${HOST}" | awk -F '@' '{print $1}')"
  43. HOST_PART="$(echo "${HOST}" | awk -F '@' '{print $2}')"
  44. if [[ $(echo "${USER_PART}" | tr -cd '[:alnum:].-' | wc -c) -ne ${#USER_PART} ]] ; then
  45. die "Invalid user: ${USER_PART}"
  46. elif [[ $(echo "${HOST_PART}" | tr -cd '[:alnum:].-' | wc -c) -ne ${#HOST_PART} ]] ; then
  47. die "Invalid host: ${HOST_PART}"
  48. fi
  49. fi
  50. }
  51. function make_temp() {
  52. prefix="${1}"
  53. suffix="${2}"
  54. echo "$(mktemp ${prefix}.${suffix}.XXXXXXXX)"
  55. }
  56. function make_temp_dir() {
  57. prefix="${1}"
  58. suffix="${2}"
  59. echo "$(mktemp -d ${prefix}.${suffix}.XXXXXXXX)"
  60. }
  61. function quote_args() {
  62. args=""
  63. for i in "$@"; do
  64. if [[ "$i" =~ \ |\' ]]; then
  65. i="${i//\\/\\\\}"
  66. args="$args \"${i//\"/\\\"}\""
  67. else
  68. args="$args ${i}"
  69. fi
  70. done
  71. echo -n ${args}
  72. }
  73. handle_help_request "${0}" "${1}"
  74. # Ensure we can find run.sh
  75. if [[ -z "${BUBBLE_SCRIPTS}" ]] ; then
  76. BC_DIR="$(cd "$(dirname "${0}")" && pwd)"
  77. RUN_SH="$(find "${BC_DIR}" -type f -name "run.sh" | head -1)"
  78. if [[ -z "${RUN_SH}" ]] ; then
  79. RUN_SH="$(find . -type f -name "run.sh" | head -1)"
  80. fi
  81. if [[ -z "${RUN_SH}" ]] ; then
  82. RUN_SH="$(find ${BC_DIR}/../../bubble -type f -name "run.sh" | head -1)"
  83. fi
  84. if [[ -z "${RUN_SH}" ]] ; then
  85. die "run.sh script not found. Set BUBBLE_SCRIPTS to be the directory containing run.sh"
  86. fi
  87. BUBBLE_SCRIPTS="$(dirname "${RUN_SH}")"
  88. elif [[ ! -f "${BUBBLE_SCRIPTS}/run.sh" ]] ; then
  89. die "run.sh script not found in BUBBLE_SCRIPTS dir (${BUBBLE_SCRIPTS})"
  90. fi
  91. if [[ -z "${BUBBLE_JAR}" ]] ; then
  92. if [[ -f "${HOME}/api/bubble.jar" ]] ; then
  93. BUBBLE_JAR="${HOME}/api/bubble.jar"
  94. elif [[ -f "/home/bubble/api/bubble.jar" ]] ; then
  95. BUBBLE_JAR="/home/bubble/api/bubble.jar"
  96. elif [[ -f "${BUBBLE_SCRIPTS}/../bubble.jar" ]] ; then
  97. BUBBLE_JAR="${BUBBLE_SCRIPTS}/../bubble.jar"
  98. else
  99. BUBBLE_JAR="$(find "${BUBBLE_SCRIPTS}/../bubble-server/target" -type f -name "bubble*.jar" | head -1)"
  100. if [[ -n "${BUBBLE_JAR}" ]] ; then
  101. # Use full jar if available. Client libraries like to have the JS engine for example. This is stripped from the server.
  102. BUBBLE_FULL_JAR="$(find "${BUBBLE_SCRIPTS}/../bubble-server/target" -type f -name "bubble*-full.jar" | head -1)"
  103. if [[ -n "${BUBBLE_FULL_JAR}" ]] ; then
  104. BUBBLE_JAR="${BUBBLE_FULL_JAR}"
  105. fi
  106. fi
  107. fi
  108. fi
  109. if [[ -z "${BUBBLE_JAR}" ]] ; then
  110. echo 1>&2 "warning: bubble jar could not be located"
  111. fi
  112. # Check to see if we are on the PATH, if not suggest that we could be
  113. BUBBLE_BIN="$(cd "$(dirname "${0}")" && pwd)"
  114. if [[ -z "${BUBBLE_SKIP_PATH_WARNING}" && -z "$(which "$(basename "${0}")")" ]] ; then
  115. echo 1>&2 "Note: ${BUBBLE_BIN} is not on your PATH. To make things easier, add it to your PATH:"
  116. echo 1>&2 ""
  117. echo 1>&2 "export PATH=\${PATH}:${BUBBLE_BIN}"
  118. echo 1>&2 ""
  119. echo 1>&2 "(set BUBBLE_SKIP_PATH_WARNING to silence this warning)"
  120. export BUBBLE_SKIP_PATH_WARNING=1
  121. fi