process_zip.sh 2.71 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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48

  TEMPLATE_PATH="templates/$TEMPLATE"

  TEMPLATE_COMMIT=$(git rev-list -1 HEAD -- "$TEMPLATE_PATH")
  if [ -z "$TEMPLATE_COMMIT" ]; then
    echo "Could not retrieve the git commit of the template"
    exit 1
  fi

  TEMPLATE_TIMESTAMP=$(git show -s --format=%ct "$TEMPLATE_COMMIT")
  if [ -z "$TEMPLATE_TIMESTAMP" ]; then
    echo "Could not retrieve the git commit date of the template"
    exit 1
  fi

  ./compile_all.py -s $SUBMISSION -t $TEMPLATE_PATH -b "$TMPDIR"
49
  
50 51
  for cipher in $TMPDIR/*; do
    if [[ ! -d $cipher ]]; then continue; fi
lwc-tester committed
52

53 54 55 56 57 58
    CIPHER_SLUG=$(basename $cipher);
    FAMILY="${CIPHER_SLUG%%.*}";
    REM="${CIPHER_SLUG#*.}";
    VARIANT="${REM%%.*}";
    IMPLEMENTATION="${REM#*.}";

59
    CIPHER_TIMESTAMP=$(cat "$cipher/cipher_mtime.txt")
lwc-tester committed
60

61
    TEST_PATH="$DESTDIR/$CIPHER_SLUG"
lwc-tester committed
62
    mkdir -p "$TEST_PATH" || exit 1
63 64
    TEST_PATH=$(realpath $TEST_PATH)

lwc-tester committed
65
    mv $cipher/*.log "$TEST_PATH"
66
    cp test_vectors/$VARIANT/LWC_AEAD_KAT_*.txt "$TEST_PATH/LWC_AEAD_KAT.txt" || exit 1
67
    mv $TMPDIR/$CIPHER_SLUG/*{.elf,.bin,.hex,.map} "$TEST_PATH"
68

69 70 71
    curl \
      --request 'POST' \
      --header "Content-Type: application/json" \
72 73 74 75 76 77 78 79 80
      --data "\
{\
\"build_dir\":\"$TEST_PATH\",\
\"cipher\":\"$CIPHER_SLUG\",\
\"cipher_timestamp\":\"$CIPHER_TIMESTAMP\",\
\"template\":\"$TEMPLATE\",\
\"template_commit\":\"$TEMPLATE_COMMIT\",\
\"template_timestamp\":\"$TEMPLATE_TIMESTAMP\"\
}" \
81
      "http://127.0.0.1:5002/schedule_test"
lwc-tester committed
82

83
  done
84

85
  #rm -rf "$TMPDIR"
86 87 88
}

if [[ $1 == "run" ]]; then
89
  run $2 $3 $4
90
else
91 92 93 94 95
  ZIP_PATH="$1"
  if [[ ! -f $ZIP_PATH ]]; then
    echo "Error: '$ZIP_PATH' is not a zip file"
    exit 1
  fi
96 97 98

  MAINDIR=email-submissions/$(date +%Y-%m-%d-%H:%M)
  mkdir -p $MAINDIR
lwc-tester committed
99
  TMPDIR=$(mktemp -d -t submission-XXXXXXXXXX)
100
  echo "Extracting in $TMPDIR"
lwc-tester committed
101
  unzip $ZIP_PATH -d $TMPDIR
102
  for i in templates/{uno,bluepill,f7,longan-nano,esp32,maixduino}; do
103 104 105
    TEMPLATE="${i##*/}"
    echo "Template is $TEMPLATE"
    touch $MAINDIR/locky.lock
106
    flock $MAINDIR/locky.lock $0 run $TMPDIR $TEMPLATE $MAINDIR/$TEMPLATE
107
  done
108
  #rm -rf $TMPDIR
109 110 111 112

fi