#!/usr/bin/env bash

# Unzips .zip homework submissions to a directory (where the zip file will also be moved)
# and creates a file filetypes.txt to tell the type of each of the files.
# Run from hwsubmit/core directory with $1 being assignment number.

hwno=$1

for stud in *; do
  mkdir -p $stud/.graded/$hwno
  cp $stud/$hwno.* $stud/.graded/$hwno
  pushd $stud/.graded/$hwno
  if [[ -e $hwno.zip ]]; then
    unzip $hwno.zip
    file * | \egrep -v 'filetypes.txt|\.zip|\.diff' | sed 's+BuildID\[[^,]*, ++' > filetypes.txt
  else
    empty filetypes.txt
  fi
  popd
done
