download_repos.sh 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #!/bin/bash
  2. # Copyright (C) 2013 Tomasz Olszak <olszak.tomasz@gmail.com>
  3. # All rights reserved.
  4. # Redistribution and use in source and binary forms, with or without
  5. # modification, are permitted provided that the following conditions
  6. # are met:
  7. # 1. Redistributions of source code must retain the copyright
  8. # notice, this list of conditions and the following disclaimer.
  9. # 2. Redistributions in binary form must reproduce the copyright
  10. # notice, this list of conditions and the following disclaimer in the
  11. # documentation and/or other materials provided with the distribution.
  12. # 3. The name of the author may not be used to endorse or promote products
  13. # derived from this software without specific prior written permission.
  14. #
  15. # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  16. # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  17. # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  18. # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  19. # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  20. # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  21. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  22. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  23. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  24. # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. #
  26. set -e
  27. if [ -z "$TIZEN_VERSION" -o -z "$CROSS_COMPILE_FOR" ]; then
  28. echo "download_repos: Unset obligatory variables: TIZEN_VERSION, CROSS_COMPILE_FOR"
  29. exit 1
  30. fi
  31. if [ "$CROSS_COMPILE_FOR" == "emulator" ]; then
  32. SIZE_IN_MB=827
  33. TARGET_NAME=$TIZEN_VERSION-emul
  34. base_packages_url=http://download.tizen.org/snapshots/$TARGET_NAME/common/latest/repos/tizen-base/ia32/packages
  35. main_packages_url=http://download.tizen.org/snapshots/$TARGET_NAME/common/latest/repos/tizen-main/ia32/packages
  36. base_parts="i586 i686 noarch repodata"
  37. main_parts="i586 noarch repodata"
  38. else
  39. SIZE_IN_MB=839
  40. TARGET_NAME=$TIZEN_VERSION
  41. base_packages_url=http://download.tizen.org/snapshots/$TARGET_NAME/common/latest/repos/tizen-base/armv7l/packages
  42. main_packages_url=http://download.tizen.org/snapshots/$TARGET_NAME/common/latest/repos/tizen-main/armv7l/packages
  43. base_parts="armv7l noarch repodata"
  44. main_parts="armv7l noarch repodata"
  45. fi
  46. for part in $base_parts; do
  47. wget -qbN -r -l 1 $base_packages_url/$part
  48. done
  49. for part in $main_parts; do
  50. wget -qbN -r -l 1 $main_packages_url/$part
  51. done
  52. set +e
  53. count=0
  54. LAST_PERCENT=0
  55. while [ $(pgrep -c wget) -gt 0 ]; do
  56. if [ $(($count%5)) -eq 0 ]; then
  57. if [ -d download.tizen.org ]; then
  58. CUR_SIZE=$(du -sh download.tizen.org | grep -Eo "^[0-9]+")
  59. percentCompleted=$(echo "100.0 * $CUR_SIZE / $SIZE_IN_MB" | bc )
  60. if [ "$LAST_PERCENT" != "$percentCompleted" ]; then
  61. echo "Percent completed: $percentCompleted"
  62. LAST_PERCENT=$percentCompleted
  63. fi
  64. fi
  65. fi
  66. sleep 1
  67. (( count++ ))
  68. done
  69. set -e
  70. echo "Download finished!"
  71. find . -name 'index.html*' -exec rm {} +
  72. mkdir repos
  73. mv download.tizen.org/snapshots/$TARGET_NAME/common/latest/repos/tizen-* repos/
  74. rm -rf download.tizen.org
  75. echo "Tizen repositories ready"