folderFixup.sh 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 we're already running
  28. LOCK="${TMPDIR}/folderFixup.run"
  29. touch "${LOCK}"
  30. read MOUNT_PID < "${LOCK}"
  31. if [ -n "${MOUNT_PID}" ]; then
  32. if ps -A -o pid | grep -q "${MOUNT_PID}"; then
  33. if [ -n "${DEBUG}" ] && [ $DEBUG -gt 0 ]; then
  34. echo 'Already running' 1>&2
  35. fi
  36. exit 0
  37. fi
  38. fi
  39. echo $$ > "${LOCK}"
  40. # Bail if the load is high
  41. if ! ~/bin/video/checkLoad.sh; then
  42. if [ -n "${DEBUG}" ] && [ $DEBUG -gt 0 ]; then
  43. echo 'Load too high' 1>&2
  44. fi
  45. exit 0
  46. fi
  47. # Bail if the media share isn't available
  48. if ! ~/bin/video/isMediaMounted; then
  49. echo 'Media not mounted' 1>&2
  50. exit 1
  51. fi
  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 "^cp: .*: could not copy extended attributes to .*: Operation not permitted$" | \
  59. grep -v "GetFileInfo: could not get info about file (-1401)" | \
  60. grep -v "ERROR: Unexpected Error. (-1401) on file: " | \
  61. grep -v "ERROR: Unexpected Error. (-5000) on file: " | \
  62. grep -v "^ *$"
  63. # Cleanup
  64. rm -f "${LOCK}"
  65. rm -rf "${tmp}"
  66. # Debug
  67. if [ -n "${DEBUG}" ] && [ $DEBUG -gt 0 ]; then
  68. echo -n 'Complete: '
  69. date
  70. fi