download 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. rm -f "build_error"
  28. download=resources/scripts/download
  29. listprograms() {
  30. for program in "${download}"/*; do
  31. printf '%s\n' "${program##*/}"
  32. done
  33. }
  34. help() {
  35. cat <<- EOF
  36. USAGE: ./download <PROGRAM> <OPTIONS>
  37. possible values for 'program':
  38. $(listprograms)
  39. Example: ./download flashrom
  40. Example: ./download coreboot
  41. Some program options allow for additional parameters:
  42. Example: ./download coreboot default
  43. Example: ./download coreboot x60
  44. Each program download script should work without extra paramaters, but
  45. they can use them. For instance, './download coreboot' will download all
  46. coreboot trees by default, but './download coreboot x60' will only download
  47. the coreboot tree required for the target: x60
  48. Each program download script should also accept the --help parameter to
  49. display the usage of the script.
  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. "${downloadProgram}"
  67. done
  68. exit 0
  69. elif [ ! -f "${download}/${program}" ]; then
  70. help
  71. die "Invalid argument '${program}'. See: './download help'."
  72. fi
  73. if [ $# -lt 1 ]; then
  74. "${download}/${program}"
  75. else
  76. "${download}/${program}" $@
  77. fi
  78. exit 0
  79. ./.gitcheck clean