Skip to content

Instantly share code, notes, and snippets.

@DonaldKellett
Last active May 22, 2021 11:41
Show Gist options
  • Save DonaldKellett/d5a07027fcc81d9de0b712d2a6e54016 to your computer and use it in GitHub Desktop.
Save DonaldKellett/d5a07027fcc81d9de0b712d2a6e54016 to your computer and use it in GitHub Desktop.
Simple Bash script for Linux I made for processing and zipping submission material for COMP 4521 at HKUST
#!/bin/bash
if [[ $# -ne 2 ]]; then
echo "Usage: /path/to/comp4521.sh prefix project"
echo "Where:"
echo "- prefix is the file to prepend to all JavaScript programs"
echo "- project is the project directory to apply the action to"
exit 1
fi
if [[ ! -f "$1" ]]; then
echo "First argument must be the name of a valid file"
exit 1
fi
if [[ ! -d "$2" ]]; then
echo "Second argument must be the name of a valid directory"
exit 1
fi
tmpdir="$(mktemp -d)"
cp -r "$2/." "$tmpdir/"
for file in $(find "$tmpdir" -name "*.js"); do
tmpfile="$(mktemp)"
cat "$1" "$file" > "$tmpfile"
mv "$tmpfile" "$file"
done
cwd="$(pwd)"
cd "$tmpdir"
zip -rm "$cwd/$2" .
cd "$cwd"
rmdir "$tmpdir"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment