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.
 
 
 
 

64 rivejä
2.1 KiB

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