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


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

function run() {
8 9 10
  SUBMISSION="$1"
  TEMPLATE="$2"
  DESTDIR="$3"
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'"
33
  ./compile_all.py -s $SUBMISSION -t "templates/$TEMPLATE" -b "$TMPDIR"
34
  
35 36
  for cipher in $TMPDIR/*; do
    if [[ ! -d $cipher ]]; then continue; fi
lwc-tester committed
37 38 39 40 41 42 43 44 45

    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"
46

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

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

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

64 65 66 67 68 69
    curl \
      --request 'POST' \
      --header "Content-Type: application/json" \
      --header "Authorization: OAuth ecP9ZsoKMPui4akg1MyGoT7yoGR2bLPo" \
      --data "{\"path\":\"$(realpath $TEST_PATH)\",\"template\":\"$TEMPLATE\"}" \
      "http://127.0.0.1:5002/schedule_test"
lwc-tester committed
70

71
  done
72 73

  rm -rf "$TMPDIR"
74 75 76
}

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

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

fi