#!/bin/bash
# Portable Ruby environment setup
RUBY_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/ruby-3.4.3-portable" && pwd)"
RUBY_BIN="$RUBY_DIR/bin"
export PATH="$RUBY_BIN:$PATH"
export GEM_HOME="$RUBY_DIR/gems"
export GEM_PATH="$GEM_HOME"
export RUBYLIB="$RUBY_DIR/lib:$RUBYLIB"
if [ "$(uname)" = "Darwin" ]; then
    # Remove quarantine attribute on macOS
    # This is necessary to avoid the "ruby is damaged and can't be opened" error when running the ruby interpreter for the first time
    if grep -q "com.apple.quarantine" <<< "$(xattr "$RUBY_BIN/ruby")"; then
        xattr -d com.apple.quarantine "$RUBY_BIN/ruby"
    fi
    export DYLD_LIBRARY_PATH="$RUBY_DIR/lib${DYLD_LIBRARY_PATH:+:$DYLD_LIBRARY_PATH}"
else
    export LD_LIBRARY_PATH="$RUBY_DIR/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
fi
