54 lines
2.7 KiB
Bash
54 lines
2.7 KiB
Bash
|
|
#!/bin/sh
|
||
|
|
export FX_SOURCES_DIR=/root/shell-project/contrib/fx/sources.d
|
||
|
|
. /root/shell-project/src/f.sh
|
||
|
|
. /root/shell-project/contrib/fx/fx.sh
|
||
|
|
. /root/shell-project/contrib/heal/heal.sh
|
||
|
|
cd /root/shell-project 2>/dev/null
|
||
|
|
|
||
|
|
# --- Persistent learning state -------------------------------------------
|
||
|
|
# f()/fx() key learned fixes in a file called "p" in the current directory.
|
||
|
|
# On a plain live-CD boot that file lives on tmpfs and every reboot forgets
|
||
|
|
# everything the shell has ever learned.
|
||
|
|
#
|
||
|
|
# If a second, writable disk is attached (anything that isn't the boot
|
||
|
|
# CD), use it as a raw flat store for "p" -- no filesystem, no mkfs. This
|
||
|
|
# live image never mounts modloop-virt into /lib/modules, so modprobe has
|
||
|
|
# nothing to load and mkfs.ext4/mount fail with "Invalid argument"
|
||
|
|
# regardless of e2fsprogs being installed; dd/tr are busybox builtins and
|
||
|
|
# need no kernel module at all, so they work unconditionally. Learned
|
||
|
|
# fixes are restored from the disk's first 1MB at boot, and a background
|
||
|
|
# loop flushes "p" back to it every few seconds. No such disk -> "p"
|
||
|
|
# stays on tmpfs exactly as before.
|
||
|
|
STATE_DEV=""
|
||
|
|
for d in /dev/vda /dev/vdb /dev/vdc /dev/sda /dev/sdb /dev/sdc /dev/xvda /dev/xvdb; do
|
||
|
|
[ -b "$d" ] && { STATE_DEV="$d"; break; }
|
||
|
|
done
|
||
|
|
|
||
|
|
if [ -n "$STATE_DEV" ]; then
|
||
|
|
dd if="$STATE_DEV" bs=1M count=1 2>/dev/null | tr -d '\0' > /root/shell-project/p
|
||
|
|
# p.trace (fx()'s "which source suggested this fix" record) lives in
|
||
|
|
# the SECOND 1MB block of the same raw device via skip=1/seek=1 --
|
||
|
|
# a distinct region, not appended after p, so growth of one file can
|
||
|
|
# never overwrite the other's flat 1MB slot. Requires STATE_DEV to be
|
||
|
|
# at least 2MB; a device only large enough for p's block silently
|
||
|
|
# leaves p.trace unpersisted rather than corrupting p.
|
||
|
|
dd if="$STATE_DEV" bs=1M skip=1 count=1 2>/dev/null | tr -d '\0' > /root/shell-project/p.trace
|
||
|
|
(
|
||
|
|
while true; do
|
||
|
|
sleep 3
|
||
|
|
[ -f /root/shell-project/p ] && dd if=/root/shell-project/p of="$STATE_DEV" bs=1M count=1 conv=notrunc 2>/dev/null
|
||
|
|
[ -f /root/shell-project/p.trace ] && dd if=/root/shell-project/p.trace of="$STATE_DEV" bs=1M seek=1 count=1 conv=notrunc 2>/dev/null
|
||
|
|
done
|
||
|
|
) &
|
||
|
|
echo "AdaptiveOS: persistent learning state active on $STATE_DEV -- learned fixes AND fix provenance survive reboot"
|
||
|
|
fi
|
||
|
|
|
||
|
|
echo '========================================='
|
||
|
|
echo ' Welcome to AdaptiveOS'
|
||
|
|
echo ' Self-healing shell is live: f(), fx(), heal()'
|
||
|
|
echo ' Try: fx some-command-that-might-fail'
|
||
|
|
echo ' heal() does the same, plus logs a MISS to'
|
||
|
|
echo ' /var/log/glyphos-heal.log if nothing (not'
|
||
|
|
echo ' even the manual prompt) fixes it'
|
||
|
|
echo '========================================='
|