#!/usr/bin/env bash # # Compile every cBot/indicator project in src/ into .algo files — on Linux, with # no Windows and no cTrader desktop app. The .algo files are collected into dist/. # # Usage: ./scripts/build.sh [Release|Debug] # defaults to Release # set -euo pipefail REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" CONFIG="${1:-Release}" # Pick up the locally-installed SDK (see scripts/install-dotnet.sh). export DOTNET_ROOT="${DOTNET_ROOT:-$HOME/.dotnet}" export PATH="$DOTNET_ROOT:$PATH" export DOTNET_CLI_TELEMETRY_OPTOUT=1 export DOTNET_NOLOGO=1 if ! command -v dotnet >/dev/null 2>&1; then echo "dotnet not found. Run ./scripts/install-dotnet.sh first." >&2 exit 1 fi SLN="$REPO_ROOT/cTraderBots.sln" if [[ ! -f "$SLN" ]]; then echo ">> Creating solution and adding projects..." dotnet new sln --name cTraderBots --output "$REPO_ROOT" find "$REPO_ROOT/src" -name '*.csproj' -print0 \ | xargs -0 -I{} dotnet sln "$SLN" add {} fi echo ">> Building ($CONFIG)..." dotnet build "$SLN" --configuration "$CONFIG" DIST="$REPO_ROOT/dist" mkdir -p "$DIST" # Collect artifacts. cTrader.Automate names the raw .algo after the project's parent # folder (which collides across bots), so rename each to .algo here. while IFS= read -r -d '' csproj; do name="$(basename "${csproj%.csproj}")" algo="$(find "$(dirname "$csproj")/bin/$CONFIG" -name '*.algo' 2>/dev/null | head -1)" if [[ -n "$algo" ]]; then cp -v "$algo" "$DIST/$name.algo" fi done < <(find "$REPO_ROOT/src" -name '*.csproj' -print0) echo echo ">> .algo artifacts in $DIST:" ls -1 "$DIST"/*.algo 2>/dev/null || echo " (none found — check the build output above)"