#!/bin/sh # /init - Nano Kernel Initramfs init # This is the first process started by the nano kernel set -e # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' # No Color echo -e "${GREEN}[NANO-KERNEL] Research Stack Appliance Boot${NC}" echo "============================================" # Mount essential filesystems echo "[*] Mounting proc, sys, dev..." mount -t proc none /proc mount -t sysfs none /sys mount -t devtmpfs none /dev mount -t tmpfs none /tmp # Set up network echo "[*] Configuring network..." ip link set lo up ip link set eth0 up 2>/dev/null || ip link set ens3 up 2>/dev/null || true # Try DHCP echo "[*] Acquiring IP via DHCP..." udhcpc -i eth0 2>/dev/null || udhcpc -i ens3 2>/dev/null || { echo -e "${YELLOW}[!] DHCP failed, using static IP${NC}" ip addr add 172.245.19.182/24 dev eth0 2>/dev/null || ip addr add 172.245.19.182/24 dev ens3 2>/dev/null || true } echo "[*] Network status:" ip addr | grep "inet " # Set hostname echo "[*] Setting hostname..." hostname nano-kernel-racknerd echo "172.245.19.182 nano-kernel-racknerd" >> /etc/hosts # Mount Research Stack data (if available) # In production, this would be a persistent volume or network mount echo "[*] Setting up Research Stack environment..." mkdir -p /research-stack cd /research-stack # Extract embedded Research Stack (if included in initramfs) if [ -f /research-stack.squashfs ]; then echo "[*] Mounting Research Stack squashfs..." mount -t squashfs /research-stack.squashfs /research-stack fi # Set up Lean environment export PATH="/usr/local/bin:/usr/bin:/bin" export LEAN_PATH="/research-stack/0-Core-Formalism/lean/Semantics" echo "[*] Starting socket server..." /research-stack/bin/socket-server & SERVER_PID=$! echo -e "${GREEN}[NANO-KERNEL] Boot complete${NC}" echo "============================================" echo "IP: $(ip addr show eth0 2>/dev/null | grep 'inet ' | awk '{print $2}' | cut -d/ -f1 || ip addr show ens3 2>/dev/null | grep 'inet ' | awk '{print $2}' | cut -d/ -f1 || echo 'UNKNOWN')" echo "Port: 8220" echo "Commands: status, lake_build, eval_lean, swarm_probe, shutdown" echo "============================================" # Keep init alive and handle signals trap "echo '[NANO-KERNEL] Shutting down...'; kill $SERVER_PID 2>/dev/null; exit 0" TERM INT # Wait for socket server wait $SERVER_PID # If socket server exits, keep system running for debugging echo -e "${YELLOW}[!] Socket server exited, entering maintenance shell${NC}" exec /bin/sh