download 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #!/bin/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. rm -f "osbmk_error"
  24. download=resources/scripts/download
  25. listprograms() {
  26. for program in "${download}"/*; do
  27. printf '%s\n' "${program##*/}"
  28. done
  29. }
  30. help() {
  31. cat <<- EOF
  32. USAGE: ./download <PROGRAM> <OPTIONS>
  33. possible values for 'program':
  34. $(listprograms)
  35. Example: ./download flashrom
  36. Example: ./download coreboot
  37. Some program options allow for additional parameters:
  38. Example: ./download coreboot default
  39. Example: ./download coreboot x60
  40. Each program download script should work without extra paramaters, but
  41. they can use them. For instance, './download coreboot' will download all
  42. coreboot trees by default, but './download coreboot x60' will only download
  43. the coreboot tree required for the target: x60
  44. Refer to the documentation for more information.
  45. EOF
  46. }
  47. die() {
  48. printf 'Error: %s\n' "${@}" 1>&2
  49. exit 1
  50. }
  51. if [ $# -lt 1 ]; then
  52. die "Wrong number of arguments specified. See './download help'."
  53. fi
  54. program="${1}"
  55. shift 1
  56. [ "${program}" = help ] && help && exit 0
  57. if [ ! -f "${download}/${program}" ]; then
  58. help
  59. die "Invalid argument '${program}'. See: './download help'."
  60. fi
  61. if [ $# -lt 1 ]; then
  62. "${download}/${program}"
  63. else
  64. "${download}/${program}" $@
  65. fi
  66. exit 0