summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortranch <tranch.xiao@gmail.com>2026-11-17 00:13:25 +0800
committertranch <tranch.xiao@gmail.com>2026-11-17 00:21:20 +0800
commit2d46b8296a7ee7243f5f6d2d01d6effa1e5b27e9 (patch)
tree24359c8ce049669b7a880e3e54acee24a78dcd3d
parentf273f285f546173a4a9abf61eee0ec8b83e09ad7 (diff)
downloadAeroCore-OS-2d46b8296a7ee7243f5f6d2d01d6effa1e5b27e9.tar.gz
AeroCore-OS-2d46b8296a7ee7243f5f6d2d01d6effa1e5b27e9.zip
Make Flatpak mirror setup resilienttesting-45.20261116
Try the Bazzite mirror helper first, then update the repo definition directly when the helper is unavailable or fails. Keep image builds running if neither path can configure the mirror, and add behavior coverage for each fallback. Verified on ayaneo-am02.lan with the Linux behavior test.
-rwxr-xr-xbuild_files/build.sh37
-rw-r--r--tests/test-flatpak-mirror-build-config.sh68
2 files changed, 103 insertions, 2 deletions
diff --git a/build_files/build.sh b/build_files/build.sh
index 94a5ef5..2d43e33 100755
--- a/build_files/build.sh
+++ b/build_files/build.sh
@@ -145,6 +145,7 @@ if [[ -f "${CEC_CONFIG}" ]]; then
fi
fi
+configure_mirrors() {
mkdir -p /etc/environment.d
if [[ -n "${FLATPAK_REMOTE_URL:-}" || -n "${HOMEBREW_BOTTLE_DOMAIN:-}" || -n "${HOMEBREW_API_DOMAIN:-}" ]]; then
@@ -153,8 +154,35 @@ fi
if [[ -n "${FLATPAK_REMOTE_URL:-}" ]]; then
printf '%s\n' "FLATPAK_REMOTE_URL=${FLATPAK_REMOTE_URL}" >> /etc/environment.d/99-aerocore-mirrors.conf
- if [[ -f /usr/libexec/bazzite-mirror-utils.sh ]]; then
- bash /usr/libexec/bazzite-mirror-utils.sh update_flathub_repo_url "${FLATPAK_REMOTE_URL}"
+ mirror_utils=/usr/libexec/bazzite-mirror-utils.sh
+ flatpak_repo=/etc/flatpak/remotes.d/flathub.flatpakrepo
+ expected_flatpak_url="${FLATPAK_REMOTE_URL%/}/"
+ mirror_updated=false
+
+ if [[ -r "${mirror_utils}" ]] && bash "${mirror_utils}" update_flathub_repo_url "${FLATPAK_REMOTE_URL}"; then
+ mirror_updated=true
+ fi
+
+ # Keep mirror configuration best-effort. If Bazzite's helper is absent or
+ # cannot update the definition, update its Url field directly as a fallback.
+ if [[ "${mirror_updated}" != true && -w "${flatpak_repo}" ]]; then
+ temp_repo="$(mktemp)"
+ if awk -v url="${expected_flatpak_url}" '
+ BEGIN { updated = 0 }
+ /^Url=/ { print "Url=" url; updated = 1; next }
+ { print }
+ END { if (!updated) print "Url=" url }
+ ' "${flatpak_repo}" > "${temp_repo}" && mv "${temp_repo}" "${flatpak_repo}"; then
+ mirror_updated=true
+ else
+ rm -f "${temp_repo}"
+ fi
+ fi
+
+ if [[ "${mirror_updated}" == true ]]; then
+ echo "Configured Flathub mirror: ${expected_flatpak_url}"
+ else
+ echo "Warning: could not configure Flathub mirror ${expected_flatpak_url}; keeping the existing repo definition." >&2
fi
fi
@@ -172,6 +200,11 @@ if [[ -n "${HOMEBREW_API_DOMAIN:-}" ]]; then
fi
find /etc/environment.d /etc/skel/.config/environment.d -name 99-aerocore-mirrors.conf -type f -exec chmod 0644 {} + 2>/dev/null || true
+}
+
+if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
+ configure_mirrors
+fi
/ctx/install-instruments.sh
/ctx/patch-bazzite-deck-identity.sh
diff --git a/tests/test-flatpak-mirror-build-config.sh b/tests/test-flatpak-mirror-build-config.sh
new file mode 100644
index 0000000..1b661bd
--- /dev/null
+++ b/tests/test-flatpak-mirror-build-config.sh
@@ -0,0 +1,68 @@
+#!/usr/bin/env bash
+
+set -euo pipefail
+
+project_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
+build_script="${project_root}/build_files/build.sh"
+test_root="$(mktemp -d)"
+trap 'rm -rf "${test_root}"' EXIT
+
+mirror_function="${test_root}/configure-mirrors.sh"
+sed -n '/^configure_mirrors() {/,/^}$/p' "${build_script}" > "${mirror_function}"
+source "${mirror_function}"
+
+assert_eq() {
+ local expected="$1" actual="$2" message="$3"
+ if [[ "${expected}" != "${actual}" ]]; then
+ printf 'FAIL: %s\nexpected: <%s>\nactual: <%s>\n' "${message}" "${expected}" "${actual}" >&2
+ exit 1
+ fi
+}
+
+run_case() {
+ local name="$1" helper_mode="$2" repo_mode="$3"
+ local case_root="${test_root}/${name}"
+ mkdir -p "${case_root}/etc/environment.d" "${case_root}/skel/.config/environment.d" "${case_root}/etc/flatpak/remotes.d" "${case_root}/usr/libexec"
+ export TEST_ROOT="${case_root}"
+ export FLATPAK_REMOTE_URL='https://mirror.example/flathub'
+ unset HOMEBREW_BOTTLE_DOMAIN HOMEBREW_API_DOMAIN
+
+ if [[ "${helper_mode}" != missing ]]; then
+ cat > "${case_root}/usr/libexec/bazzite-mirror-utils.sh" <<'HELPER'
+#!/usr/bin/env bash
+[[ "${HELPER_MODE}" == fail ]] && exit 1
+awk -v url="${2%/}/" 'BEGIN{updated=0} /^Url=/{print "Url=" url;updated=1;next} {print} END{if(!updated)print "Url=" url}' "${TEST_ROOT}/etc/flatpak/remotes.d/flathub.flatpakrepo" > "${TEST_ROOT}/repo.tmp" && mv "${TEST_ROOT}/repo.tmp" "${TEST_ROOT}/etc/flatpak/remotes.d/flathub.flatpakrepo"
+HELPER
+ chmod +x "${case_root}/usr/libexec/bazzite-mirror-utils.sh"
+ fi
+
+ printf '[Flatpak Repo]\nTitle=Flathub\nUrl=https://dl.flathub.org/repo/\nHomepage=https://flathub.org/\n' > "${case_root}/etc/flatpak/remotes.d/flathub.flatpakrepo"
+ if [[ "${repo_mode}" == readonly ]]; then chmod 0444 "${case_root}/etc/flatpak/remotes.d/flathub.flatpakrepo"; fi
+
+ # Relocate production paths into an isolated fixture, then execute the
+ # extracted production function directly.
+ export HELPER_MODE="${helper_mode}"
+ sed -e "s|/etc/environment.d|${case_root}/etc/environment.d|g" \
+ -e "s|/etc/skel|${case_root}/skel|g" \
+ -e "s|/usr/libexec|${case_root}/usr/libexec|g" \
+ -e "s|/etc/flatpak|${case_root}/etc/flatpak|g" \
+ "${mirror_function}" > "${case_root}/configure-mirrors.sh"
+ source "${case_root}/configure-mirrors.sh"
+ configure_mirrors
+
+ local actual_url
+ actual_url="$(sed -n 's/^Url=//p' "${case_root}/etc/flatpak/remotes.d/flathub.flatpakrepo")"
+ if [[ "${helper_mode}" == success || ( "${repo_mode}" == writable && "${helper_mode}" != success ) ]]; then
+ assert_eq 'https://mirror.example/flathub/' "${actual_url}" "${name}: configured mirror URL"
+ else
+ assert_eq 'https://dl.flathub.org/repo/' "${actual_url}" "${name}: retain original URL when no write path exists"
+ fi
+ assert_eq 'FLATPAK_REMOTE_URL=https://mirror.example/flathub' "$(cat "${case_root}/etc/environment.d/99-aerocore-mirrors.conf")" "${name}: persist environment setting"
+}
+
+run_case helper_success success writable
+run_case helper_failure fail writable
+run_case helper_missing missing writable
+run_case no_write_path fail readonly
+
+echo "Flatpak mirror behavior checks passed."