mirror of
https://github.com/trailofbits/buttercup
synced 2026-06-21 14:11:39 +00:00
95875b4ec5
Apply automated fixes from shellcheck and shfmt to all shell scripts: - Quote variables to prevent word splitting and globbing - Use $(...) instead of backticks for command substitution - Add proper shebang and set -euo pipefail where missing - Fix array handling and iteration patterns - Consistent indentation (4 spaces) - Remove unnecessary curly braces and simplify expressions Files fixed: - deployment/*.sh - scripts/*.sh - orchestrator/scripts/*.sh - fuzzer_runner/runner.sh - protoc.sh Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
77 lines
3.6 KiB
Bash
Executable File
77 lines
3.6 KiB
Bash
Executable File
#!/bin/bash -xe
|
|
|
|
OUTPUT_DIR=$1
|
|
|
|
# Ensure python3.12 is installed
|
|
PYTHON_CMD="python3.12"
|
|
if ! command -v python3.12 &> /dev/null
|
|
then
|
|
# Test if python refers to python3.12
|
|
if ! python3 --version | grep "Python 3.12" &> /dev/null
|
|
then
|
|
echo "Python 3.12 is not installed"
|
|
exit 1
|
|
fi
|
|
PYTHON_CMD="python3"
|
|
fi
|
|
|
|
# Get script path
|
|
SCRIPT_PATH=$(realpath "$0")
|
|
SCRIPT_DIR=$(dirname "$SCRIPT_PATH")
|
|
PROJECT_DIR=$(dirname "$SCRIPT_DIR")
|
|
|
|
cd "$PROJECT_DIR" || exit 1
|
|
|
|
# Clone the repo, but ignore LFS files to avoid downloading large files
|
|
GIT_LFS_SKIP_SMUDGE=1 git clone git@github.com:tob-challenges/example-crs-architecture.git || true
|
|
git -C example-crs-architecture pull
|
|
|
|
cp -rv example-crs-architecture/docs/ "$OUTPUT_DIR/src/buttercup/orchestrator/docs/"
|
|
|
|
TEMPDIR=$(mktemp -d)
|
|
$PYTHON_CMD -m venv "$TEMPDIR/venv"
|
|
. "$TEMPDIR/venv/bin/activate"
|
|
|
|
# Update competition API client
|
|
# Run docker with current user to ensure correct file permissions
|
|
USER_ID=$(id -u)
|
|
GROUP_ID=$(id -g)
|
|
docker run --rm --user "$USER_ID:$GROUP_ID" -v "$(realpath example-crs-architecture/docs/api):/local" -v "$OUTPUT_DIR/src/buttercup/orchestrator:/out" openapitools/openapi-generator-cli generate \
|
|
-i /local/competition-swagger-v1.4.0.json \
|
|
-g python \
|
|
-o /out \
|
|
--package-name competition_api_client
|
|
|
|
find "$OUTPUT_DIR/src/buttercup/orchestrator" -name '*.py' -exec sed -i.bak 's/^from competition_api_client/from buttercup.orchestrator.competition_api_client/' {} +
|
|
find "$OUTPUT_DIR/src/buttercup/orchestrator" -name '*.py' -exec sed -i.bak 's/competition_api_client.models,/buttercup.orchestrator.competition_api_client.models,/' {} +
|
|
find "$OUTPUT_DIR/src/buttercup/orchestrator" -name '*.py' -exec sed -i.bak 's/^import competition_api_client/import buttercup.orchestrator.competition_api_client/' {} +
|
|
find "$OUTPUT_DIR/src/buttercup/orchestrator" -name '*.md' -exec sed -i.bak 's/^from competition_api_client/from buttercup.orchestrator.competition_api_client/' {} +
|
|
find "$OUTPUT_DIR/src/buttercup/orchestrator" -name '*.md' -exec sed -i.bak 's/^import competition_api_client./import buttercup.orchestrator.competition_api_client./' {} +
|
|
|
|
mkdir -p "$OUTPUT_DIR/docs"
|
|
mkdir -p "$OUTPUT_DIR/test"
|
|
cp -rv "$OUTPUT_DIR"/src/buttercup/orchestrator/docs/* "$OUTPUT_DIR/docs/"
|
|
cp -rv "$OUTPUT_DIR"/src/buttercup/orchestrator/test/* "$OUTPUT_DIR/test/"
|
|
rm -rf "$OUTPUT_DIR/src/buttercup/orchestrator/docs"
|
|
rm -rf "$OUTPUT_DIR/src/buttercup/orchestrator/test"
|
|
|
|
# Update task_server APIs
|
|
uv pip install --isolated git+https://github.com/trail-of-forks/fastapi-code-generator uvicorn fastapi
|
|
|
|
TEMPDIR=$(mktemp -d)
|
|
curl -o "$TEMPDIR/openapi.json" -X POST https://converter.swagger.io/api/convert -H "Content-Type: application/json" --data-binary "@example-crs-architecture/docs/api/crs-swagger-v1.4.0.json"
|
|
|
|
fastapi-codegen --input "$TEMPDIR/openapi.json" --output "$OUTPUT_DIR/src/buttercup/orchestrator/task_server"
|
|
|
|
mv "$OUTPUT_DIR/src/buttercup/orchestrator/task_server/main.py" "$OUTPUT_DIR/src/buttercup/orchestrator/task_server/server.py"
|
|
|
|
# replace `from .models` with `from orchestrator.task_server.models` in server.py
|
|
sed -i.bak 's/from .models/from buttercup.orchestrator.task_server.models/g' "$OUTPUT_DIR/src/buttercup/orchestrator/task_server/server.py"
|
|
# remove `from uuid import UUID` and replace UUID with str
|
|
sed -i.bak '/from uuid import UUID/d' "$OUTPUT_DIR/src/buttercup/orchestrator/task_server/models/types.py"
|
|
sed -i.bak 's/UUID/str/g' "$OUTPUT_DIR/src/buttercup/orchestrator/task_server/models/types.py"
|
|
|
|
echo "Look at server.py and adjust as needed (HTTP auth, etc.)"
|
|
|
|
rm -rf "$TEMPDIR"
|