download 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. # Copyright (C) 2022, Caleb La Grange <thonkpeasant@protonmail.com>
  8. #
  9. # This program is free software: you can redistribute it and/or modify
  10. # it under the terms of the GNU General Public License as published by
  11. # the Free Software Foundation, either version 3 of the License, or
  12. # (at your option) any later version.
  13. #
  14. # This program is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. # GNU General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU General Public License
  20. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. #
  22. ./.gitcheck
  23. [ "x${DEBUG+set}" = 'xset' ] && set -v
  24. set -u -e
  25. ./resources/scripts/misc/versioncheck
  26. # set this when you want to modify each coreboot tree
  27. # for example, you want to test custom patches
  28. # NODELETE= ./download coreboot
  29. deleteblobs="true"
  30. [ "x${NODELETE+set}" = 'xset' ] && deleteblobs="false"
  31. rm -f "build_error"
  32. download=resources/scripts/download
  33. listprograms() {
  34. for program in "${download}"/*; do
  35. printf '%s\n' "${program##*/}"
  36. done
  37. }
  38. help() {
  39. cat <<- EOF
  40. USAGE: ./download <PROGRAM> <OPTIONS>
  41. possible values for 'program':
  42. $(listprograms)
  43. Example: ./download flashrom
  44. Example: ./download coreboot
  45. Some program options allow for additional parameters:
  46. Example: ./download coreboot default
  47. Example: ./download coreboot x60
  48. Each program download script should work without extra paramaters, but
  49. they can use them. For instance, './download coreboot' will download all
  50. coreboot trees by default, but './download coreboot x60' will only download
  51. the coreboot tree required for the target: x60
  52. Each program download script should also accept the --help paramater to
  53. display the usage of the script.
  54. Refer to the documentation for more information.
  55. EOF
  56. }
  57. die() {
  58. printf 'Error: %s\n' "${@}" 1>&2
  59. exit 1
  60. }
  61. if [ $# -lt 1 ]; then
  62. help
  63. die "Please specify arguments."
  64. fi
  65. program="${1}"
  66. shift 1
  67. [ "${program}" = help ] && help && exit 0
  68. if [ "${program}" = "all" ]; then
  69. for downloadProgram in ${download}/*; do
  70. if [ -f "${downloadProgram}" ]; then
  71. if [ "${deleteblobs}" = "false" ]; then
  72. NODELETE= "${downloadProgram}"
  73. else
  74. "${downloadProgram}"
  75. fi
  76. fi
  77. done
  78. exit 0
  79. elif [ ! -f "${download}/${program}" ]; then
  80. help
  81. die "Invalid argument '${program}'. See: './download help'."
  82. fi
  83. if [ $# -lt 1 ]; then
  84. if [ "${deleteblobs}" = "false" ]; then
  85. NODELETE= "${download}/${program}"
  86. else
  87. "${download}/${program}"
  88. fi
  89. else
  90. if [ "${deleteblobs}" = "false" ]; then
  91. NODELETE= "${download}/${program}" $@
  92. else
  93. "${download}/${program}" $@
  94. fi
  95. fi
  96. exit 0
  97. ./.gitcheck clean