process_zip.sh 1.91 KB
Newer Older
1 2 3 4 5 6 7
#!/bin/bash


shopt -s extglob

function run() {
  TEMPLATE="$1"
8
  DESTDIR="$2"
9

10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
  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"
32
  
33 34 35 36 37 38
  for cipher in $TMPDIR/*; do
    CIPHER_SLUG=$(basename $cipher)
    if [[ ! -d $cipher ]]; then continue; fi
    mkdir -p $DESTDIR/$CIPHER_SLUG || exit 1
    mv $cipher/*.log $DESTDIR/$CIPHER_SLUG/

39
    case $TEMPLATE in
40
      f7)         mv $cipher/build/f7.* $DESTDIR/$CIPHER_SLUG/
41 42
                  ;;

43
      maixduino)  mv $cipher/.pio/build/sipeed-maixduino/firmware.* $DESTDIR/$CIPHER_SLUG/
44 45
                  ;;

46
      bluepill)   mv $cipher/.pio/build/bluepill_f103c8/firmware.* $DESTDIR/$CIPHER_SLUG/
47 48
                  ;;
      
49
      uno)        mv $cipher/.pio/build/uno/firmware.* $DESTDIR/$CIPHER_SLUG/
50 51
                  ;;
      
52
      esp32)      mv $cipher/.pio/build/esp32dev/firmware.* $DESTDIR/$CIPHER_SLUG/
53
                  ;;
54
    esac
55 56

  done
57 58

  rm -rf "$TMPDIR"
59 60 61 62 63
}

if [[ $1 == "run" ]]; then
  run $2 $3
else
64 65 66 67 68
  ZIP_PATH="$1"
  if [[ ! -f $ZIP_PATH ]]; then
    echo "Error: '$ZIP_PATH' is not a zip file"
    exit 1
  fi
69 70 71

  MAINDIR=email-submissions/$(date +%Y-%m-%d-%H:%M)
  mkdir -p $MAINDIR
72
  unzip $ZIP_PATH -d all-lwc-submission-files
73 74 75 76
  for i in templates/*; do
    TEMPLATE="${i##*/}"
    echo "Template is $TEMPLATE"
    touch $MAINDIR/locky.lock
77
    flock $MAINDIR/locky.lock $0 run $TEMPLATE $MAINDIR/$TEMPLATE
78 79 80 81 82
  done

fi