mirror of
https://github.com/frappe/frappe_docker.git
synced 2026-06-18 06:05:09 +00:00
128 lines
3.4 KiB
Bash
Executable file
128 lines
3.4 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
|
|
cleanup_gum_tmp_dir() {
|
|
local tmp_dir="${1:-}"
|
|
|
|
if [ -n "${tmp_dir}" ] && [ -d "${tmp_dir}" ]; then
|
|
rm -rf "${tmp_dir}"
|
|
fi
|
|
}
|
|
|
|
install_gum_from_github_release() {
|
|
local release_version=""
|
|
local checksums_path=""
|
|
local asset_name=""
|
|
local asset_path=""
|
|
local download_url=""
|
|
local tmp_dir=""
|
|
local extract_dir=""
|
|
local target_dir=""
|
|
local gum_binary_path=""
|
|
local target_binary_name="gum"
|
|
local gum_os=""
|
|
local gum_arch=""
|
|
local expected_checksum=""
|
|
|
|
if ! command_exists curl; then
|
|
echo "curl is required for the GitHub fallback."
|
|
return 1
|
|
fi
|
|
|
|
if ! read -r gum_os gum_arch < <(detect_gum_platform); then
|
|
echo "Unsupported platform for automatic GitHub fallback."
|
|
return 1
|
|
fi
|
|
|
|
release_version="$(get_pinned_gum_version || true)"
|
|
if [ -z "${release_version}" ]; then
|
|
echo "Could not determine the pinned gum release version."
|
|
return 1
|
|
fi
|
|
|
|
checksums_path="$(get_gum_checksums_path)"
|
|
if [ ! -f "${checksums_path}" ]; then
|
|
echo "Pinned gum checksum file is missing: ${checksums_path}"
|
|
return 1
|
|
fi
|
|
|
|
if ! sha256_verification_available; then
|
|
echo "A SHA256 verification tool is required for the GitHub fallback."
|
|
return 1
|
|
fi
|
|
|
|
tmp_dir="$(mktemp -d 2>/dev/null || true)"
|
|
if [ -z "${tmp_dir}" ] || [ ! -d "${tmp_dir}" ]; then
|
|
echo "Failed to create temporary directory for gum installation."
|
|
return 1
|
|
fi
|
|
extract_dir="${tmp_dir}/extract"
|
|
|
|
while IFS= read -r asset_name; do
|
|
expected_checksum="$(get_pinned_gum_asset_checksum "${release_version}" "${asset_name}" || true)"
|
|
if [ -z "${expected_checksum}" ]; then
|
|
continue
|
|
fi
|
|
|
|
asset_path="${tmp_dir}/${asset_name}"
|
|
download_url="https://github.com/charmbracelet/gum/releases/download/v${release_version}/${asset_name}"
|
|
|
|
if ! curl -fsSL "${download_url}" -o "${asset_path}"; then
|
|
continue
|
|
fi
|
|
|
|
if ! verify_file_sha256 "${asset_path}" "${expected_checksum}"; then
|
|
echo "Checksum verification failed for ${asset_name}."
|
|
continue
|
|
fi
|
|
|
|
rm -rf "${extract_dir}"
|
|
mkdir -p "${extract_dir}"
|
|
|
|
if ! extract_gum_asset "${asset_path}" "${extract_dir}"; then
|
|
continue
|
|
fi
|
|
|
|
gum_binary_path="$(find_gum_binary "${extract_dir}" || true)"
|
|
if [ -n "${gum_binary_path}" ]; then
|
|
break
|
|
fi
|
|
done < <(get_gum_asset_candidates "${release_version}" "${gum_os}" "${gum_arch}")
|
|
|
|
if [ -z "${gum_binary_path}" ]; then
|
|
cleanup_gum_tmp_dir "${tmp_dir}"
|
|
echo "No compatible, verified gum binary was found in the pinned GitHub release assets."
|
|
return 1
|
|
fi
|
|
|
|
if [[ "${gum_binary_path}" == *.exe ]]; then
|
|
target_binary_name="gum.exe"
|
|
fi
|
|
|
|
if [ "${gum_os}" != "Windows" ] && [ -w "/usr/local/bin" ]; then
|
|
target_dir="/usr/local/bin"
|
|
if copy_binary "${gum_binary_path}" "${target_dir}/${target_binary_name}"; then
|
|
cleanup_gum_tmp_dir "${tmp_dir}"
|
|
return 0
|
|
fi
|
|
fi
|
|
|
|
if [ "${gum_os}" != "Windows" ] && command_exists sudo; then
|
|
if copy_binary_with_privileges "${gum_binary_path}" "/usr/local/bin/${target_binary_name}"; then
|
|
cleanup_gum_tmp_dir "${tmp_dir}"
|
|
return 0
|
|
fi
|
|
fi
|
|
|
|
if [ -n "${HOME:-}" ]; then
|
|
target_dir="${HOME}/.local/bin"
|
|
mkdir -p "${target_dir}"
|
|
if copy_binary "${gum_binary_path}" "${target_dir}/${target_binary_name}"; then
|
|
cleanup_gum_tmp_dir "${tmp_dir}"
|
|
return 0
|
|
fi
|
|
fi
|
|
|
|
cleanup_gum_tmp_dir "${tmp_dir}"
|
|
echo "Failed to install gum binary from GitHub release."
|
|
return 1
|
|
}
|