#!/bin/sh # rfs mount firmware flist over /lib/firmware (plain S3 route inside the .fl) # Looks for firmware-latest.fl in known locations; can be overridden via FIRMWARE_FLIST env set -eu log() { echo "[rfs-firmware] $*"; } RFS_BIN="${RFS_BIN:-rfs}" TARGET="/lib/firmware" # Accept both FLISTS_BASE_URL and FLIST_BASE_URL (alias); prefer FLISTS_BASE_URL if [ -n "${FLISTS_BASE_URL:-}" ]; then BASE_URL="${FLISTS_BASE_URL}" elif [ -n "${FLIST_BASE_URL:-}" ]; then BASE_URL="${FLIST_BASE_URL}" else BASE_URL="https://zos.grid.tf/store/flists" fi # HTTP readiness helper: wait until BASE_URL responds to HTTP(S) wait_for_http() { url="$1" tries="${2:-60}" delay="${3:-2}" i=0 while [ "$i" -lt "$tries" ]; do if command -v wget >/dev/null 2>&1; then if wget -q --spider "$url"; then return 0 fi elif command -v busybox >/dev/null 2>&1; then if busybox wget -q --spider "$url"; then return 0 fi fi i=$((i+1)) log "waiting for $url (attempt $i/$tries)" sleep "$delay" done return 1 } # Allow override via env if [ -n "${FIRMWARE_FLIST:-}" ] && [ -f "${FIRMWARE_FLIST}" ]; then FL="${FIRMWARE_FLIST}" else # Candidate paths for the flist manifest for p in \ /etc/rfs/firmware-latest.fl \ /var/lib/rfs/firmware-latest.fl \ /root/firmware-latest.fl \ /firmware-latest.fl \ ; do if [ -f "$p" ]; then FL="$p" break fi done fi if [ -z "${FL:-}" ]; then # Try remote fetch as a fallback (but first ensure BASE_URL is reachable) mkdir -p /etc/rfs FL="/etc/rfs/firmware-latest.fl" URL="${BASE_URL%/}/firmware-latest.fl" log "firmware-latest.fl not found locally; will fetch ${URL}" # Probe BASE_URL root so DNS/HTTP are ready before fetch ROOT_URL="${BASE_URL%/}/" if ! wait_for_http "$ROOT_URL" 60 2; then log "BASE_URL not reachable yet: ${ROOT_URL}; continuing to attempt fetch anyway" fi log "fetching ${URL}" if command -v wget >/dev/null 2>&1; then wget -q -O "${FL}" "${URL}" || true elif command -v busybox >/dev/null 2>&1; then busybox wget -q -O "${FL}" "${URL}" || true else log "no wget available to fetch ${URL}" fi if [ ! -s "${FL}" ]; then log "failed to fetch ${URL}; skipping mount" exit 0 fi fi # Ensure target directory exists mkdir -p "$TARGET" # Skip if already mounted if mountpoint -q "$TARGET" 2>/dev/null; then log "already mounted: $TARGET" exit 0 fi # Perform the mount log "mounting ${FL} -> ${TARGET}" exec "$RFS_BIN" mount -m "$FL" "$TARGET"