fork 0k-charms
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.

107 lines
2.8 KiB

  1. #!/bin/bash
  2. ## Init is run on host
  3. ## For now it is run every time the script is launched, but
  4. ## it should be launched only once after build.
  5. ## Accessible variables are:
  6. ## - SERVICE_NAME Name of current service
  7. ## - DOCKER_BASE_IMAGE Base image from which this service might be built if any
  8. ## - SERVICE_DATASTORE Location on host of the DATASTORE of this service
  9. ## - SERVICE_CONFIGSTORE Location on host of the CONFIGSTORE of this service
  10. LIB="$SERVICE_DATASTORE/var/lib/odoo"
  11. . lib/common
  12. set -e
  13. odoo_uid=$(get_odoo_uid)
  14. mkdir -p "$LIB"
  15. ## XXXvlab: this one can fail if files are removed (from sessions dir)
  16. find "$LIB" \! -user "$odoo_uid" -print0 | while read-0 f; do
  17. chown -v "$odoo_uid" "$f" || exit 1
  18. done
  19. ## workers management
  20. workers=$(options-get workers 2>/dev/null) || true
  21. workers=${workers:-1}
  22. modules=$(options-get modules 2>/dev/null | yaml_get_values ,) || true
  23. if [ -z "$modules" ]; then
  24. modules=base
  25. else
  26. modules="base,${modules}"
  27. fi
  28. cmd_args=()
  29. ## dbfilter management
  30. service_def=$(get_compose_service_def "$SERVICE_NAME") || return 1
  31. dbfilter=$(e "$service_def" | yq e -r=false '.options.dbfilter') || true
  32. if [ -n "$dbfilter" ]; then
  33. type=$(e "$dbfilter" | yq e "type")
  34. case "${type:2}" in
  35. str)
  36. dbfilter=$(e "$dbfilter" | yq e -o=json '.')
  37. cmd_args+=("--db-filter=${dbfilter}")
  38. ;;
  39. map)
  40. python_expr="["
  41. while read-0 key val; do
  42. [[ "$key" == "null" ]] && key="None"
  43. python_expr+="(${key//\$/\$\$}, ${val//\$/\$\$}),"
  44. done < <(e "$dbfilter" | yq -o=json -0 'to_entries | .[] | [.key, .value] | .[]')
  45. python_expr+="]"
  46. cmd_args+=("--db-filter=${python_expr}")
  47. ;;
  48. null)
  49. :
  50. ;;
  51. *)
  52. err "Invalid value for ${WHITE}dbfilter${NORMAL}: ${dbfilter}" >&2
  53. echo " It should be a string or a key/value mapping" >&2
  54. exit 1
  55. ;;
  56. esac
  57. fi
  58. ## config file
  59. conf=$(options-get conf 2>/dev/null) || true
  60. CONFIGFILE="$SERVICE_CONFIGSTORE/etc/odoo/tecnativa.conf"
  61. mkdir -p "${CONFIGFILE%/*}"
  62. while read-0 section section_def; do
  63. debug "'$section' '$section_def'"
  64. printf "[%s]\n" "$section"
  65. while read-0 key val; do
  66. debug "'$key' '$val'"
  67. key_option=${key//-/_}
  68. printf "%s=%s\n" "$key_option" "$val"
  69. done < <(e "$section_def" | shyaml key-values-0)
  70. done < <(e "$conf" | shyaml key-values-0) > "$CONFIGFILE"
  71. if [ -s "$CONFIGFILE" ]; then
  72. init-config-add "
  73. $SERVICE_NAME:
  74. volumes:
  75. - \"$CONFIGFILE:/opt/odoo/custom/conf.d/compose.conf:ro\"
  76. "
  77. fi
  78. init-config-add "
  79. $SERVICE_NAME:
  80. command:
  81. - \"--workers=${workers}\"
  82. - \"-i ${modules}\"
  83. $(
  84. for arg in "${cmd_args[@]}"; do
  85. echo " - |"
  86. e "$arg" | prefix " "
  87. done
  88. )
  89. "