download 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #!/usr/bin/env 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 Leah Rowe <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. if [ "${program}" = "seabios" ]; then
  68. # temporary hack. download grub also downloads seabios,
  69. # which breaks automated build when running ./download all
  70. # Later on, we'll delete the seabios download script
  71. # and grub download script and replace both with
  72. # a download seagrub script
  73. rm -Rf "${program:?}" && printf "Old %s directory deleted.\n\n" "${program}"
  74. else
  75. printf "A %s/ directory already exists, delete it? [yN]: " "${program}"
  76. read -r answer
  77. if [ "${answer}" = "y" ]; then
  78. rm -Rf "${program:?}" && printf "Old %s directory deleted.\n\n" "${program}"
  79. else
  80. printf "%s directory not deleted, and therefore not replaced.\n" "${program}"
  81. continue
  82. fi
  83. fi
  84. fi
  85. fi
  86. "${download}/${program}"
  87. done