download 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #!/usr/bin/env bash
  2. # Generic script for downloading programs used by the build system
  3. #
  4. # Copyright (C) 2014, 2015, 2020, 2021 Leah Rowe <info@minifree.org>
  5. # Copyright (C) 2015 Patrick "P. J." McDermott <pj@pehjota.net>
  6. # Copyright (C) 2015, 2016 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. ./resources/scripts/misc/versioncheck
  24. # set this when you want to modify each coreboot tree
  25. # for example, you want to test custom patches
  26. # NODELETE= ./download coreboot
  27. deleteblobs="true"
  28. [ "x${NODELETE+set}" = 'xset' ] && deleteblobs="false"
  29. rm -f "build_error"
  30. download=resources/scripts/download
  31. listprograms() {
  32. for program in "${download}"/*; do
  33. printf '%s\n' "${program##*/}"
  34. done
  35. }
  36. help() {
  37. cat <<- EOF
  38. USAGE: ./download <PROGRAM> <OPTIONS>
  39. possible values for 'program':
  40. $(listprograms)
  41. Example: ./download flashrom
  42. Example: ./download coreboot
  43. Some program options allow for additional parameters:
  44. Example: ./download coreboot default
  45. Example: ./download coreboot x60
  46. Each program download script should work without extra paramaters, but
  47. they can use them. For instance, './download coreboot' will download all
  48. coreboot trees by default, but './download coreboot x60' will only download
  49. the coreboot tree required for the target: x60
  50. Refer to the documentation for more information.
  51. EOF
  52. }
  53. die() {
  54. printf 'Error: %s\n' "${@}" 1>&2
  55. exit 1
  56. }
  57. if [ $# -lt 1 ]; then
  58. help
  59. die "Please specify arguments."
  60. fi
  61. program="${1}"
  62. shift 1
  63. [ "${program}" = help ] && help && exit 0
  64. if [ "${program}" = "all" ]; then
  65. for downloadProgram in ${download}/*; do
  66. if [ -f "${downloadProgram}" ]; then
  67. if [ "${deleteblobs}" = "false" ]; then
  68. NODELETE= "${downloadProgram}"
  69. else
  70. "${downloadProgram}"
  71. fi
  72. fi
  73. done
  74. exit 0
  75. elif [ ! -f "${download}/${program}" ]; then
  76. help
  77. die "Invalid argument '${program}'. See: './download help'."
  78. fi
  79. if [ $# -lt 1 ]; then
  80. if [ "${deleteblobs}" = "false" ]; then
  81. NODELETE= "${download}/${program}"
  82. else
  83. "${download}/${program}"
  84. fi
  85. else
  86. if [ "${deleteblobs}" = "false" ]; then
  87. NODELETE= "${download}/${program}" $@
  88. else
  89. "${download}/${program}" $@
  90. fi
  91. fi
  92. exit 0