schedule.sh 938 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/bin/sh
  2. # https://mro.name/radio-privatkopie
  3. #
  4. set -e
  5. cd "$(dirname "${0}")/.." || exit 1
  6. [ -r "${1}.pending" ] && exit 0
  7. [ -r "${1}.ripping" ] && exit 0
  8. ls "${1}".??? >/dev/null 2>&1 && exit 0
  9. readonly bc="../stations/${1}.xml"
  10. readonly tmin_iso="$(grep -F " name=\"DC.format.timestart\"" "${bc}" | cut -d '"' -f 2)"
  11. readonly tmin_epo="$(date -d "${tmin_iso}" +'%s')"
  12. do_touch () {
  13. mkdir -p "$(dirname "${1}")" \
  14. && touch "${1}"
  15. }
  16. ls "../podcasts"/*/"${1}" >/dev/null 2>&1 \
  17. || do_touch "../podcasts/ad_hoc/${1}"
  18. sh "../podcasts/app/marker.sh" "${1}"
  19. rm "${1}.reserved" >/dev/null 2>&1 || true
  20. mkdir -p "$(dirname "${1}.pending")"
  21. readonly dt_s=$((tmin_epo - $(date +'%s') - 0))
  22. if [ 0 -gt $((dt_s)) ] ; then
  23. readonly dt_m=0
  24. else
  25. readonly dt_m=$((dt_s / 60))
  26. fi
  27. # how to report stderr to error.log?
  28. echo "sh app/record.sh ${1} 2>&1 | logger" \
  29. | at "now + $((dt_m)) minutes" 2>&1 \
  30. | tee "${1}.pending" \
  31. | logger