folderFixup.sh 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #!/bin/bash
  2. # Parameters
  3. inFolder="`~/bin/video/mediaPath`/TV"
  4. # Debug
  5. if [ -n "${DEBUG}" ] && [ $DEBUG -gt 0 ]; then
  6. echo -n "Starting `basename "${0}"`: "
  7. date
  8. fi
  9. # Command line
  10. if [ -n "${1}" ]; then
  11. inFolder="${1}"
  12. fi
  13. if [ ! -e "${inFolder}" ]; then
  14. echo "Usage: `basename "${0}"` input_folder" 1>&2
  15. exit 1
  16. fi
  17. # Ensure we have a valid TMPDIR
  18. if [ ! -d "${TMPDIR}" ]; then
  19. TMPDIR="`getconf DARWIN_USER_TEMP_DIR 2>/dev/null`"
  20. if [ ! -d "${TMPDIR}" ]; then
  21. TMPDIR="/var/tmp"
  22. fi
  23. if [ ! -d "${TMPDIR}" ]; then
  24. TMPDIR="/tmp"
  25. fi
  26. fi
  27. # Bail if the media share isn't available
  28. if ! ~/bin/video/isMediaMounted; then
  29. echo 'Media not mounted' 1>&2
  30. exit 1
  31. fi
  32. # Bail if the load is high
  33. if ! ~/bin/video/checkLoad.sh; then
  34. if [ -n "${DEBUG}" ] && [ $DEBUG -gt 0 ]; then
  35. echo 'Load too high' 1>&2
  36. fi
  37. exit 0
  38. fi
  39. # Bail if we're already running
  40. LOCK="${TMPDIR}/folderFixup.`basename "${inFolder}"`.run"
  41. touch "${LOCK}"
  42. read MOUNT_PID < "${LOCK}"
  43. if [ -n "${MOUNT_PID}" ]; then
  44. if ps -A -o pid | grep -q "${MOUNT_PID}"; then
  45. if [ -n "${DEBUG}" ] && [ $DEBUG -gt 0 ]; then
  46. echo 'Already running' 1>&2
  47. fi
  48. exit 0
  49. fi
  50. fi
  51. echo $$ > "${LOCK}"
  52. # Cache output
  53. tmp="`mktemp -t 'folderFixup.XXXXXXXX'`"
  54. # Re-wrap or recode as needed
  55. find "${inFolder}" -mindepth 1 -type d -exec ~/bin/video/folderToMKV.sh {} \; 1>>"${tmp}" 2>&1
  56. # Filter the output
  57. cat "${tmp}" | \
  58. grep -Ev "/update: Permission denied$" | \
  59. grep -Ev "/update.disabled: Permission denied$" | \
  60. grep -Ev "^cp: .*: could not copy extended attributes to .*: Operation not permitted$" | \
  61. grep -v "GetFileInfo: could not get info about file (-1401)" | \
  62. grep -v "ERROR: Unexpected Error. (-1401) on file: " | \
  63. grep -v "ERROR: Unexpected Error. (-5000) on file: " | \
  64. grep -v "^ *$"
  65. # Cleanup
  66. rm -f "${LOCK}"
  67. rm -rf "${tmp}"
  68. # Debug
  69. if [ -n "${DEBUG}" ] && [ $DEBUG -gt 0 ]; then
  70. echo -n 'Complete: '
  71. date
  72. fi