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

    CIPHER_SLUG=$(basename $cipher)
54
    CIPHER_TIMESTAMP=$(cat "$cipher/cipher_mtime.txt")
lwc-tester committed
55

56
    TEST_PATH="$DESTDIR/$CIPHER_SLUG"
lwc-tester committed
57
    mkdir -p "$TEST_PATH" || exit 1
58 59
    TEST_PATH=$(realpath $TEST_PATH)

lwc-tester committed
60 61
    mv $cipher/*.log "$TEST_PATH"
    mv "$cipher/LWC_AEAD_KAT.txt" "$TEST_PATH"
62

63
    case $TEMPLATE in
64 65 66
      f1-libopencm3) mv $cipher/firmware.{bin,elf} "$TEST_PATH"
                  ;;

lwc-tester committed
67
      f7)         mv $cipher/build/f7.* "$TEST_PATH"
68 69
                  ;;

lwc-tester committed
70
      maixduino)  mv $cipher/.pio/build/sipeed-maixduino/firmware.* "$TEST_PATH"
71 72
                  ;;

lwc-tester committed
73
      bluepill)   mv $cipher/.pio/build/bluepill_f103c8/firmware.* "$TEST_PATH"
74 75
                  ;;
      
lwc-tester committed
76
      uno)        mv $cipher/.pio/build/uno/firmware.* "$TEST_PATH"
77 78
                  ;;
      
lwc-tester committed
79
      esp32)      mv $cipher/.pio/build/esp32dev/firmware.* $cipher/.pio/build/esp32dev/partitions.bin "$TEST_PATH"
80
                  ;;
81
    esac
82

83

84 85 86
    curl \
      --request 'POST' \
      --header "Content-Type: application/json" \
87 88 89 90 91 92 93 94 95
      --data "\
{\
\"build_dir\":\"$TEST_PATH\",\
\"cipher\":\"$CIPHER_SLUG\",\
\"cipher_timestamp\":\"$CIPHER_TIMESTAMP\",\
\"template\":\"$TEMPLATE\",\
\"template_commit\":\"$TEMPLATE_COMMIT\",\
\"template_timestamp\":\"$TEMPLATE_TIMESTAMP\"\
}" \
96
      "http://127.0.0.1:5002/schedule_test"
lwc-tester committed
97

98
  done
99

100
  rm -rf "$TMPDIR"
101 102 103
}

if [[ $1 == "run" ]]; then
104
  run $2 $3 $4
105
else
106 107 108 109 110
  ZIP_PATH="$1"
  if [[ ! -f $ZIP_PATH ]]; then
    echo "Error: '$ZIP_PATH' is not a zip file"
    exit 1
  fi
111 112 113

  MAINDIR=email-submissions/$(date +%Y-%m-%d-%H:%M)
  mkdir -p $MAINDIR
lwc-tester committed
114
  TMPDIR=$(mktemp -d -t submission-XXXXXXXXXX)
115
  echo "Extracting in $TMPDIR"
lwc-tester committed
116
  unzip $ZIP_PATH -d $TMPDIR
117
  for i in templates/{uno,bluepill,esp32,f7,maixduino}; do
118 119 120
    TEMPLATE="${i##*/}"
    echo "Template is $TEMPLATE"
    touch $MAINDIR/locky.lock
121
    flock $MAINDIR/locky.lock $0 run $TMPDIR $TEMPLATE $MAINDIR/$TEMPLATE
122
  done
lwc-tester committed
123
  rm -rf $TMPDIR
124 125 126 127

fi