logo

live-bootstrap

Mirror of <https://github.com/fosslinux/live-bootstrap>

download-distfiles.sh (1681B)


  1. #!/usr/bin/env bash
  2. # SPDX-FileCopyrightText: 2022 fosslinux <fosslinux@aussies.space>
  3. #
  4. # SPDX-License-Identifier: GPL-3.0-or-later
  5. download_source() {
  6. local distfiles="${1}"
  7. local url="${2}"
  8. local checksum="${3}"
  9. local fname="${4}"
  10. # Default to basename of url if not given
  11. fname="${fname:-$(basename "${url}")}"
  12. local dest_path="${distfiles}/${fname}"
  13. if ! [ -e "${dest_path}" ]; then
  14. echo "Downloading ${fname}"
  15. curl --fail --location "${url}" --output "${dest_path}" || true
  16. fi
  17. }
  18. check_source() {
  19. local distfiles="${1}"
  20. local url="${2}"
  21. local checksum="${3}"
  22. local fname="${4}"
  23. # Default to basename of url if not given
  24. fname="${fname:-$(basename "${url}")}"
  25. local dest_path="${distfiles}/${fname}"
  26. echo "${checksum} ${dest_path}" | sha256sum -c
  27. }
  28. set -e
  29. cd "$(dirname "$(readlink -f "$0")")"
  30. mkdir -p distfiles
  31. # First, try to download anything missing - ignore failing mirrors
  32. for entry in steps/*; do
  33. [ -e "${entry}/sources" ] || continue
  34. # shellcheck disable=SC2162
  35. while read line; do
  36. # This is intentional - we want to split out ${line} into separate arguments.
  37. # shellcheck disable=SC2086
  38. download_source distfiles ${line}
  39. done < "${entry}/sources"
  40. done
  41. # Then, check if everything has been obtained at least once
  42. for entry in steps/*; do
  43. [ -e "${entry}/sources" ] || continue
  44. # shellcheck disable=SC2162
  45. while read line; do
  46. # This is intentional - we want to split out ${line} into separate arguments.
  47. # shellcheck disable=SC2086
  48. check_source distfiles ${line}
  49. done < "${entry}/sources"
  50. done