Files
2026-08-13 09:31:12 +08:00

83 lines
2.1 KiB
Bash

#!/bin/bash
# shellcheck disable=SC2155
if ! type "include" >/dev/null 2>&1; then
include() {
. "$(cd "$(dirname "$1")" && pwd)/${2}"
}
fi
include "${BASH_SOURCE[0]}" ../pragma_once.bash
if ! pragma_once ${BASH_SOURCE[0]}; then return 0; fi
include "${BASH_SOURCE[0]}" ./global_rely/export.bash
# shellcheck source=./global_rely/export.bash
#download_msys2_pkg() {
# local repo="$1"
# local pkg_name="$2"
# local pkg_root="$3"
# local sha256="${4:-}"
#
# check_and_create_dir_var pkg_root
#
# local pkg_path="${pkg_root}/${pkg_name}"
# local url="https://mirror.msys2.org/mingw/${repo}/${pkg_name}"
#
# if [[ -f "${pkg_path}" ]]; then
# echo "[reuse] ${pkg_path}" >&2
# else
# echo "[download] ${url}" >&2
# curl -L --fail --retry 3 \
# -o "${pkg_path}" \
# "${url}"
# fi
#
# if [[ -n "${sha256}" ]]; then
# echo "${sha256} ${pkg_path}" | sha256sum -c - >&2
# fi
#
# printf '%s\n' "${pkg_path}"
#}
#download_msys2_pkg() {
# local repo="$1"
# local pkg_name="$2"
# local pkg_root="$3"
# local sha256="${4:-}"
# check_and_create_dir_var pkg_root >&2
# local pkg_path="${pkg_root}/${pkg_name}"
# local url="https://mirror.msys2.org/mingw/${repo}/${pkg_name}"
# if [[ -f "${pkg_path}" ]]; then
# echo "[reuse] ${pkg_path}" >&2
# else
# echo "[download] ${url}" >&2
# curl -L --fail --retry 3 -o "${pkg_path}" "${url}"
# fi
# if [[ -n "${sha256}" ]]; then
# echo "${sha256} ${pkg_path}" | sha256sum -c - >&2
# fi
# printf '%s\n' "${pkg_path}"
#}
download_msys2_pkg() {
local -n out_path="$1"
local repo="$2"
local pkg_name="$3"
local pkg_root="$4"
local sha256="${5:-}"
check_and_create_dir_var pkg_root || exit $?
out_path="${pkg_root}/${pkg_name}"
local url="https://mirror.msys2.org/mingw/${repo}/${pkg_name}"
if [[ -f "${out_path}" ]]; then
echo "[reuse] ${out_path}" >&2
else
echo "[download] ${url}" >&2
curl -L --fail --retry 3 -o "${out_path}" "${url}" || {
local ret=$?
rm -f -- "${out_path}"
exit "$ret"
}
fi
if [[ -n "${sha256}" ]]; then
echo "${sha256} ${out_path}" | sha256sum -c - >&2 || exit $?
fi
}