download 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #!/bin/bash
  2. # download script: Download the programmes used in libreboot, that
  3. # aren't distributed in the git repository.
  4. #
  5. # Copyright (C) 2014, 2015 Francis Rowe <info@gluglug.org.uk>
  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. programmes=( "${download}"/* )
  25. noconfirm="0"
  26. help () {
  27. printf "%s\n\n" "./download programme(s) # programmes are space separated, if specifing multiple programmes"
  28. printf "possible values for 'programmes':\nall:\n%s\n\n" "${programmes}"
  29. printf "Example (download everything): ./download all\n"
  30. printf "Example (download flashrom): ./download flashrom\n"
  31. printf "Example (download coreboot): ./download coreboot\n"
  32. printf "Example (download coreboot and flashrom): ./download coreboot flashrom\n"
  33. printf "Example (lists all available downloadable components): ./download list\n"
  34. }
  35. if [ $# -lt 1 ]; then
  36. printf "ERROR: download script: no argmunt given.\n"
  37. help
  38. exit 1
  39. fi
  40. if [ "${1}" = "--noconfirm" ] || [ "${1}" = "-y" ]; then
  41. noconfirm="1"
  42. shift 1
  43. fi
  44. case "${1}" in
  45. all)
  46. ;;
  47. list)
  48. printf "possible values for 'programmes':\nall\n%s\n\n" "${programmes}"
  49. exit
  50. ;;
  51. help)
  52. help
  53. exit
  54. ;;
  55. *)
  56. for programme in "${@}"; do
  57. printf "%s" "${programmes}\n" | grep -wq "${programme}" || (printf "ERROR: Invalid programme '%s'. See ./download help.\n" "${programme}"; exit 1)
  58. done
  59. programmes="${*}"
  60. ;;
  61. esac
  62. for programme in ${programmes}; do
  63. if [ "${noconfirm}" = "0" ]; then
  64. printf "Use \"./download --noconfirm\" or \"./download -y\" if you want to be rid of these confirmation dialogues.\n\n"
  65. if [ -d "${programme}/" ]; then
  66. printf "A %s/ directory already exists, delete it? [yN]: " "${programme}"
  67. read -r answer
  68. if [ "${answer}" = "y" ]; then
  69. rm -Rf "${programme:?}" && printf "Old %s directory deleted.\n\n" "${programme}"
  70. else
  71. printf "%s directory not deleted, and therefore not replaced.\n" "${programme}"
  72. continue
  73. fi
  74. fi
  75. fi
  76. "${download}/${programme}"
  77. done