Created
September 25, 2016 00:18
-
-
Save pr1sm/4f53aeb574f049734d75e21e649c1fe4 to your computer and use it in GitHub Desktop.
bash script to automatically setup submissions for CPRE 381 Labs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# CPRE 381 Lab Submission Setup | |
# | |
# Usage: ./submit.sh <lab_directory> | |
# | |
# This script takes the directory of your lab files | |
# and copies all the source files and waveform files | |
# to a submission directory, organizing them into | |
# src/ and test/ subdirectories for each part. | |
# Get the target dir | |
TARGET_DIR=$1 | |
# Check if input exists | |
if ! [ -n "$1" ]; then | |
echo "Please specify the target directory!" | |
exit | |
fi | |
# Check if input is a directory | |
if ! [ -d "$TARGET_DIR" ]; then | |
echo "Please specify a directory!" | |
exit | |
fi | |
# Remove submission folder and create a new one | |
rm -rf submission | |
mkdir submission | |
# Loop through all files in lab directory | |
for i in "$TARGET_DIR"/*; do | |
# Capture file name | |
FILE=${i#$TARGET_DIR/} | |
# Check if file is a directory | |
if [ -d $i ]; then | |
# Check if directory is a part of the lab (P1, P2, ...) | |
if [[ $FILE =~ ^[P*] ]]; then | |
# Create directory in submission/ and copy files | |
# to appropriate sub directory | |
echo "Found Directory $FILE..." | |
mkdir submission/$FILE | |
mkdir submission/$FILE/src | |
mkdir submission/$FILE/test | |
cp $i/*.vhd $i/c*.do submission/$FILE/src | |
cp $i/*.wlf $i/s*.do submission/$FILE/test | |
echo "$FILE Copied for Submission!" | |
fi | |
else | |
# Copy file to submission base directory | |
echo "Found $FILE..." | |
cp $i submission/$FILE | |
echo "$FILE Copied for Submission!" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment