#!/bin/bash

readargs() {
  while [ "$#" -gt 0 ] ; do
    case "$1" in
       -c)
        if [ "$2" ] ; then
          commit="$2"
          shift ; shift
        else
          echo "Missing a value for $1."
          echo
          shift
          usage
exit
        fi
      ;;
      *)
        echo "Unknown option or argument $1."
        echo
        shift
        usage
      exit
      ;;
    esac
  done
}

#  BEGIN THE PROGRAM
readargs "$@"
shortcommit=$( echo ${commit} | cut -c 1-7)
name=supercollider

rm -rf ${name}-${shortcommit}/
rm -f ${name}-${shortcommit}.tar.gz
git clone --depth 1 https://github.com/supercollider/supercollider.git ${name}-${shortcommit}
#svn export https://github.com/videolan/vlc/trunk/ ${name}-${shortcommit}
pushd ${name}-${shortcommit}/
git checkout --force "${commit}" 
echo "You are in Commit: $( git rev-parse HEAD )"
git submodule init && git submodule update
popd
tar -cvzf ${name}-${shortcommit}.tar.gz ${name}-${shortcommit}

