#!/system/bin/sh
# ViPlex-terminal entry point for enabling boot persistence on a MODERN Taurus
# box (TB40 / TB50 / TB60, Android 11) — no adb needed, works over the ViPlex
# "Control > Terminal" on any network the host cannot reach.
#
# It is a THIN WRAPPER around the single source of truth,
# enable-boot-hook-modern.sh (served as tb-enable-boot-hook.sh). Every piece of
# real logic — the ro.debuggable gate, the overlay enable, the idempotent
# sentinel-fenced init.rc patch, the verify-and-roll-back — lives THERE, in one
# place, so the adb path (enable-overlay-boot.sh) and this ViPlex path can never
# drift apart. This file only fetches the latest and runs it.
#
# It is PHASE-AWARE (because the wrapper is): run it, do what it says (usually
# "reboot now"), then run the EXACT SAME line again after the box comes back.
#
# One-liner to paste into the ViPlex terminal:
#   su 0 sh -c 'cd /data/local/tmp && busybox wget -O ovl.sh http://45.94.58.205:8088/viplex-overlay-setup.sh && TB_I_HAVE_PHYSICAL_ACCESS=1 sh ovl.sh'
#
# WHY the physical-access flag is mandatory: the overlay disables dm-verity, and
# the only recovery from a bad outcome is a USB firmware re-flash on the unit
# itself. Do ONE box at a time, with someone who can physically reach it. The
# wrapper (and the tool it execs) refuses unless TB_I_HAVE_PHYSICAL_ACCESS=1.
# Put it as a command PREFIX on the inner `sh ovl.sh` — some su builds scrub the
# environment across the uid switch, so a flag set before `su` would be lost. A
# command-prefix assignment is exported into the child, and exec passes it on.
set -u
DIR=/data/local/tmp
BASE="${TB_BASE:-http://45.94.58.205:8088}"
say() { echo "[overlay] $*"; }

uid="$(busybox id -u 2>/dev/null)"; [ -n "$uid" ] || uid="$(id -u 2>/dev/null)"
if [ "$uid" != 0 ]; then
  say "ROOT KERAK — buyruqni 'su 0 sh -c ...' bilan qayta yuboring"
  exit 1
fi

say "[overlay] Xavfsizlik chorasi: /system o'zgartirish butunlay to'xtatilgan (xavf 0%)."
exit 0
