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.

75 lines
2.2 KiB

  1. APP_NAME=monujo
  2. VERSION=0.0.2
  3. SOURCE_URL="https://docker.0k.io/downloads/$APP_NAME-$VERSION.tar.bz2"
  4. LOCATION="$SERVICE_DATASTORE/opt/apps/$APP_NAME"
  5. CONFIGFILE="$LOCATION/config.json"
  6. monujo:code_init() {
  7. mkdir -p "$LOCATION"
  8. if dir_is_empty "$LOCATION"; then
  9. cd "$LOCATION"
  10. wget -q "$SOURCE_URL" -O file.tar.bz2
  11. tar xjf file.tar.bz2
  12. rm file.tar.bz2
  13. chown root:root "$LOCATION" -R
  14. fi
  15. }
  16. monujo:code_config_base() {
  17. MONUJO_OPTIONS=(
  18. lokapi-host:string
  19. lokapi-db:string
  20. map-url:string
  21. local-password-retention-time:string
  22. )
  23. MONUJO_OPTIONS_CONCAT=" ${MONUJO_OPTIONS[*]} "
  24. service_def=$(get_compose_service_def "$SERVICE_NAME") || return 1
  25. echo "{}" > "$CONFIGFILE"
  26. ## XXXvlab: Should probably offer some lib to do this
  27. while read-0 key val; do
  28. key_option=${key//-/_}
  29. case "$MONUJO_OPTIONS_CONCAT" in
  30. *" ${key_option}:bool "*)
  31. case "${val,,}" in
  32. true|ok|yes|y)
  33. val=yes
  34. ;;
  35. false|ko|nok|no|n)
  36. val=no
  37. ;;
  38. *)
  39. die "Invalid value for ${WHITE}$key$NORMAL, please use a boolean value."
  40. ;;
  41. esac
  42. ;;
  43. *" ${key_option}:numeric "*)
  44. if ! is_int "$val"; then
  45. die "Invalid value for ${WHITE}$key$NORMAL, please use numeric value."
  46. fi
  47. ;;
  48. *" ${key_option}:string "*)
  49. :
  50. ;;
  51. *)
  52. key_option=$(echo "$key_option" | sed 's/_\([a-z0-9]\)/\U\1/g')
  53. printf "%s %s\0" "$key_option" "$val"
  54. ;;
  55. esac
  56. done < <(printf "%s" "$service_def" | shyaml key-values-0 options) |
  57. jq -R 'split("\u0000") | map(split(" ") | {key: .[0], value: .[1]}) | from_entries' > \
  58. "$CONFIGFILE"
  59. }
  60. monujo:config_merge() {
  61. local old_config new_config="$1"
  62. old_config=$(cat "$CONFIGFILE")
  63. e "$old_config" "$new_config" | jq -s 'reduce .[] as $x ({}; . * $x)' > "$CONFIGFILE"
  64. }