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.
 
 
 
 

67 regels
2.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. # Update a role on a remote node
  7. #
  8. # Usage:
  9. #
  10. # update_role domain role-dir
  11. #
  12. # domain : a bubble domain
  13. # role-dir : the role directory
  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_INCLUDE : path to look for JSON include files. default value is to assume we are being run from
  21. # bubble repo, bubble-models repo, or bubble-client and use include files from minimal model.
  22. #
  23. SCRIPT="${0}"
  24. SCRIPT_DIR=$(cd $(dirname ${SCRIPT}) && pwd)
  25. . ${SCRIPT_DIR}/bubble_common
  26. DOMAIN=${1:?no domain provided}
  27. ROLE_DIR="${2:?no role dir provided}"
  28. ROLE_TO_UPDATE="$(basename "${ROLE_DIR}")"
  29. ROLE_JSON="${ROLE_DIR}/files/bubble_role.json"
  30. if [[ ! -d "${ROLE_DIR}" ]] ; then
  31. die "Role dir does not exist or is not a directory: ${ROLE_DIR}"
  32. fi
  33. if [[ ! -f "${ROLE_DIR}/tasks/main.yml" ]] ; then
  34. die "Role dir is invalid (missing tasks/main.yml): ${ROLE_DIR}"
  35. fi
  36. if [[ ! -f "${ROLE_JSON}" ]] ; then
  37. die "Role json does not exist: ${ROLE_JSON}"
  38. fi
  39. role_json_name="$(cat ${ROLE_JSON} | jq -r .name)"
  40. if [[ -z "${role_json_name}" ]] ; then
  41. die "Role json does not have a name field"
  42. fi
  43. role_name="$(echo -n ${role_json_name} | cut -d- -f1)"
  44. if [[ "${role_name}" != "${ROLE_TO_UPDATE}" ]] ; then
  45. die "Role name in JSON (${role_name}) does not match dir basename: ${ROLE_DIR}"
  46. fi
  47. # update tgzB64 in JSON
  48. temp_tar_b64="$(mktemp /tmp/${role_name}.XXXXXXX.tgz.b64)"
  49. echo -n '"' > "${temp_tar_b64}"
  50. cd ${ROLE_DIR}/.. && tar cz $(basename ${ROLE_DIR}) | base64 -w0 >> ${temp_tar_b64} && cd - > /dev/null
  51. echo -n '"' >> "${temp_tar_b64}"
  52. ROLE_JSON="$(cat ${ROLE_JSON} | jq --argfile tgzB64 "${temp_tar_b64}" '. + {tgzB64: $tgzB64}')"
  53. rm -f "${temp_tar_b64}"
  54. #echo "${temp_tar_b64}"
  55. #exit 0
  56. echo "{\"domain\": \"${DOMAIN}\", \"update_role\": \"${ROLE_TO_UPDATE}\", \"role\": ${ROLE_JSON} }" | \
  57. exec ${SCRIPT_DIR}/bscript ${SCRIPT_DIR}/../scripts/update_role.json --vars -