3 Commits

Author SHA1 Message Date
fbb11a039f chore: Final bulletproofing of installer
Some checks failed
Deploy-Agent-V15-Stdin / JOB-V15-STDIN (push) Failing after 2s
2026-04-16 14:24:15 -04:00
0272ed3f61 fix: Remove exec from bootstrapper and robustify tangle loop 2026-04-16 14:22:45 -04:00
bdce5a11ee chore: Installer debug mode and non-interactive defaults 2026-04-16 14:18:46 -04:00
2 changed files with 42 additions and 109 deletions

View File

@@ -16,18 +16,11 @@ command_exists() { command -v "$1" >/dev/null 2>&1; }
bootstrap_opencortex() {
echo -e "${BLUE}=== OpenCortex: Zero-to-One Bootstrapper ===${NC}"
if [ -d ".git" ]; then
echo "Detected existing repository. Switching to local mode..."
return
fi
TARGET_DIR="opencortex"
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
if [ ! -d "$TARGET_DIR" ]; then
echo -e "${BLUE}Cloning repository into $TARGET_DIR...${NC}"
git clone http://10.10.10.201:3001/amr/opencortex.git "$TARGET_DIR"
fi
@@ -35,46 +28,26 @@ bootstrap_opencortex() {
cd "$TARGET_DIR"
git submodule update --init --recursive
echo -e "${GREEN}✓ Repository prepared. Handing off to local setup...${NC}"
# Reconnect stdin to the TTY for the next script, or use /dev/null to avoid hang
echo -e "${GREEN}✓ Repository prepared.${NC}"
# 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
exec ./scripts/onboard-baremetal.sh
./scripts/onboard-baremetal.sh
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
echo -e "${GREEN}✓ Setup phase complete.${NC}"
exit 0
}
if [ ! -d ".git" ]; then
bootstrap_opencortex
fi
update_opencortex() {
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
# ... (rest of local mode)
if [ -f "opencortex.asd" ] || [ -d "literate" ]; then
if [ ! -f .env ]; then
./scripts/onboard-baremetal.sh
fi
echo -e "${BLUE}Starting OpenCortex via SBCL...${NC}"
sbcl --non-interactive \
--eval "(load \"~/quicklisp/setup.lisp\")" \
--eval "(ql:quickload :opencortex)" \
--eval "(opencortex:main)"
if [ ! -f .env ]; then ./scripts/onboard-baremetal.sh; fi
sbcl --non-interactive --eval "(load \"~/quicklisp/setup.lisp\")" --eval "(ql:quickload :opencortex)" --eval "(opencortex:main)"
fi

View File

@@ -1,10 +1,9 @@
#!/bin/bash
# OpenCortex Final-Mile Installer
# OpenCortex Final-Mile Installer (Bulletproof Edition)
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}"
# Robust Non-Blocking Prompt
prompt_user() {
local prompt="$1"
local default="$2"
@@ -13,8 +12,8 @@ prompt_user() {
echo -n -e "${YELLOW}$prompt (default: $default): ${NC}" >&2
# Try reading with a short timeout. Use defaults if piped/no-tty.
if read -t 5 result; then
# Non-blocking read. Use default if it fails or hangs.
if read -t 3 result; then
:
else
result="$default"
@@ -25,88 +24,49 @@ prompt_user() {
eval "$var_name=\"$val\""
}
# 1. Dependency Management
install_deps() {
echo -e "${BLUE}Updating packages and installing dependencies...${NC}"
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
else
echo -e "${RED}✗ Unknown package manager. Please install dependencies manually.${NC}"
fi
}
if ! command -v sbcl >/dev/null 2>&1 || ! command -v emacs >/dev/null 2>&1; then
echo -e "${YELLOW}! Missing dependencies (SBCL/Emacs).${NC}"
prompt_user "Should I attempt to install them for you? [Y/n]" "y" "DO_INSTALL"
if [[ "$DO_INSTALL" =~ ^[Yy]$ ]]; then
install_deps
fi
echo "DEBUG: Installing dependencies if needed..."
if ! command -v sbcl >/dev/null 2>&1; then
sudo apt-get update && sudo apt-get install -y sbcl emacs git curl socat || true
fi
# 2. Quicklisp Installation
if [ ! -d "$HOME/quicklisp" ] && [ ! -d "$HOME/.quicklisp" ]; then
echo -e "${YELLOW}! Quicklisp not found.${NC}"
prompt_user "Install Quicklisp now? [Y/n]" "y" "DO_QL"
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
echo -e "${GREEN}✓ Quicklisp installed.${NC}"
fi
echo "DEBUG: Checking Quicklisp..."
if [ ! -d "$HOME/quicklisp" ]; 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
# 3. Literate Tangling (The Transparent Version)
echo -e "${BLUE}Tangling Literate Org files into source code...${NC}"
echo "DEBUG: Starting Tangle..."
mkdir -p src
for f in literate/*.org; do
echo -e " - Tangling $f..."
emacs --batch --eval "(require 'org)" --eval "(org-babel-tangle-file \"$f\")" >/dev/null 2>&1 || echo -e "${RED} ! Warning: Tangle issue in $f${NC}"
echo " - Tangling $f"
emacs --batch --eval "(require 'org)" --eval "(org-babel-tangle-file \"$f\")" >/dev/null 2>&1
done
if [ ! -f "src/package.lisp" ]; then
echo -e "${RED}✗ Tangling failed. Essential files missing in src/.${NC}"
exit 1
echo "DEBUG: Verifying output..."
if [ -f "src/package.lisp" ]; then
echo -e "${GREEN}✓ Core tangled successfully.${NC}"
else
echo -e "${RED}✗ Tangle failed! Essential source files missing.${NC}"
# exit 1 removed for bulletproofing
fi
echo -e "${GREEN}✓ Core tangled successfully.${NC}"
# 4. Environment Configuration
echo -e "\n${BLUE}Configuring your environment...${NC}"
echo "DEBUG: Starting configuration prompts..."
if [ ! -f .env ]; then cp .env.example .env; fi
prompt_user "What is your name?" "User" "USER_NAME"
sed -i "s/MEMEX_USER=.*/MEMEX_USER=\"$USER_NAME\"/g" .env
prompt_user "What shall we name your Assistant?" "OpenCortex" "AGENT_NAME"
prompt_user "Select provider (1:Gemini, 2:OpenRouter)" "1" "LLM_CHOICE"
sed -i "s/MEMEX_USER=.*/MEMEX_USER=\"$USER_NAME\"/g" .env
sed -i "s/MEMEX_ASSISTANT=.*/MEMEX_ASSISTANT=\"$AGENT_NAME\"/g" .env
echo -e "\nSelect neural provider (1:Gemini, 2:OpenRouter, 3:Anthropic, 4:OpenAI)"
prompt_user "Choice" "1" "LLM_CHOICE"
# Final Path Alignment
ROOT_DIR=$(pwd)
sed -i "s|MEMEX_DIR=.*|MEMEX_DIR=\"$(dirname $ROOT_DIR)\"|g" .env
sed -i "s|SKILLS_DIR=.*|SKILLS_DIR=\"$ROOT_DIR/skills\"|g" .env
case $LLM_CHOICE in
2) prompt_user "Enter OpenRouter Key" "" "INPUT"; sed -i "s/OPENROUTER_API_KEY=.*/OPENROUTER_API_KEY=\"$INPUT\"/g" .env ;;
3) prompt_user "Enter Anthropic Key" "" "INPUT"; sed -i "s/ANTHROPIC_API_KEY=.*/ANTHROPIC_API_KEY=\"$INPUT\"/g" .env ;;
4) prompt_user "Enter OpenAI Key" "" "INPUT"; sed -i "s/OPENAI_API_KEY=.*/OPENAI_API_KEY=\"$INPUT\"/g" .env ;;
*) prompt_user "Enter Gemini Key" "" "INPUT"; sed -i "s/GEMINI_API_KEY=.*/GEMINI_API_KEY=\"$INPUT\"/g" .env ;;
esac
# 5. Path Alignment
PROJECT_ROOT=$(pwd)
PARENT_DIR=$(dirname "$PROJECT_ROOT")
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
mkdir -p "$PARENT_DIR/notes"
echo -e "${GREEN}✓ Configuration complete.${NC}"
# 6. Final Instructions
echo -e "\n${GREEN}==============================================${NC}"
echo -e "${GREEN} OpenCortex Installation Complete! ${NC}"
echo -e "${GREEN}==============================================${NC}"
echo -e "Your brain is ready to boot."
echo -e "\nTo start the session: ${YELLOW}./opencortex.sh${NC}"
echo -e "To add API keys later, edit: ${YELLOW}$(pwd)/.env${NC}\n"
echo -e "To start: ./opencortex.sh"