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

63 64 65 66 67 68
    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
69

70
  done
71 72

  rm -rf "$TMPDIR"
73 74 75 76 77
}

if [[ $1 == "run" ]]; then
  run $2 $3
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 $TEMPLATE $MAINDIR/$TEMPLATE
93
  done
lwc-tester committed
94
  rm -rf $TMPDIR
95 96 97 98

fi