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.
 
 

123 line
2.5 KiB

  1. #!/bin/bash
  2. # Feeds the upload queue with megawarcs.
  3. # (Needs a config.sh in the working directory.)
  4. #
  5. # ./pack-one
  6. #
  7. # 1. Grabs an item from PACKING_QUEUE_DIR
  8. # 2. Reserves the item by moving the directory to the
  9. # PACKER_WORKING_CHUNKS_DIR
  10. # 3. Makes a megawarc in the PACKER_WORKING_MEGAWARC_DIR
  11. # 4. Removes the source files from the working directory
  12. # 5. Moves the megawarc to the UPLOAD_QUEUE_DIR
  13. #
  14. # The program exits with 1 on any nontransient error.
  15. #
  16. WORKING_DIR="$( pwd )"
  17. SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
  18. MEGAWARC="${SCRIPT_DIR}/megawarc/megawarc"
  19. if [[ ! -x "${MEGAWARC}" ]]
  20. then
  21. echo "${MEGAWARC} does not exist or is not executable."
  22. exit 1
  23. fi
  24. source ./config.sh || exit 1
  25. mkdir -p "${PACKER_WORKING_CHUNKS_DIR}" || exit 1
  26. mkdir -p "${PACKER_WORKING_MEGAWARC_DIR}" || exit 1
  27. mkdir -p "${UPLOAD_QUEUE_DIR}" || exit 1
  28. function mayicontinue {
  29. echo
  30. # echo "May I continue?"
  31. # read
  32. # echo
  33. }
  34. # check if the upload queue is empty
  35. # if [ "$( ls -A ${UPLOAD_QUEUE_DIR} )" ]
  36. # then
  37. # echo "Upload queue not empty. Wait."
  38. # sleep 30
  39. # exit 0
  40. # fi
  41. mayicontinue
  42. # try to grab a directory from the packing queue
  43. ITEM=none
  44. while [[ "${ITEM}" = none ]]
  45. do
  46. possible_item=$( ls -1 "${PACKING_QUEUE_DIR}/" | grep -E '[0-9]{14}_[a-f0-9]{8}$' | sort | head -n 1 )
  47. if test -n "${possible_item}"
  48. then
  49. echo "Trying to grab ${possible_item}"
  50. if mv "${PACKING_QUEUE_DIR}/${possible_item}" "${PACKER_WORKING_CHUNKS_DIR}/"
  51. then
  52. ITEM="${possible_item}"
  53. else
  54. echo "Failed to move ${possible_item}"
  55. sleep 5
  56. fi
  57. else
  58. date
  59. echo "No current item found!"
  60. sleep 30
  61. exit 0
  62. fi
  63. done
  64. mayicontinue
  65. echo "$( date ): Starting megawarc for item ${ITEM}" >> packer.log
  66. # construct a megawarc
  67. mkdir -p "${PACKER_WORKING_MEGAWARC_DIR}/${ITEM}"
  68. # megawarcs use relative paths
  69. cd "${PACKER_WORKING_CHUNKS_DIR}/"
  70. "${MEGAWARC}" --verbose pack --server "${ZST_DICTIONARY_API}" "${PACKER_WORKING_MEGAWARC_DIR}/${ITEM}/${FILE_PREFIX}${ITEM}" "${ITEM}"
  71. result="${?}"
  72. cd "${WORKING_DIR}"
  73. if [[ "${result}" -ne 0 ]]
  74. then
  75. date
  76. echo "megawarc exited with ${result} for ${ITEM}"
  77. exit 1
  78. fi
  79. echo "$( date ): Completed megawarc for item ${ITEM}" >> packer.log
  80. mayicontinue
  81. # remove files
  82. echo "megawarc OK, removing source files"
  83. rm -rf "${PACKER_WORKING_CHUNKS_DIR}/${ITEM}"
  84. result="${?}"
  85. if [[ "${result}" -ne 0 ]]
  86. then
  87. date
  88. echo "rm -rf source files exited with ${result} for ${ITEM}"
  89. exit 1
  90. fi
  91. echo "add to upload queue"
  92. mv "${PACKER_WORKING_MEGAWARC_DIR}/${ITEM}" "${UPLOAD_QUEUE_DIR}/"
  93. exit 0