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.

78 lines
1.6 KiB

  1. #!/bin/bash
  2. ## compose: no-hooks
  3. if [ -z "$SERVICE_DATASTORE" ]; then
  4. echo "This script is meant to be run through 'compose' to work properly." >&2
  5. exit 1
  6. fi
  7. version=0.1
  8. usage="$exname [-h|--help] [--force|-f] [DBNAME]"
  9. help="
  10. USAGE:
  11. $usage
  12. DESCRIPTION:
  13. Read stdin and send it to the restore API of odoo service to restore
  14. in the database DBNAME. If DBNAME is not provided, it'll take the
  15. default odoo database from the ${DARKCYAN}postgres-database${NORMAL} relation of
  16. current service.
  17. EXAMPLES:
  18. $exname < dump.zip
  19. $exname odoo2 < odoo2.zip
  20. "
  21. dbname=
  22. neutralize=
  23. while [ "$1" ]; do
  24. case "$1" in
  25. "--help"|"-h")
  26. print_help >&2
  27. exit 0
  28. ;;
  29. "--neutralize"|"-n")
  30. neutralize=yes
  31. ;;
  32. "--force"|"-f")
  33. force=yes
  34. ;;
  35. --*|-*)
  36. err "Unexpected optional argument '$1'"
  37. print_usage >&2
  38. exit 1
  39. ;;
  40. *)
  41. [ -z "$dbname" ] && { dbname=$1 ; shift ; continue ; }
  42. err "Unexpected positional argument '$1'"
  43. print_usage >&2
  44. exit 1
  45. ;;
  46. esac
  47. shift
  48. done
  49. version:ge() { [ "$(printf '%s\n' "$@" | sort -rV | head -n 1)" == "$1" ]; }
  50. version:lt() { ! version:ge "$@"; }
  51. if [ -z "$dbname" ]; then
  52. dbname=$(relation:get "$SERVICE_NAME:postgres-database" dbname) || {
  53. err "Couldn't retrieve information of" \
  54. "${DARKYELLOW}$SERVICE_NAME${NORMAL}-->${DARKCYAN}postgres-database${NORMAL}."
  55. exit 1
  56. }
  57. fi
  58. . "$CHARM_PATH/lib/common"
  59. set -e
  60. odoo:load "$dbname" "$neutralize"