#!/system/bin/sh
# ===============================================
# RaiRin-AI - post-fs-data.sh (KernelSU Compatible)
# ===============================================

MODDIR="/data/adb/modules/RaiRin-AI"
SERVICE="$MODDIR/service.sh"
LOGFILE="/data/local/tmp/rairin_service.log"

chmod 755 "$SERVICE"

(
    # Tunggu boot complete
    until [ "$(getprop sys.boot_completed)" = "1" ]; do
        sleep 2
    done
    sleep 5

    echo "[RaiRin-AI] Boot complete — starting service.sh (KernelSU mode)" >> "$LOGFILE"
    date >> "$LOGFILE"

    if [ -f "$SERVICE" ]; then
        /system/bin/sh "$SERVICE" >> "$LOGFILE" 2>&1 &
    else
        echo "[RaiRin-AI] ERROR: service.sh not found!" >> "$LOGFILE"
    fi
) &