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.

38 lines
997 B

  1. #!/bin/bash
  2. . lib/common
  3. set -e
  4. root_crontab="$SERVICE_CONFIGSTORE/etc/crontabs/root"
  5. cron_content=$(set -o pipefail; cron:entries | tr '\0' '\n') || {
  6. err "Failed to make cron entries" >&2
  7. exit 1
  8. }
  9. if [ -z "${cron_content::1}" ]; then
  10. err "Unexpected empty scheduled command list."
  11. exit 1
  12. fi
  13. if [ -e "$root_crontab" ]; then
  14. if ! [ -f "$root_crontab" ]; then
  15. err "Destination '$root_crontab' exists and is not a file."
  16. exit 1
  17. fi
  18. current_content=$(cat "$root_crontab")
  19. if [ "$current_content" = "$cron_content" ]; then
  20. info "Cron entry already up to date."
  21. exit 0
  22. fi
  23. fi
  24. if ! [ -d "${root_crontab%/*}" ]; then
  25. mkdir -p "${root_crontab%/*}"
  26. fi
  27. printf "%s\n" "$cron_content" > "$root_crontab"
  28. ## Busybox cron uses cron.update file to rescan new cron entries
  29. ## cf: https://git.busybox.net/busybox/tree/miscutils/crond.c#n1089
  30. touch "${root_crontab%/*}/cron.update"
  31. info "Cron entry updated ${GREEN}successfully${NORMAL}."