/ scripts / run-quantum-compression-demo.sh
run-quantum-compression-demo.sh
  1  #!/bin/bash
  2  
  3  # Run the quantum compression demo
  4  echo "Building and running quantum compression demo..."
  5  
  6  # Navigate to the project root
  7  cd "$(dirname "$0")/.."
  8  
  9  # Default values
 10  INPUT_FILE=""
 11  OUTPUT_DIR=""
 12  ALGORITHM="zstd"
 13  LEVEL="default"
 14  MIN_SIZE=1024
 15  
 16  # Parse command-line arguments
 17  while [[ $# -gt 0 ]]; do
 18    case $1 in
 19      --input=*)
 20        INPUT_FILE="${1#*=}"
 21        shift
 22        ;;
 23      --output=*)
 24        OUTPUT_DIR="${1#*=}"
 25        shift
 26        ;;
 27      --algorithm=*)
 28        ALGORITHM="${1#*=}"
 29        shift
 30        ;;
 31      --level=*)
 32        LEVEL="${1#*=}"
 33        shift
 34        ;;
 35      --min-size=*)
 36        MIN_SIZE="${1#*=}"
 37        shift
 38        ;;
 39      *)
 40        # If no named parameter, assume it's the input file
 41        if [ -z "$INPUT_FILE" ]; then
 42          INPUT_FILE="$1"
 43        fi
 44        shift
 45        ;;
 46    esac
 47  done
 48  
 49  # Check if input file is provided
 50  if [ -z "$INPUT_FILE" ]; then
 51      echo "Usage: $0 [--input=<input_file>] [--output=<output_dir>] [--algorithm=<none|gzip|zlib|zstd>] [--level=<default|speed|compression>] [--min-size=<bytes>]"
 52      echo "Example: $0 --input=test-data/sample.bin --algorithm=zstd --level=compression"
 53      exit 1
 54  fi
 55  
 56  # Check if input file exists
 57  if [ ! -f "$INPUT_FILE" ]; then
 58      echo "Input file not found: $INPUT_FILE"
 59      exit 1
 60  fi
 61  
 62  # Create output directory if not specified
 63  if [ -z "$OUTPUT_DIR" ]; then
 64      OUTPUT_DIR="./compression-results/$(date +%Y%m%d-%H%M%S)"
 65  fi
 66  
 67  # Create output directory
 68  mkdir -p "$OUTPUT_DIR"
 69  
 70  # Build the demo
 71  echo "Building..."
 72  go build -o bin/quantum-compression-demo cmd/keepsync-cli/quantum-compression-demo/main.go
 73  
 74  # Check if build was successful
 75  if [ $? -ne 0 ]; then
 76      echo "Build failed"
 77      exit 1
 78  fi
 79  
 80  # Run the demo
 81  echo "Running..."
 82  ./bin/quantum-compression-demo \
 83    --input="$INPUT_FILE" \
 84    --output="$OUTPUT_DIR" \
 85    --algorithm="$ALGORITHM" \
 86    --level="$LEVEL" \
 87    --min-size="$MIN_SIZE"
 88  
 89  # Check if run was successful
 90  if [ $? -ne 0 ]; then
 91      echo "Run failed"
 92      exit 1
 93  fi
 94  
 95  echo "Results saved to $OUTPUT_DIR"
 96  
 97  # Clean up
 98  echo "Cleaning up..."
 99  rm -f bin/quantum-compression-demo
100  
101  echo "Done"