From c889fe1ceaff4a24c2ad2f490ca708e2a61cb26e Mon Sep 17 00:00:00 2001 From: Amr Gharbeia Date: Fri, 17 Apr 2026 17:38:37 -0400 Subject: [PATCH] fix(setup): Make SCRIPT_DIR symlink-aware and harden bootstrapper logic --- literate/setup.org | 12 ++++++++++-- opencortex.sh | 12 ++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/literate/setup.org b/literate/setup.org index bf58069..d311213 100644 --- a/literate/setup.org +++ b/literate/setup.org @@ -15,10 +15,18 @@ HOST=${1:-localhost} RED='\033[0;31m'; GREEN='\033[0;32m'; BLUE='\033[0;34m'; YELLOW='\033[0;33m'; NC='\033[0m' command_exists() { command -v "$1" >/dev/null 2>&1; } -SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" +# Resolve symlinks to find the actual repository location +SOURCE="${BASH_SOURCE[0]}" +while [ -h "$SOURCE" ]; do + DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" + SOURCE="$(readlink "$SOURCE")" + [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" +done +SCRIPT_DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" # --- 1. BOOTSTRAP --- -if [ ! -d "$SCRIPT_DIR/.git" ] && [[ ! "$(pwd)" =~ "opencortex" ]]; then +# Only bootstrap if we are not in a git repo and the target hidden folder does not exist +if [ ! -d "$SCRIPT_DIR/.git" ] && [ ! -d "$HOME/.opencortex" ] && [[ ! "$(pwd)" =~ "opencortex" ]]; then echo -e "${BLUE}=== OpenCortex: Zero-to-One Bootstrapper ===${NC}" git clone http://10.10.10.201:3001/amr/opencortex.git ~/.opencortex cd ~/.opencortex && git submodule update --init --recursive diff --git a/opencortex.sh b/opencortex.sh index 105ce49..17e343a 100755 --- a/opencortex.sh +++ b/opencortex.sh @@ -6,10 +6,18 @@ HOST=${1:-localhost} RED='\033[0;31m'; GREEN='\033[0;32m'; BLUE='\033[0;34m'; YELLOW='\033[0;33m'; NC='\033[0m' command_exists() { command -v "$1" >/dev/null 2>&1; } -SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" +# Resolve symlinks to find the actual repository location +SOURCE="${BASH_SOURCE[0]}" +while [ -h "$SOURCE" ]; do + DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" + SOURCE="$(readlink "$SOURCE")" + [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" +done +SCRIPT_DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" # --- 1. BOOTSTRAP --- -if [ ! -d "$SCRIPT_DIR/.git" ] && [[ ! "$(pwd)" =~ "opencortex" ]]; then +# Only bootstrap if we are not in a git repo and the target hidden folder does not exist +if [ ! -d "$SCRIPT_DIR/.git" ] && [ ! -d "$HOME/.opencortex" ] && [[ ! "$(pwd)" =~ "opencortex" ]]; then echo -e "${BLUE}=== OpenCortex: Zero-to-One Bootstrapper ===${NC}" git clone http://10.10.10.201:3001/amr/opencortex.git ~/.opencortex cd ~/.opencortex && git submodule update --init --recursive