process_zip.sh 2.36 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

    mkdir -p "./queues"
    QUEUE_PATH="./queues/$TEMPLATE"
    CIPHER_SLUG=$(basename $cipher)
41
    TEST_PATH="$DESTDIR/$CIPHER_SLUG"
lwc-tester committed
42 43 44 45

    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
    curl \
      --request 'POST' \
      --header "Content-Type: application/json" \
      --data "{\"path\":\"$(realpath $TEST_PATH)\",\"template\":\"$TEMPLATE\"}" \
      "http://127.0.0.1:5002/schedule_test"
lwc-tester committed
69

70
  done
71 72

  rm -rf "$TMPDIR"
73 74 75
}

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

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

fi