The main Bubble source repository. Contains the Bubble API server, the web UI, documentation and utilities. https://getbubblenow.com
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.
 
 
 
 

102 line
3.2 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. #
  6. # Bubble client script. Wraps the run.sh script.
  7. #
  8. # Usually not called directly, instead use one of the higher-level wrappers: sync-model, run-script
  9. #
  10. # Usage: bubble command [args]
  11. #
  12. # command : one of the Bubble CLI commands. Find the full list of commands in BubbleMain.java
  13. # args : depends on the command, usually -h / --help will show command help
  14. #
  15. # Environment variables
  16. #
  17. # BUBBLE_API : which API to use. Default is local (http://127.0.0.1:PORT, where PORT is found in .bubble.env)
  18. # BUBBLE_USER : account to use. Default is root
  19. # BUBBLE_PASS : password for account. Default is root
  20. # BUBBLE_ENV : env file to load. Default is ~/.bubble.env or /home/bubble/api/bubble.env (whichever is found first)
  21. # DEBUG_PORT : if set, this is the port number the client will wait for a debugger to attach before starting
  22. # BUBBLE_INCLUDE : when using the sync-model and run-script commands, this is the directory to find included files
  23. # For sync-model and migrate-model, the default is the current directory.
  24. # For run-script, the default is a directory named "tests" within the current directory
  25. # BUBBLE_SCRIPTS : location of run.sh script. Default is to assume it is in the same directory containing this script
  26. #
  27. SCRIPT="${0}"
  28. SCRIPT_DIR=$(cd $(dirname ${SCRIPT}) && pwd)
  29. . ${SCRIPT_DIR}/bubble_common
  30. function is_api_command {
  31. case "${1}" in
  32. -h|--help)
  33. echo "0"
  34. ;;
  35. *)
  36. echo "1"
  37. ;;
  38. esac
  39. }
  40. if [[ -z "${DEBUG_PORT}" ]] ; then
  41. debug=""
  42. else
  43. debug="debug ${DEBUG_PORT}"
  44. fi
  45. if [[ -z "${1}" ]] ; then
  46. COMMAND="-h"
  47. else
  48. COMMAND="${1}"
  49. shift
  50. fi
  51. # always send help commands through
  52. last_arg="$(echo "${@}" | awk '{print $NF}')"
  53. is_help=0
  54. if [[ ! -z "${last_arg}" && ( "${last_arg}" == "-h" || "${last_arg}" == "--help" ) ]] ; then
  55. is_help=1
  56. fi
  57. if [[ -z "${BUBBLE_ENV}" ]] ; then
  58. if [[ -f "${HOME}/.bubble.env" ]] ; then
  59. BUBBLE_ENV="${HOME}/.bubble.env"
  60. elif [[ -f "/home/bubble/api/bubble.env" ]] ; then
  61. BUBBLE_ENV="/home/bubble/api/bubble.env"
  62. else
  63. die "bubble environment file not found"
  64. fi
  65. fi
  66. if [[ -z "${BUBBLE_API}" ]] ; then
  67. if [[ "$(is_api_command ${COMMAND})" == "1" && is_help -eq 0 ]] ; then
  68. BUBBLE_API=local
  69. fi
  70. fi
  71. if [[ "${BUBBLE_API}" == "local" ]] ; then
  72. if [[ -z "${BUBBLE_PORT}" ]] ; then
  73. BUBBLE_PORT="$(cat ${BUBBLE_ENV} | egrep -v '\s*#' | grep BUBBLE_SERVER_PORT | awk -F '=' '{print $NF}' | tr -d "'" | tr -d '"')"
  74. if [[ -z "${BUBBLE_PORT}" ]] ; then
  75. die "Error reading BUBBLE_SERVER_PORT from ${BUBBLE_ENV}"
  76. fi
  77. fi
  78. BUBBLE_API="http://127.0.0.1:${BUBBLE_PORT}/api"
  79. fi
  80. if [[ -z "${BUBBLE_INCLUDE}" ]] ; then
  81. if [[ "${COMMAND}" == "sync-model" ]] ; then
  82. BUBBLE_INCLUDE="$(pwd)"
  83. elif [[ "${COMMAND}" == "script" ]] ; then
  84. BUBBLE_INCLUDE="$(pwd)/tests"
  85. else
  86. BUBBLE_INCLUDE="$(pwd)"
  87. fi
  88. fi
  89. BUBBLE_PASS=${BUBBLE_PASS} \
  90. BUBBLE_USER=${BUBBLE_USER} \
  91. BUBBLE_API=${BUBBLE_API} \
  92. BUBBLE_INCLUDE=${BUBBLE_INCLUDE} \
  93. exec ${BUBBLE_SCRIPTS}/run.sh ${debug} ${COMMAND} "${@}"