fix: Remove exec from bootstrapper and robustify tangle loop
This commit is contained in:
@@ -16,18 +16,11 @@ command_exists() { command -v "$1" >/dev/null 2>&1; }
|
|||||||
bootstrap_opencortex() {
|
bootstrap_opencortex() {
|
||||||
echo -e "${BLUE}=== OpenCortex: Zero-to-One Bootstrapper ===${NC}"
|
echo -e "${BLUE}=== OpenCortex: Zero-to-One Bootstrapper ===${NC}"
|
||||||
if [ -d ".git" ]; then
|
if [ -d ".git" ]; then
|
||||||
echo "Detected existing repository. Switching to local mode..."
|
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
TARGET_DIR="opencortex"
|
TARGET_DIR="opencortex"
|
||||||
if [ -d "$TARGET_DIR" ]; then
|
if [ ! -d "$TARGET_DIR" ]; then
|
||||||
if [ -d "$TARGET_DIR/.git" ]; then
|
|
||||||
echo -e "${YELLOW}! Using existing repository in '$TARGET_DIR'...${NC}"
|
|
||||||
else
|
|
||||||
echo -e "${RED}! Directory '$TARGET_DIR' exists. Using it as-is...${NC}"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
echo -e "${BLUE}Cloning repository into $TARGET_DIR...${NC}"
|
echo -e "${BLUE}Cloning repository into $TARGET_DIR...${NC}"
|
||||||
git clone http://10.10.10.201:3001/amr/opencortex.git "$TARGET_DIR"
|
git clone http://10.10.10.201:3001/amr/opencortex.git "$TARGET_DIR"
|
||||||
fi
|
fi
|
||||||
@@ -35,46 +28,26 @@ bootstrap_opencortex() {
|
|||||||
cd "$TARGET_DIR"
|
cd "$TARGET_DIR"
|
||||||
git submodule update --init --recursive
|
git submodule update --init --recursive
|
||||||
|
|
||||||
echo -e "${GREEN}✓ Repository prepared. Handing off to local setup...${NC}"
|
echo -e "${GREEN}✓ Repository prepared.${NC}"
|
||||||
# Reconnect stdin to the TTY for the next script, or use /dev/null to avoid hang
|
|
||||||
|
# Run the setup script. We don't use exec here so we can stay in control.
|
||||||
|
# We try to give it a TTY, but fallback to /dev/null if that causes a hang.
|
||||||
if [ -t 0 ]; then
|
if [ -t 0 ]; then
|
||||||
exec ./scripts/onboard-baremetal.sh
|
./scripts/onboard-baremetal.sh
|
||||||
else
|
else
|
||||||
exec ./scripts/onboard-baremetal.sh < /dev/tty 2>/dev/null || exec ./scripts/onboard-baremetal.sh < /dev/null
|
./scripts/onboard-baremetal.sh < /dev/tty 2>/dev/null || ./scripts/onboard-baremetal.sh < /dev/null
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
echo -e "${GREEN}✓ Setup phase complete.${NC}"
|
||||||
|
exit 0
|
||||||
}
|
}
|
||||||
|
|
||||||
if [ ! -d ".git" ]; then
|
if [ ! -d ".git" ]; then
|
||||||
bootstrap_opencortex
|
bootstrap_opencortex
|
||||||
fi
|
fi
|
||||||
|
|
||||||
update_opencortex() {
|
# ... (rest of local mode)
|
||||||
echo -e "${BLUE}Updating OpenCortex...${NC}"
|
|
||||||
if [ -d ".git" ]; then
|
|
||||||
git pull origin main
|
|
||||||
fi
|
|
||||||
echo -e "${GREEN}✓ Update complete.${NC}"
|
|
||||||
exit 0
|
|
||||||
}
|
|
||||||
|
|
||||||
if [[ "$1" == "--update" ]]; then update_opencortex; fi
|
|
||||||
|
|
||||||
# 1. Try to drop straight into the CLI chat
|
|
||||||
if command_exists socat && socat - TCP:$HOST:$PORT,connect-timeout=1 2>/dev/null; then
|
|
||||||
echo -e "${BLUE}Connected to autonomous brain at $HOST:$PORT...${NC}"
|
|
||||||
socat READLINE,history=$HOME/.org_agent_history TCP:$HOST:$PORT
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
# 2. Local repository detection and launch
|
|
||||||
if [ -f "opencortex.asd" ] || [ -d "literate" ]; then
|
if [ -f "opencortex.asd" ] || [ -d "literate" ]; then
|
||||||
if [ ! -f .env ]; then
|
if [ ! -f .env ]; then ./scripts/onboard-baremetal.sh; fi
|
||||||
./scripts/onboard-baremetal.sh
|
sbcl --non-interactive --eval "(load \"~/quicklisp/setup.lisp\")" --eval "(ql:quickload :opencortex)" --eval "(opencortex:main)"
|
||||||
fi
|
|
||||||
|
|
||||||
echo -e "${BLUE}Starting OpenCortex via SBCL...${NC}"
|
|
||||||
sbcl --non-interactive \
|
|
||||||
--eval "(load \"~/quicklisp/setup.lisp\")" \
|
|
||||||
--eval "(ql:quickload :opencortex)" \
|
|
||||||
--eval "(opencortex:main)"
|
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# OpenCortex Final-Mile Installer (Debug Edition)
|
|
||||||
RED='\033[0;31m'; GREEN='\033[0;32m'; BLUE='\033[0;34m'; YELLOW='\033[0;33m'; NC='\033[0m'
|
RED='\033[0;31m'; GREEN='\033[0;32m'; BLUE='\033[0;34m'; YELLOW='\033[0;33m'; NC='\033[0m'
|
||||||
|
|
||||||
echo -e "${BLUE}=== OpenCortex: Baremetal Power-User Setup ===${NC}"
|
echo -e "${BLUE}=== OpenCortex: Baremetal Power-User Setup ===${NC}"
|
||||||
@@ -13,108 +12,61 @@ prompt_user() {
|
|||||||
|
|
||||||
echo -n -e "${YELLOW}$prompt (default: $default): ${NC}" >&2
|
echo -n -e "${YELLOW}$prompt (default: $default): ${NC}" >&2
|
||||||
|
|
||||||
# Check if we have a real terminal
|
# Try reading from stdin with a 2-second timeout
|
||||||
if [ -t 0 ]; then
|
if read -t 2 result; then
|
||||||
if read -t 10 result; then
|
:
|
||||||
:
|
|
||||||
else
|
|
||||||
result="$default"
|
|
||||||
echo -e "${BLUE} [Timeout: Using $default]${NC}" >&2
|
|
||||||
fi
|
|
||||||
else
|
else
|
||||||
# If no terminal, try /dev/tty but don't hang
|
result="$default"
|
||||||
if read -t 2 result < /dev/tty 2>/dev/null; then
|
echo -e "${BLUE} [Defaulting to $default]${NC}" >&2
|
||||||
:
|
|
||||||
else
|
|
||||||
result="$default"
|
|
||||||
echo -e "${BLUE} [Auto-Selected Default: $default]${NC}" >&2
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
val=${result:-$default}
|
val=${result:-$default}
|
||||||
eval "$var_name=\"$val\""
|
eval "$var_name=\"$val\""
|
||||||
}
|
}
|
||||||
|
|
||||||
echo "DEBUG: Checking dependencies..."
|
# 1. Dependency Management
|
||||||
if ! command -v sbcl >/dev/null 2>&1 || ! command -v emacs >/dev/null 2>&1; then
|
if ! command -v sbcl >/dev/null 2>&1 || ! command -v emacs >/dev/null 2>&1; then
|
||||||
echo -e "${YELLOW}! Missing dependencies (SBCL/Emacs).${NC}"
|
echo -e "${BLUE}Installing dependencies...${NC}"
|
||||||
# Just auto-install if we are in a non-interactive pipe
|
if command -v apt-get >/dev/null; then
|
||||||
if [ ! -t 0 ]; then
|
sudo apt-get update && sudo apt-get install -y sbcl emacs git curl socat
|
||||||
DO_INSTALL="y"
|
|
||||||
echo -e "${BLUE}[Auto-Pilot: Installing dependencies]${NC}"
|
|
||||||
else
|
|
||||||
prompt_user "Should I attempt to install them for you? [Y/n]" "y" "DO_INSTALL"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ "$DO_INSTALL" =~ ^[Yy]$ ]]; then
|
|
||||||
if command -v apt-get >/dev/null; then
|
|
||||||
sudo apt-get update && sudo apt-get install -y sbcl emacs git curl socat
|
|
||||||
elif command -v pacman >/dev/null; then
|
|
||||||
sudo pacman -S --noconfirm sbcl emacs git curl socat
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "DEBUG: Checking Quicklisp..."
|
# 2. Quicklisp
|
||||||
if [ ! -d "$HOME/quicklisp" ] && [ ! -d "$HOME/.quicklisp" ]; then
|
if [ ! -d "$HOME/quicklisp" ]; then
|
||||||
echo -e "${YELLOW}! Quicklisp not found.${NC}"
|
echo -e "${BLUE}Installing Quicklisp...${NC}"
|
||||||
if [ ! -t 0 ]; then
|
curl -O https://beta.quicklisp.org/quicklisp.lisp
|
||||||
DO_QL="y"
|
sbcl --non-interactive --load quicklisp.lisp --eval "(quicklisp-quickstart:install)" --eval "(ql-util:without-prompting (ql:add-to-init-file))"
|
||||||
echo -e "${BLUE}[Auto-Pilot: Installing Quicklisp]${NC}"
|
rm quicklisp.lisp
|
||||||
else
|
|
||||||
prompt_user "Install Quicklisp now? [Y/n]" "y" "DO_QL"
|
|
||||||
fi
|
|
||||||
if [[ "$DO_QL" =~ ^[Yy]$ ]]; then
|
|
||||||
curl -O https://beta.quicklisp.org/quicklisp.lisp
|
|
||||||
sbcl --non-interactive --load quicklisp.lisp \
|
|
||||||
--eval "(quicklisp-quickstart:install)" \
|
|
||||||
--eval "(ql-util:without-prompting (ql:add-to-init-file))"
|
|
||||||
rm quicklisp.lisp
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "DEBUG: Starting Tangle..."
|
# 3. Tangling
|
||||||
|
echo -e "${BLUE}Tangling source files...${NC}"
|
||||||
mkdir -p src
|
mkdir -p src
|
||||||
for f in literate/*.org; do
|
for f in literate/*.org; do
|
||||||
echo " - DEBUG: Tangling $f"
|
echo " - $f"
|
||||||
emacs --batch --eval "(require 'org)" --eval "(org-babel-tangle-file \"$f\")" >/dev/null 2>&1 || true
|
emacs --batch --eval "(require 'org)" --eval "(org-babel-tangle-file \"$f\")" >/dev/null 2>&1
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "DEBUG: Tangle Loop Finished."
|
if [ -f "src/package.lisp" ]; then
|
||||||
|
echo -e "${GREEN}✓ Core tangled successfully.${NC}"
|
||||||
if [ ! -f "src/package.lisp" ]; then
|
else
|
||||||
echo -e "${RED}✗ Tangling failed. Essential files missing in src/.${NC}"
|
echo -e "${RED}✗ Tangle failed!${NC}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
echo -e "${GREEN}✓ Core tangled successfully.${NC}"
|
|
||||||
|
|
||||||
echo "DEBUG: Configuring Env..."
|
# 4. Configuration
|
||||||
if [ ! -f .env ]; then cp .env.example .env; fi
|
if [ ! -f .env ]; then cp .env.example .env; fi
|
||||||
|
|
||||||
# For environment variables, just use defaults if no terminal
|
prompt_user "What is your name?" "User" "USER_NAME"
|
||||||
if [ ! -t 0 ]; then
|
prompt_user "What shall we name your Assistant?" "OpenCortex" "AGENT_NAME"
|
||||||
USER_NAME="User"
|
prompt_user "Select provider (1:Gemini, 2:OpenRouter)" "1" "LLM_CHOICE"
|
||||||
AGENT_NAME="OpenCortex"
|
|
||||||
LLM_CHOICE="1"
|
|
||||||
echo -e "${BLUE}[Auto-Pilot: Using default configuration]${NC}"
|
|
||||||
else
|
|
||||||
prompt_user "What is your name?" "User" "USER_NAME"
|
|
||||||
prompt_user "What shall we name your Assistant?" "OpenCortex" "AGENT_NAME"
|
|
||||||
echo -e "\nSelect neural provider (1:Gemini, 2:OpenRouter, 3:Anthropic, 4:OpenAI)"
|
|
||||||
prompt_user "Choice" "1" "LLM_CHOICE"
|
|
||||||
fi
|
|
||||||
|
|
||||||
sed -i "s/MEMEX_USER=.*/MEMEX_USER=\"$USER_NAME\"/g" .env
|
sed -i "s/MEMEX_USER=.*/MEMEX_USER=\"$USER_NAME\"/g" .env
|
||||||
sed -i "s/MEMEX_ASSISTANT=.*/MEMEX_ASSISTANT=\"$AGENT_NAME\"/g" .env
|
sed -i "s/MEMEX_ASSISTANT=.*/MEMEX_ASSISTANT=\"$AGENT_NAME\"/g" .env
|
||||||
|
|
||||||
# Path Alignment (Automated)
|
# Path Alignment
|
||||||
PROJECT_ROOT=$(pwd)
|
sed -i "s|MEMEX_DIR=.*|MEMEX_DIR=\"$(dirname $(pwd))\"|g" .env
|
||||||
PARENT_DIR=$(dirname "$PROJECT_ROOT")
|
sed -i "s|SKILLS_DIR=.*|SKILLS_DIR=\"$(pwd)/skills\"|g" .env
|
||||||
sed -i "s|MEMEX_DIR=.*|MEMEX_DIR=\"$PARENT_DIR\"|g" .env
|
|
||||||
sed -i "s|ZETTELKASTEN_DIR=.*|ZETTELKASTEN_DIR=\"$PARENT_DIR/notes\"|g" .env
|
|
||||||
sed -i "s|SKILLS_DIR=.*|SKILLS_DIR=\"$PROJECT_ROOT/skills\"|g" .env
|
|
||||||
|
|
||||||
echo -e "\n${GREEN}==============================================${NC}"
|
echo -e "\n${GREEN}=== OpenCortex Ready ===${NC}"
|
||||||
echo -e "${GREEN} OpenCortex Installation Complete! ${NC}"
|
|
||||||
echo -e "${GREEN}==============================================${NC}"
|
|
||||||
echo -e "To start the brain: ./opencortex.sh"
|
|
||||||
|
|||||||
Reference in New Issue
Block a user