Skip to content

Instantly share code, notes, and snippets.

@ellotheth
Last active December 21, 2015 17:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ellotheth/6339003 to your computer and use it in GitHub Desktop.
Save ellotheth/6339003 to your computer and use it in GitHub Desktop.
Setup script for Coursera's Algorithms I class. Downloads the relevant files and massages them into a /path/to/class/{bin,lib} structure.
#!/bin/bash
# Load class materials for Coursera's 'Algorithms I' course into the directory
# specified on the command line. Files will be downloaded directly from the
# class book site, maven and ellotheth's Makefile samples. Where appropriate,
# hard-coded paths (in e.g. source files and shell scripts) will be replaced
# by the user-specified path.
#
# USAGE
# $ chmod +x algo-i-setup.sh
# $ ./algo-i-setup.sh /path/to/algo-i
# $ source /path/to/algo-i/bin/configrc
#
# DEPENDENCIES
# - wget
# - sed
# - unzip
#
# TROUBLESHOOTING
# http://algs4.cs.princeton.edu/linux/
#
# Final structure:
#
# root (from command line)
# +-- bin
# | +-- checkstyle [http://algs4.cs.princeton.edu/linux/checkstyle]
# | +-- findbugs [http://algs4.cs.princeton.edu/linux/findbugs]
# | +-- configrc [http://algs4.cs.princeton.edu/linux/config.sh]
# | +-- drjava [http://algs4.cs.princeton.edu/linux/drjava]
# +-- lib
# | +-- checkstyle* [http://algs4.cs.princeton.edu/linux/checkstyle.zip]
# | | +-- checkstyle.xml [http://algs4.cs.princeton.edu/linux/checkstyle.xml]
# | +-- findbugs* [http://algs4.cs.princeton.edu/linux/findbugs.zip]
# | | +-- findbugs.xml [http://algs4.cs.princeton.edu/linux/findbugs.xml]
# | +-- algs4.jar [http://algs4.cs.princeton.edu/code/algs4.jar]
# | +-- drjava.jar [http://algs4.cs.princeton.edu/linux/drjava.jar]
# | +-- stdlib.jar [http://algs4.cs.princeton.edu/code/stdlib.jar]
# | +-- junit.jar [http://search.maven.org/remotecontent?filepath=junit/junit/4.11/junit-4.11.jar]
# | +-- hamcrest-core.jar [http://search.maven.org/remotecontent?filepath=org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar]
# +-- Makefile.sample [https://gist.github.com/ellotheth/6315832/raw/Makefile]
# +-- common.mk [https://gist.github.com/ellotheth/6315832/raw/common.mk]
#
if [ -z "$1" ]; then
echo Specify a path for the Algorithms I class materials
exit 1
elif [ "${1/ /}" != "$1" ]; then
echo Spaces in your path? Really? This is Linux. Get it together.
exit 1
fi
# get the full path
root=`readlink -m $1`
bin=$root/bin
lib=$root/lib
[ -d $bin ] || mkdir -p $bin || (echo "Failed to make $bin" && false) || exit 1
[ -d $lib ] || mkdir -p $lib || (echo "Failed to make $lib" && false) || exit 1
# get the java libs, including junit
wget -nv -O $lib/drjava.jar http://algs4.cs.princeton.edu/linux/drjava.jar
wget -nv -O $lib/stdlib.jar http://algs4.cs.princeton.edu/code/stdlib.jar
wget -nv -O $lib/algs4.jar http://algs4.cs.princeton.edu/code/algs4.jar
wget -nv -O $lib/junit.jar http://search.maven.org/remotecontent?filepath=junit/junit/4.11/junit-4.11.jar
wget -nv -O $lib/hamcrest-core.jar http://search.maven.org/remotecontent?filepath=org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar
# get the course utilities
wget -nv -O checkstyle.zip http://algs4.cs.princeton.edu/linux/checkstyle.zip
wget -nv -O findbugs.zip http://algs4.cs.princeton.edu/linux/findbugs.zip
wget -nv -O checkstyle.xml http://algs4.cs.princeton.edu/linux/checkstyle.xml
wget -nv -O findbugs.xml http://algs4.cs.princeton.edu/linux/findbugs.xml
# unpack checkstyle and findbugs
unzip -q checkstyle.zip
unzip -q findbugs.zip
rm {checkstyle,findbugs}.zip
mv checkstyle.xml checkstyle*/.
mv findbugs.xml findbugs*/.
mv {checkstyle,findbugs}* $lib/.
# get the executables (shell scripts)
wget -nv -O checkstyle http://algs4.cs.princeton.edu/linux/checkstyle
wget -nv -O findbugs http://algs4.cs.princeton.edu/linux/findbugs
wget -nv -O drjava http://algs4.cs.princeton.edu/linux/drjava
wget -nv -O configrc http://algs4.cs.princeton.edu/linux/config.sh
# replace the hard-coded paths from the algs class with the user-specified dir
sed "s|~/algs4|$lib|" drjava > $bin/drjava
sed "s|~/algs4|$lib|" checkstyle > $bin/checkstyle
sed "s|~/algs4|$lib|" findbugs > $bin/findbugs
sed -e "s|\$HOME/algs4/bin|$bin|g" \
-e "s|\$HOME/algs4|$lib|g" \
-e "s|algs4\.jar$|algs4\.jar:$lib/junit.jar:$lib/hamcrest-core.jar|" \
configrc > $bin/configrc
rm drjava checkstyle findbugs configrc
chmod +x $bin/*
# get the makefiles
wget -nv -O common.mk https://gist.github.com/ellotheth/6315832/raw/common.mk
wget -nv -O $root/Makefile.sample https://gist.github.com/ellotheth/6315832/raw/Makefile
sed "s|ALGO = .*|ALGO = $root|" common.mk > $root/common.mk
rm common.mk
if [ ! `which javac` ]; then
echo "You don't have a Java compiler in your path. Try openjdk-7-jdk." >&2
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment