download_and_untar.sh 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #!/bin/bash
  2. # Copyright 2014 Johns Hopkins University (author: Daniel Povey)
  3. # Apache 2.0
  4. remove_archive=false
  5. if [ "$1" == --remove-archive ]; then
  6. remove_archive=true
  7. shift
  8. fi
  9. if [ $# -ne 3 ]; then
  10. echo "Usage: $0 [--remove-archive] <data-base> <url-base> <corpus-part>"
  11. echo "e.g.: $0 /export/a15/vpanayotov/data www.openslr.org/resources/11 dev-clean"
  12. echo "With --remove-archive it will remove the archive after successfully un-tarring it."
  13. echo "<corpus-part> can be one of: dev-clean, test-clean, dev-other, test-other,"
  14. echo " train-clean-100, train-clean-360, train-other-500."
  15. exit 1
  16. fi
  17. data=$1
  18. url=$2
  19. part=$3
  20. if [ ! -d "$data" ]; then
  21. echo "$0: no such directory $data"
  22. exit 1
  23. fi
  24. part_ok=false
  25. list="dev-clean test-clean dev-other test-other train-clean-100 train-clean-360 train-other-500"
  26. for x in $list; do
  27. if [ "$part" == $x ]; then part_ok=true; fi
  28. done
  29. if ! $part_ok; then
  30. echo "$0: expected <corpus-part> to be one of $list, but got '$part'"
  31. exit 1
  32. fi
  33. if [ -z "$url" ]; then
  34. echo "$0: empty URL base."
  35. exit 1
  36. fi
  37. if [ -f $data/LibriTTS/$part/.complete ]; then
  38. echo "$0: data part $part was already successfully extracted, nothing to do."
  39. exit 0
  40. fi
  41. # sizes of the archive files in bytes. This is some older versions.
  42. sizes_old="371012589 347390293 379743611 361838298 6420417880 23082659865 30626749128"
  43. # sizes_new is the archive file sizes of the final release. Some of these sizes are of
  44. # things we probably won't download.
  45. sizes_new="337926286 314305928 695964615 297279345 87960560420 33373768 346663984 328757843 6387309499 23049477885 30593501606"
  46. if [ -f $data/$part.tar.gz ]; then
  47. size=$(/bin/ls -l $data/$part.tar.gz | awk '{print $5}')
  48. size_ok=false
  49. for s in $sizes_old $sizes_new; do if [ $s == $size ]; then size_ok=true; fi; done
  50. if ! $size_ok; then
  51. echo "$0: removing existing file $data/$part.tar.gz because its size in bytes $size"
  52. echo "does not equal the size of one of the archives."
  53. rm $data/$part.tar.gz
  54. else
  55. echo "$data/$part.tar.gz exists and appears to be complete."
  56. fi
  57. fi
  58. if [ ! -f $data/$part.tar.gz ]; then
  59. if ! which wget >/dev/null; then
  60. echo "$0: wget is not installed."
  61. exit 1
  62. fi
  63. full_url=$url/$part.tar.gz
  64. echo "$0: downloading data from $full_url. This may take some time, please be patient."
  65. if ! wget -P $data --no-check-certificate $full_url; then
  66. echo "$0: error executing wget $full_url"
  67. exit 1
  68. fi
  69. fi
  70. if ! tar -C $data -xvzf $data/$part.tar.gz; then
  71. echo "$0: error un-tarring archive $data/$part.tar.gz"
  72. exit 1
  73. fi
  74. touch $data/LibriTTS/$part/.complete
  75. echo "$0: Successfully downloaded and un-tarred $data/$part.tar.gz"
  76. if $remove_archive; then
  77. echo "$0: removing $data/$part.tar.gz file since --remove-archive option was supplied."
  78. rm $data/$part.tar.gz
  79. fi