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.

46 lines
1.5 KiB

  1. # -*- mode: shell-script -*-
  2. NTFY_CONFIGFILE="$SERVICE_CONFIGSTORE/etc/ntfy/server.yml"
  3. NTFY_FIREBASE_KEYFILE="$SERVICE_CONFIGSTORE/etc/ntfy/firebase-key.json"
  4. ntfy:init() {
  5. service_def=$(get_compose_service_def "$SERVICE_NAME")
  6. options=$(e "$service_def" | yq e '.options' -)
  7. mkdir -p "${NTFY_CONFIGFILE%/*}" || {
  8. err "failed to create directory ${NTFY_CONFIGFILE%/*}"
  9. exit 1
  10. }
  11. ## Ensure 'firebase-key-file' was not set in '$options'
  12. if yq e -e '.firebase-key-file' <<< "$options" >/dev/null; then
  13. err "${WHITE}firebase-key-file${NORMAL} should not be" \
  14. "specified in ${DARKYELLOW}$SERVICE_NAME${NORMAL}'s options"
  15. exit 1
  16. fi
  17. ## if 'firebase' is set
  18. if firebase_key=$(yq e -e '.firebase' 2>/dev/null <<< "$options"); then
  19. ## set 'firebase-key-file' in '$options'
  20. options=$(yq e '.firebase-key-file = "/etc/ntfy/firebase-key.json"' <<< "$options") || {
  21. err "failed to set firebase-key-file in options"
  22. exit 1
  23. }
  24. umask 077
  25. ## store content of $firebase_key in json format in '$NTFY_FIREBASE_KEYFILE'
  26. e "$firebase_key" | yq -p yaml -o json . > "$NTFY_FIREBASE_KEYFILE" || {
  27. err "failed to store firebase-key-file"
  28. exit 1
  29. }
  30. fi
  31. e "$options" > "$NTFY_CONFIGFILE" || {
  32. err "failed to store ntfy config"
  33. exit 1
  34. }
  35. }
  36. ntfy:config() {
  37. local cmd="$1"
  38. yq e "$1" -i "$NTFY_CONFIGFILE"
  39. }