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.

unix-get-dependencies.sh 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #! /bin/bash
  2. ## Get needed dependencies from cache or remote server and unzip into
  3. ## dest folder.
  4. #
  5. DEPENDENCIES="./tests-data.txt"
  6. CACHE_DIR="../dependencies/arch"
  7. if [ ! -z $DEPENDENCY_CACHE ]; then
  8. CACHE_DIR=$DEPENDENCY_CACHE
  9. fi
  10. OUTPUT_DIR="../dependencies"
  11. function usage () {
  12. cat <<EOF
  13. Usage: $0 --manifest dependencies-file --cache cache_folder [--out output-folder]
  14. [Options]
  15. --manifest: file listing dependencies
  16. --cache: dependency cache
  17. --out: output destination folder [default: ../dependencies]
  18. Example:
  19. $0 --manifest dependencies.txt --cache /media/dependencies
  20. EOF
  21. }
  22. while test -n "$1"; do
  23. case "$1" in
  24. --help)
  25. usage
  26. exit 0
  27. ;;
  28. -h)
  29. usage
  30. exit 0
  31. ;;
  32. --manifest)
  33. DEPENDENCIES=$2
  34. shift
  35. ;;
  36. --cache)
  37. CACHE_DIR=$2
  38. shift
  39. ;;
  40. --out)
  41. OUTPUT_DIR=$2
  42. shift
  43. ;;
  44. esac
  45. shift
  46. done
  47. if [ -z ${DEPENDENCIES} ] || [ -z ${CACHE_DIR} ]; then
  48. usage
  49. exit 1
  50. fi
  51. if [ -z ${DEPENDENCY_SERVER} ]; then
  52. echo "If your dependencies are not up-to-date, you won't be able to download new files."
  53. else
  54. echo "Download dependencies from server [$DEPENDENCY_SERVER]."
  55. fi
  56. if [ -z ${PROXYPASS} ]; then
  57. echo "Credentials were not provided. If your dependencies are not up-to-date, you won't be able to download new files."
  58. else
  59. user=`echo ${PROXYPASS} | cut -d ':' -f 1`
  60. pass=`echo ${PROXYPASS} | cut -d ':' -f 2`
  61. echo "Credentials are provided. Try to download from server with username [$user]."
  62. fi
  63. if [ ! -d ${CACHE_DIR} ]; then
  64. echo "${CACHE_DIR} does not exist"
  65. exit 2
  66. fi
  67. function get_dependency() {
  68. local _dep=$1
  69. if [ ! -f ${CACHE_DIR}/${_dep} ]; then
  70. echo "Download zip archive: [${DEPENDENCY_SERVER}/${_dep}]"
  71. wget --user=$user --password=$pass -nv -P ${CACHE_DIR}/${_dep%/*} ${DEPENDENCY_SERVER}/${_dep}
  72. fi
  73. }
  74. function install_dependency() {
  75. local _dep=$1 _dir=$2
  76. get_dependency ${_dep}
  77. echo "Unzip ${CACHE_DIR}/${_dep} to ${OUTPUT_DIR}/${_dir}"
  78. if [ ! -f ${CACHE_DIR}/${_dep} ]; then
  79. echo "Dependency ${_dep} does not exist in cache ${CACHE_DIR}"
  80. exit 3
  81. fi
  82. mkdir -p ${OUTPUT_DIR}/${_dir}
  83. unzip -q -o ${CACHE_DIR}/${_dep} -d ${OUTPUT_DIR}/${_dir}
  84. }
  85. mkdir -p ${OUTPUT_DIR}
  86. echo "Get and unzip dependencies. Read dependencies from manifest [$DEPENDENCIES]"
  87. cat ${DEPENDENCIES} | while read d; do
  88. dep=`echo $d | cut -d ';' -f 1`
  89. dir=`echo $d | cut -d ';' -f 2`
  90. install_dependency ${dep} ${dir}
  91. done