#!/bin/sh # rfs mount modules flist over /lib/modules/$(uname -r) (plain S3 route embedded in the .fl) # Looks for modules-$(uname -r).fl in known locations; can be overridden via MODULES_FLIST env. set -eu log() { echo "[rfs-modules] $*"; } RFS_BIN="${RFS_BIN:-rfs}" KVER="$(uname -r)" TARGET="/lib/modules/${KVER}" # 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 "${MODULES_FLIST:-}" ] && [ -f "${MODULES_FLIST}" ]; then FL="${MODULES_FLIST}" else # Candidate paths for the flist manifest for p in \ "/etc/rfs/modules-${KVER}.fl" \ "/var/lib/rfs/modules-${KVER}.fl" \ "/root/modules-${KVER}.fl" \ "/modules-${KVER}.fl" \ ; do if [ -f "$p" ]; then FL="$p" break fi done fi if [ -z "${FL:-}" ]; then # Try remote fetch as a fallback (modules--Zero-OS.fl) mkdir -p /etc/rfs FL="/etc/rfs/modules-${KVER}.fl" URL="${BASE_URL%/}/modules-${KVER}-Zero-OS.fl" log "modules-${KVER}.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"