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.
 
 

122 lines
2.2 KiB

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