#!/bin/bash # Setuper script for A/D Infrastructure # Installs and configures: Packmate, moded_distructive_farm, Firegex # Don't exit on error - we want to continue even if API registration fails set +e SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" SERVICES_DIR="${SERVICES_DIR:-$SCRIPT_DIR/../services}" CONTROLLER_API="${CONTROLLER_API:-http://localhost:8001}" SECRET_TOKEN="${SECRET_TOKEN:-change-me-in-production}" echo "=== A/D Infrastructure Setuper ===" echo "Services directory: $SERVICES_DIR" echo "" # Create services directory mkdir -p "$SERVICES_DIR" # Function to call controller API call_api() { local endpoint="$1" local method="${2:-GET}" local data="${3:-}" if [ "$method" = "POST" ]; then curl -s -X POST "$CONTROLLER_API$endpoint" \ -H "Authorization: Bearer $SECRET_TOKEN" \ -H "Content-Type: application/json" \ -d "$data" else curl -s "$CONTROLLER_API$endpoint" \ -H "Authorization: Bearer $SECRET_TOKEN" fi } # Function to setup Packmate setup_packmate() { echo "=== Setting up Packmate ===" local packmate_dir="$SERVICES_DIR/packmate" if [ -d "$packmate_dir" ]; then echo "Packmate directory already exists, updating..." cd "$packmate_dir" git pull git submodule update --init --recursive else echo "Cloning Packmate with submodules..." git clone --recursive https://gitlab.com/packmate/Packmate.git "$packmate_dir" cd "$packmate_dir" fi # Create necessary directories mkdir -p pcaps rsa_keys Packmate_stuff # Create .env file cat > .env < Packmate_stuff/postgresql.conf < Packmate_stuff/update_db_config.sh <<'EOF' #!/bin/bash cp /tmp/postgresql.conf /var/lib/postgresql/data/postgresql.conf EOF chmod +x Packmate_stuff/update_db_config.sh # Create docker-compose.yml cat > docker-compose.yml </dev/null; then echo "✓ Packmate registered with controller" else echo "⚠ Warning: Could not register with controller (is it running?)" echo " You can register manually later via the web dashboard" fi cd "$SCRIPT_DIR" } # Function to setup moded_distructive_farm setup_farm() { echo "" echo "=== Setting up moded_distructive_farm ===" local farm_dir="$SERVICES_DIR/moded_distructive_farm" if [ -d "$farm_dir" ]; then echo "Farm directory already exists, updating..." cd "$farm_dir" git pull else echo "Cloning moded_distructive_farm..." git clone https://github.com/ilyastar9999/moded_distructive_farm.git "$farm_dir" cd "$farm_dir" fi # Create .env file cat > .env < docker-compose.yml </dev/null; then echo "✓ Farm registered with controller" else echo "⚠ Warning: Could not register with controller (is it running?)" echo " You can register manually later via the web dashboard" fi cd "$SCRIPT_DIR" # Register with controller echo "Registering farm with controller..." call_api "/services" "POST" "{\"name\": \"farm\", \"path\": \"$farm_dir\", \"git_url\": \"https://github.com/ilyastar9999/moded_distructive_farm.git\"}" cd "$SCRIPT_DIR" } # Function to setup Firegex setup_firegex() { echo "" echo "=== Setting up Firegex ===" local firegex_dir="$SERVICES_DIR/firegex" if [ -d "$firegex_dir" ]; then echo "Firegex directory already exists, updating..." cd "$firegex_dir" git pull else echo "Cloning Firegex..." git clone https://github.com/Pwnzer0tt1/firegex.git "$firegex_dir" cd "$firegex_dir" fi # Create .env file cat > .env < docker-compose.yml </dev/null; then echo "✓ Firegex registered with controller" else echo "⚠ Warning: Could not register with controller (is it running?)" echo " You can register manually later via the web dashboard" fi cd "$SCRIPT_DIR" # Register with controller echo "Registering Firegex with controller..." call_api "/services" "POST" "{\"name\": \"firegex\", \"path\": \"$firegex_dir\", \"git_url\": \"https://github.com/Pwnzer0tt1/firegex.git\"}" cd "$SCRIPT_DIR" } # Main setup flow main() { echo "Starting setup process..." echo "" # Read configuration read -p "Setup Packmate? (y/n): " setup_pm read -p "Setup moded_distructive_farm? (y/n): " setup_fm read -p "Setup Firegex? (y/n): " setup_fg echo "" if [ "$setup_pm" = "y" ]; then setup_packmate echo "" echo "=== Setup Complete! ===" echo "Services have been configured in: $SERVICES_DIR" echo "" echo "Next steps:" echo " 1. Start the infrastructure: docker-compose up -d" echo " 2. Access web dashboard: http://localhost:8000" echo " 3. Register services via the dashboard if auto-registration failed" echo "" } fi if [ "$setup_fg" = "y" ]; then setup_firegex fi echo "" echo "=== Setup Complete! ===" echo "Services have been configured in: $SERVICES_DIR" echo "You can manage them through the controller API or web dashboard" } # Run main if executed directly if [ "${BASH_SOURCE[0]}" = "${0}" ]; then main fi