logo

live-bootstrap

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

download-distfiles.sh (2170B)


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