reGen2 Linux Release Metatool
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.

64 lines
2.0 KiB

9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
  1. #!/bin/bash
  2. # Copyright 2010-2011, Asio Software Technologies
  3. # Distributed under the terms of the GNU General Public License v3
  4. #-------------------------------------------------------------------------------
  5. # Downloads files into specified or current directory
  6. # Parameters: %url% %directory%
  7. #-------------------------------------------------------------------------------
  8. function download() {
  9. local DEST FILENAME RESULT URL
  10. DEST="${2}"
  11. FILENAME="${1##*/}"
  12. URL="${1}"
  13. if isSet DEST; then
  14. DEST="${DEST}/${FILENAME}"
  15. else
  16. DEST="./${FILENAME}"
  17. fi
  18. logMessage "Downloading ${URL} to ${DEST}" "DEBUG"
  19. echo -ne " ${STAR_GREEN} ${FILENAME}: "
  20. wget --progress=dot -c -t ${FETCHTRIES} -T ${FETCHTIMEOUT} -O "${DEST}" \
  21. ${URL} 2>&1 | grep --line-buffered "%" | sed -u -e "s/[\.\,]//g" | \
  22. awk '{printf("\b\b\b\b%4s", $2)}'
  23. RESULT=${PIPESTATUS[0]}
  24. echo -ne "\b\b\b\b"
  25. if [ ${RESULT} -ne 0 ]; then
  26. logOutput "Unable to download ${URL}! Exit code: ${RESULT}"
  27. echo -e "${COLOR_RED}${COLOR_BOLD}ERROR${COLOR_WHITE}${COLOR_NORMAL}"
  28. else
  29. echo -e "${COLOR_GREEN}${COLOR_BOLD}DONE${COLOR_WHITE}${COLOR_NORMAL}"
  30. fi
  31. return ${RESULT}
  32. }
  33. #-------------------------------------------------------------------------------
  34. # Creates all components of the specified directories
  35. # Parameters: %directory%
  36. #-------------------------------------------------------------------------------
  37. function makeDirectory() {
  38. local OUTPUT RESULT
  39. OUTPUT=$(install -d "${@}" 2>&1)
  40. RESULT=${?}
  41. if [ ${RESULT} -ne 0 ]; then
  42. logOutput "${OUTPUT}"
  43. fi
  44. return ${RESULT}
  45. }
  46. #-------------------------------------------------------------------------------
  47. # Creates a symbolic link between to files in specified target directory
  48. # Parameters: %source% %target%
  49. #-------------------------------------------------------------------------------
  50. function makeLink() {
  51. local DESTDIR OUTPUT RESULT
  52. DESTDIR="${2%/*}"
  53. [[ ! -d ${DESTDIR} ]] && makeDirectory "${DESTDIR}"
  54. OUTPUT=$(ln -sfn "${1}" "${2}" 2>&1)
  55. RESULT=${?}
  56. if [ ${RESULT} -ne 0 ]; then
  57. logOutput "${OUTPUT}"
  58. fi
  59. return ${RESULT}
  60. }