download 3.4 KB

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