Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ services:
environment:
TELEGRAM_TOKEN: ${TELEGRAM_TOKEN}
ADMIN_USER_ID: ${ADMIN_USER_ID}
# Where to store the bot persistence file inside the container
CONDOR_PERSISTENCE_FILE: /app/data/condor_bot_data.pickle
env_file:
- .env
volumes:
# Persist bot data (user preferences, trading context, etc.)
- ./condor_bot_data.pickle:/app/condor_bot_data.pickle
# The pickle file will be created as /app/data/condor_bot_data.pickle.
- ./data:/app/data
# Mount config (servers, users, permissions)
- ./config.yml:/app/config.yml
# Mount routines for auto-discovery
Expand Down
105 changes: 79 additions & 26 deletions setup-environment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,19 @@

# Configuration
ENV_FILE=".env"
CONFIG_FILE="config.yml"
DATA_DIR="data"

# Escape special characters for .env file
escape_env_value() {
local value="$1"
# Escape backslashes, double quotes, and dollar signs
value="${value//\\/\\\\}"
value="${value//\"/\\\"}"
value="${value//\$/\\\$}"
echo "$value"
}

echo "==================================="
echo " Condor Bot Setup"
echo "==================================="
Expand All @@ -15,33 +26,66 @@ if [ -f "$ENV_FILE" ]; then
echo ">> Credentials already exist. Skipping setup params."
echo ""
else
# 2. Prompt for Telegram Bot Token
# 2. Prompt for Telegram Bot Token with validation
echo ""
read -p "Enter your Telegram Bot Token: " telegram_token
while true; do
echo -n "Enter your Telegram Bot Token: "
read -r telegram_token < /dev/tty || telegram_token=""
telegram_token=$(echo "$telegram_token" | tr -d '[:space:]')

if [ -z "$telegram_token" ]; then
echo "⚠️ Telegram Bot Token cannot be empty. Please try again."
continue
fi

# Validate token format: digits:alphanumeric
if ! [[ "$telegram_token" =~ ^[0-9]+:[A-Za-z0-9_-]+$ ]]; then
echo "⚠️ Invalid Telegram Bot Token format."
echo " Expected format: 123456789:ABCdefGHIjklMNOpqrsTUVwxyz"
echo " Please enter a valid token."
continue
fi

break
done

# 3. Prompt for Admin User ID
# 3. Prompt for Admin User ID with validation
echo ""
echo "Enter your Telegram User ID (you will be the admin)."
echo "(Tip: Message @userinfobot on Telegram to get your ID)"
read -p "Admin User ID: " admin_id
while true; do
echo -n "Admin User ID: "
read -r admin_id < /dev/tty || admin_id=""
admin_id=$(echo "$admin_id" | tr -d '[:space:]')

if [ -z "$admin_id" ]; then
echo "⚠️ Admin User ID cannot be empty. Please try again."
continue
fi

# Validate user ID is numeric
if ! [[ "$admin_id" =~ ^[0-9]+$ ]]; then
echo "⚠️ Invalid User ID. User ID should be numeric (e.g., 123456789)."
continue
fi

break
done

# 4. Prompt for OpenAI API Key (optional)
echo ""
echo "Enter your OpenAI API Key (optional, for AI features)."
echo "Press Enter to skip if not using AI features."
read -p "OpenAI API Key: " openai_key

# Clean whitespaces from inputs
telegram_token=$(echo "$telegram_token" | tr -d '[:space:]')
admin_id=$(echo "$admin_id" | tr -d '[:space:]')
echo -n "OpenAI API Key: "
read -r openai_key < /dev/tty || openai_key=""
openai_key=$(echo "$openai_key" | tr -d '[:space:]')

# 5. Create .env file
# 5. Create .env file with escaped values
{
echo "TELEGRAM_TOKEN=$telegram_token"
echo "ADMIN_USER_ID=$admin_id"
echo "TELEGRAM_TOKEN=$(escape_env_value "$telegram_token")"
echo "ADMIN_USER_ID=$(escape_env_value "$admin_id")"
if [ -n "$openai_key" ]; then
echo "OPENAI_API_KEY=$openai_key"
echo "OPENAI_API_KEY=$(escape_env_value "$openai_key")"
fi
} > "$ENV_FILE"

Expand All @@ -55,17 +99,26 @@ if [ ! -d "$DATA_DIR" ]; then
mkdir -p "$DATA_DIR"
fi

# 7. Display Run Instructions
echo "==================================="
echo " How to Run Condor"
echo "==================================="
echo ""
echo "Option 1: Docker (Recommended)"
echo " make deploy"
echo ""
echo "Option 2: Local Python"
echo " make run"
# 7. Create blank config.yml if it doesn't exist
if [ -f "$CONFIG_FILE" ]; then
echo ""
echo ">> Found existing $CONFIG_FILE file."
echo ">> Configuration already exists."
else
echo ""
echo "Creating blank $CONFIG_FILE file..."
touch "$CONFIG_FILE"
echo "✅ $CONFIG_FILE created successfully!"
echo ""
echo "Note: You can add Hummingbot API servers and manage access"
echo " using the /config command in your Telegram bot."
fi

# 8. Display Run Instructions
echo ""
echo "On first run, config.yml will be auto-created."
echo "Use /config in the bot to add servers and manage access."
echo "==================================="
echo "✅ Setup Complete! Environment and config files are ready."
echo "=========================================================="
echo "🚀 RUN: 'make deploy' (Docker) or 'make run' (Local)"
echo "🛠️ CMDS: make stop, restart, logs, ps, install"
echo "🤖 NEXT: Open Telegram, use /servers to add API servers"
echo "=========================================================="