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.

77 lines
2.4 KiB

  1. # -*- mode: shell-script -*-
  2. get_odoo_uid() {
  3. uid_label="odoo"
  4. odoo_uid=$(cached_cmd_on_base_image "$SERVICE_NAME" "id -u \"$uid_label\"") || {
  5. debug "Failed to query for '$uid_label' uid in ${DARKYELLOW}$SERVICE_NAME${NORMAL} base image."
  6. return 1
  7. }
  8. info "openerp uid from ${DARKYELLOW}$SERVICE_NAME${NORMAL} is '$odoo_uid'"
  9. echo "$odoo_uid"
  10. }
  11. sql() {
  12. local dbname="$1"
  13. (
  14. DBNAME="$(relation:get "$SERVICE_NAME":postgres-database dbname)" || return 1
  15. ts=$(service:traverse "$SERVICE_NAME":"postgres-database") || return 1
  16. export SERVICE_NAME="$ts"
  17. export SERVICE_DATASTORE="$DATASTORE/$SERVICE_NAME"
  18. target_charm=$(get_service_charm "$ts") || return 1
  19. target_charm_path=$(charm.get_dir "$target_charm") || return 1
  20. set +e
  21. . "$target_charm_path/lib/common"
  22. set -e
  23. metadata_service_def=$(_get_service_metadata "$ts") || return 1
  24. type=$(e "$metadata_service_def" | yq -r '.type') || true
  25. if [[ "$type" != "stub" ]]; then
  26. DOCKER_BASE_IMAGE=$(service_ensure_image_ready "$SERVICE_NAME") || return 1
  27. export DOCKER_BASE_IMAGE
  28. ensure_db_docker_running
  29. fi
  30. ddb "${dbname:-$DBNAME}"
  31. )
  32. }
  33. odoo:get-admin-password() {
  34. local service_def config admin_password
  35. service_def=$(get_compose_service_def "$SERVICE_NAME")
  36. config=$SERVICE_CONFIGSTORE/etc/odoo-server.conf
  37. admin_password=$(echo "$service_def" | shyaml -q get-value options.admin-password) || {
  38. if [ -e "$config" ]; then
  39. admin_password=$(grep ^admin_passwd "$config" | sed -r 's/^admin_passwd\s+=\s+(.+)$/\1/g')
  40. fi
  41. if [ -z "$admin_password" ]; then
  42. err "Could not find 'admin-password' in $SERVICE_NAME service definition nor in config file."
  43. return 1
  44. fi
  45. }
  46. echo "$admin_password"
  47. }
  48. ## XXXvlab: to include in `compose-core`
  49. get_running_container_for_service() {
  50. local containers service="$1"
  51. containers=($(get_running_containers_for_service "$service"))
  52. if [ "${#containers[@]}" == 0 ]; then
  53. err "No containers running for service $DARKYELLOW$service$NORMAL."
  54. return 1
  55. fi
  56. if [ "${#containers[@]}" -gt 1 ]; then
  57. err "More than 1 container running for service $DARKYELLOW$service$NORMAL."
  58. echo " Please contact administrator to fix this issue." >&2
  59. return 1
  60. fi
  61. echo "${containers[0]}"
  62. }