#!/bin/bash
COURSE=$1
if [[ $COURSE == "" ]] ; then echo give a course ; exit ; fi

rm -rf $COURSE

cp -ax ../$COURSE .

cd $COURSE
git checkout master

echo wordlist.dict >> .gitignore
echo '!common/.containsrepo' >> .gitignore
echo 'common/*' >> .gitignore

# get rid of old common, to be replaced
rm -rf common
git commit -a -m"got rid of common inside repo"

mkdir common
git clone -v git@github.com:/cooplf/common

# common intro chapter
cd CHAPS
rm -rf introduction
ln -s ../common/LFS_introduction introduction
cd ..

# some classes do not have a separate IMAGES directory
[[ ! -d IMAGES ]] &&  mkdir IMAGES 

cd IMAGES
for names in ../common/IMAGES/* ; do ln -s $names ; done
cd ..

ls -lF

git add -v CHAPS IMAGES wordlist.txt common

git add -v  .

git commit -a -m"REFACTORING DONE!"

