#!/usr/bin/env bash # Phase 1.2: Deep Prefix Eradication # Applies the complete PikeOS → UniversalisOS prefix mapping across the codebase. set -euo pipefail BASE="/home/fabiorafaelcoutada/portugalfuturista/universalisos" LOGDIR="$BASE/eradication-logs" TIMESTAMP=$(date +%Y%m%d-%H%M%S) LOG="$LOGDIR/eradicate-${TIMESTAMP}.log" mkdir -p "$LOGDIR" echo "=== Phase 1.2: Deep Prefix Eradication ===" | tee "$LOG" echo "Timestamp: $TIMESTAMP" | tee -a "$LOG" # Count files modified TOTAL_FILES=0 # Apply prefix rules to a single file (text files only) apply_rules() { local f="$1" local mime mime=$(file --mime-type -b "$f" 2>/dev/null) case "$mime" in text/*|application/json|application/xml|application/javascript|application/x-shellscript|application/x-perl|application/x-python*|application/x-c|application/x-c++*) sed -i \ -e 's/\bP4_E_/UOS_ERR_/g' \ -e 's/\bP4_e_t\b/UOS_ERR_T/g' \ -e 's/\bP4X_/UOSX_/g' \ -e 's/\bp4x_/uosx_/g' \ -e 's/\bp4hwvirt_/uos_hwvirt_/g' \ -e 's/\bP4HWVIRT_/UOS_HWVIRT_/g' \ -e 's/\bVMM_/UOS_VMM_/g' \ -e 's/\bP4BUS_/UOS_BUS_/g' \ -e 's/\bp4bus_/uos_bus_/g' \ -e 's/\bPSP_/UOS_PSP_/g' \ -e 's/\bpsp_/uos_psp_/g' \ -e 's/\bANIS_/UOS_ANIS_/g' \ -e 's/\bapex_/uos_apex_/g' \ -e 's/\bAPEX_/UOS_APEX_/g' \ -e 's/\bARINC653_/UOS_ARINC653_/g' \ -e 's/\bDDK_/UOS_DDK_/g' \ -e 's/\bddk-/uos_ddk-/g' \ -e 's/\bHLNET_/UOS_HLNET_/g' \ -e 's/\bHLSER_/UOS_HLSER_/g' \ -e 's/\bHLBLK_/UOS_HLBLK_/g' \ -e 's/\bHLDIO_/UOS_HLDIO_/g' \ -e 's/\bHLCAN_/UOS_HLCAN_/g' \ -e 's/\bHLCLK_/UOS_HLCLK_/g' \ -e 's/\bSPIDER_/UOS_TRACE_/g' \ -e 's/\bspider_/uos_trace_/g' \ -e 's/\bIMON_/UOS_IMON_/g' \ -e 's/\bVP_/UOS_VP_/g' \ -e 's/\bDDAPI_/UOS_DDAPI_/g' \ -e 's/\bINSTRUMON_/UOS_INSTRUMON_/g' \ -e 's/\bKDEV_/UOS_KDEV_/g' \ -e 's/\bkdev_/uos_kdev_/g' \ -e 's/\bDRV_/UOS_DRV_/g' \ -e 's/\bdrv_/uos_drv_/g' \ -e 's/\badt_/uos_adt_/g' \ -e 's/\bADT_/UOS_ADT_/g' \ -e 's/\bPD_/UOS_PART_/g' \ -e 's/\bpd_/uos_part_/g' \ -e 's/\bp4ext_/uos_ext_/g' \ -e 's/\bP4EXT_/UOS_EXT_/g' \ -e 's/\bPIKEOS_/UNIVERSALISOS_/g' \ "$f" return 0 ;; *) return 1 ;; esac } # Process pikeos-rebrand/ (excluding build logs) echo "" | tee -a "$LOG" echo ">>> Processing pikeos-rebrand/ (excluding build logs)..." | tee -a "$LOG" REBRAND_COUNT=0 while IFS= read -r -d '' f; do if apply_rules "$f"; then REBRAND_COUNT=$((REBRAND_COUNT + 1)) fi done < <(find "$BASE/pikeos-rebrand" -type f -not -path "*/log/BUILD-LOGS/*" -print0 2>/dev/null) echo " pikeos-rebrand/: $REBRAND_COUNT files processed" | tee -a "$LOG" # Process kernel/ source echo "" | tee -a "$LOG" echo ">>> Processing kernel/src/ and kernel/include/..." | tee -a "$LOG" KERNEL_COUNT=0 while IFS= read -r -d '' f; do if apply_rules "$f"; then KERNEL_COUNT=$((KERNEL_COUNT + 1)) fi done < <(find "$BASE/kernel/src" "$BASE/kernel/include" -type f -print0 2>/dev/null) echo " kernel/: $KERNEL_COUNT files processed" | tee -a "$LOG" # Process universalisos/ top-level (excluding build dirs) echo "" | tee -a "$LOG" echo ">>> Processing universalisos/ top-level files..." | tee -a "$LOG" TOP_COUNT=0 while IFS= read -r -d '' f; do if apply_rules "$f"; then TOP_COUNT=$((TOP_COUNT + 1)) fi done < <(find "$BASE" -maxdepth 1 -type f -print0 2>/dev/null) echo " top-level: $TOP_COUNT files processed" | tee -a "$LOG" TOTAL_FILES=$((REBRAND_COUNT + KERNEL_COUNT + TOP_COUNT)) echo "" | tee -a "$LOG" echo "=== Summary ===" | tee -a "$LOG" echo "Total files processed: $TOTAL_FILES" | tee -a "$LOG" # Verification: count remaining PikeOS prefixes echo "" | tee -a "$LOG" echo "=== Remaining PikeOS prefix counts ===" | tee -a "$LOG" REMAINING=0 for prefix in p4_ P4_ uosx_ UOSX_ uos_ext_ UOS_EXT_ uos_hwvirt_ UOS_HWVIRT_ UOS_VMM_ UOS_BUS_ UOS_PSP_ UOS_ANIS_ uos_apex_ UOS_APEX_ UOS_DDK_ UOS_TRACE_ UOS_KDEV_ uos_kdev_ uos_drv_ UOS_DRV_ VM_ vm_ UOS_PART_ uos_part_; do count=$(grep -rIl "\b${prefix}" "$BASE/pikeos-rebrand/" "$BASE/kernel/src/" "$BASE/kernel/include/" 2>/dev/null | grep -v 'log/BUILD-LOGS' | wc -l) if (( count > 0 )); then echo " $prefix: $count files remaining" | tee -a "$LOG" REMAINING=$((REMAINING + count)) fi done echo " Total remaining: $REMAINING files" | tee -a "$LOG" echo "" | tee -a "$LOG" echo "=== Eradication complete ===" | tee -a "$LOG" echo "Log: $LOG" | tee -a "$LOG"