process_zip.sh 2.35 KB
Newer Older
1 2 3 4
#!/bin/bash


shopt -s extglob
lwc-tester committed
5
export PYTHONPATH="$PYTHONPATH:$(pwd)"
6 7 8

function run() {
  TEMPLATE="$1"
9
  DESTDIR="$2"
10

11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
  if [[ ! -d "templates/$TEMPLATE" ]]; then
    echo "Template '$TEMPLATE' does not exist"
    exit 1
  fi

  if [[ -e "$DESTDIR" ]]; then
    echo "Destination directory '$DESTDIR' already exists"
    exit 1
  fi

  TMPDIR=$(mktemp -d -t build-XXXXXXXXXX)

  if [[ ! -d "$TMPDIR" ]]; then
    echo "Failed to create a temporary build directory"
    exit 1
  fi

  echo "Template is '$TEMPLATE', destination directory is '$DESTDIR', temporary directory is '$TMPDIR'"

  mkdir -p $DESTDIR
  echo "Compiling for template '$TEMPLATE' in directory '$TMPDIR'"
  ./compile_all.py -t "templates/$TEMPLATE" -b "$TMPDIR"
33
  
34 35
  for cipher in $TMPDIR/*; do
    if [[ ! -d $cipher ]]; then continue; fi
lwc-tester committed
36 37 38 39 40 41 42 43 44

    mkdir -p "./queues"
    QUEUE_PATH="./queues/$TEMPLATE"
    TEST_PATH="$DESTDIR/$CIPHER_SLUG"
    CIPHER_SLUG=$(basename $cipher)

    mkdir -p "$TEST_PATH" || exit 1
    mv $cipher/*.log "$TEST_PATH"
    mv "$cipher/LWC_AEAD_KAT.txt" "$TEST_PATH"
45

46
    case $TEMPLATE in
lwc-tester committed
47
      f7)         mv $cipher/build/f7.* "$TEST_PATH"
48 49
                  ;;

lwc-tester committed
50
      maixduino)  mv $cipher/.pio/build/sipeed-maixduino/firmware.* "$TEST_PATH"
51 52
                  ;;

lwc-tester committed
53
      bluepill)   mv $cipher/.pio/build/bluepill_f103c8/firmware.* "$TEST_PATH"
54 55
                  ;;
      
lwc-tester committed
56
      uno)        mv $cipher/.pio/build/uno/firmware.* "$TEST_PATH"
57 58
                  ;;
      
lwc-tester committed
59
      esp32)      mv $cipher/.pio/build/esp32dev/firmware.* $cipher/.pio/build/esp32dev/partitions.bin "$TEST_PATH"
60
                  ;;
61
    esac
62

lwc-tester committed
63 64 65 66
    CMD="PYTHONPATH=\$PYTHONPATH:$(pwd) python3 './templates/$TEMPLATE/test' '$TEST_PATH' > '$TEST_PATH/test.stdout.log' 2> '$TEST_PATH/test.stderr.log'"
    printf -v CMD "%q" "$CMD"
    flock "$QUEUE_PATH" bash -c "echo $CMD >> \"$QUEUE_PATH\""

67
  done
68 69

  rm -rf "$TMPDIR"
70 71 72 73 74
}

if [[ $1 == "run" ]]; then
  run $2 $3
else
75 76 77 78 79
  ZIP_PATH="$1"
  if [[ ! -f $ZIP_PATH ]]; then
    echo "Error: '$ZIP_PATH' is not a zip file"
    exit 1
  fi
80 81 82

  MAINDIR=email-submissions/$(date +%Y-%m-%d-%H:%M)
  mkdir -p $MAINDIR
lwc-tester committed
83 84
  TMPDIR=$(mktemp -d -t submission-XXXXXXXXXX)
  unzip $ZIP_PATH -d $TMPDIR
85 86 87 88
  for i in templates/*; do
    TEMPLATE="${i##*/}"
    echo "Template is $TEMPLATE"
    touch $MAINDIR/locky.lock
89
    flock $MAINDIR/locky.lock $0 run $TEMPLATE $MAINDIR/$TEMPLATE
90
  done
lwc-tester committed
91
  rm -rf $TMPDIR
92 93 94 95

fi