install.sh
#!/bin/bash

RED='\033[0;31m'
NC='\033[0m'

PY_VERSION="3.10"
CITADEL_DIR="~/.citadel"
CWD=$(pwd)

log_error() {
    echo -e "${RED}[ERROR]${NC} $1"
}

install_citadel() {
    if [ -d ".venv" ]; then
        return
    fi
    
    uv venv .venv
    source .venv/bin/activate
    uv pip install -e .
}

install_radare2() {
    if [ -f "/usr/local/bin/r2" ]; then
        return
    fi

    curl -Ls https://github.com/radareorg/radare2/releases/download/5.9.6/radare2-5.9.6.tar.xz | tar xJv
    radare2-5.9.6/sys/install.sh
}

setup_tlsh_database() {
    if [ ! -f "data/tlsh.tar.gz" ]; then
        log_error "TLSH database file not found at data/tlsh.tar.gz"
        return
    fi
    
    tar -xvf data/tlsh.tar.gz

    mongoimport --db citadel --collection tlsh --file tlsh.jsonl
}

install_uv() {
    if command -v uv &> /dev/null; then
        return
    fi
    curl -LsSf https://astral.sh/uv/install.sh | sh
}

install_mongodb() {
    if command -v mongod &> /dev/null; then
        return
    fi
    
    wget https://repo.mongodb.org/apt/ubuntu/dists/noble/mongodb-org/8.2/multiverse/binary-amd64/mongodb-org-server_8.2.1_amd64.deb -O /tmp/mongo.deb
    wget https://fastdl.mongodb.org/tools/db/mongodb-database-tools-ubuntu2404-x86_64-100.13.0.tgz -O /tmp/mongo-tools.tgz
    
    if [ -f "/tmp/mongo.deb" ]; then
        sudo apt install -y /tmp/mongo.deb
        rm -rf /tmp/mongo.deb
        sudo systemctl start mongod.service
        sudo systemctl enable mongod.service
    else
        log_error "MongoDB deb file not found at /tmp/mongo.deb"
    fi
    
    if [ -f "/tmp/mongo-tools.tgz" ]; then
        cd /tmp
        tar -xvf /tmp/mongo-tools.tgz
        sudo mv mongodb-database-tools-ubuntu2404-x86_64-100.13.0/bin/* /usr/bin/
        rm -rf /tmp/mongo-tools.tgz mongodb-database-tools-ubuntu2404-x86_64-100.13.0
        chmod +x /usr/bin/mongo*
        cd "$CWD"
    else
        log_error "MongoDB tools tar file not found at /tmp/mongo-tools.tgz"
    fi
}

pull_yara_rules() {
    bash scripts/pull-yara-rules.sh
}

install_uv
install_radare2
install_citadel
setup_tlsh_database