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.
 
 
 
 

99 lines
3.0 KiB

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