download 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #!/bin/bash
  2. # download script: Download the programs used in libreboot, that
  3. # aren't distributed in the git repository.
  4. #
  5. # Copyright (C) 2014, 2015 Minifree Ltd <info@minifree.org>
  6. # Copyright (C) 2015 Klemens Nanni <contact@autoboot.org>
  7. #
  8. # This program is free software: you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation, either version 3 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License
  19. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. #
  21. [ "x${DEBUG+set}" = 'xset' ] && set -v
  22. set -u -e
  23. download="resources/scripts/helpers/download"
  24. # echo "${programs##*/}" ; echo "${programs%/*}"
  25. programs="$(for program in ${download}/*; do printf "%s\n" "${program##*/}"; done)"
  26. noconfirm="0"
  27. help () {
  28. printf "%s\n\n" "./download program(s) # programs are space separated, if specifing multiple programs"
  29. printf "possible values for 'programs':\nall:\n%s\n\n" "${programs}"
  30. printf "Example (download everything): ./download all\n"
  31. printf "Example (download flashrom): ./download flashrom\n"
  32. printf "Example (download coreboot): ./download coreboot\n"
  33. printf "Example (download coreboot and flashrom): ./download coreboot flashrom\n"
  34. printf "Example (lists all available downloadable components): ./download list\n"
  35. }
  36. if [ $# -lt 1 ]; then
  37. printf "ERROR: download script: no argument given.\n"
  38. help
  39. exit 1
  40. fi
  41. if [ "${1}" = "--noconfirm" ] || [ "${1}" = "-y" ]; then
  42. noconfirm="1"
  43. shift 1
  44. fi
  45. case "${1}" in
  46. all)
  47. ;;
  48. list)
  49. printf "possible values for 'programs':\nall\n%s\n\n" "${programs}"
  50. exit
  51. ;;
  52. help)
  53. help
  54. exit
  55. ;;
  56. *)
  57. for program in "${@}"; do
  58. printf "%s" "${programs}\n" | grep -wq "${program}" || (printf "ERROR: Invalid program '%s'. See ./download help.\n" "${program}"; exit 1)
  59. done
  60. programs="${*}"
  61. ;;
  62. esac
  63. for program in ${programs}; do
  64. if [ "${noconfirm}" = "0" ]; then
  65. printf "Use \"./download --noconfirm\" or \"./download -y\" if you want to be rid of these confirmation dialogues.\n\n"
  66. if [ -d "${program}/" ]; then
  67. printf "A %s/ directory already exists, delete it? [yN]: " "${program}"
  68. read -r answer
  69. if [ "${answer}" = "y" ]; then
  70. rm -Rf "${program:?}" && printf "Old %s directory deleted.\n\n" "${program}"
  71. else
  72. printf "%s directory not deleted, and therefore not replaced.\n" "${program}"
  73. continue
  74. fi
  75. fi
  76. fi
  77. "${download}/${program}"
  78. done