#!/bin/bash

# It will empty then extract all plugin code versions into the 'unzipped' directory.
#
# This script would work within any local_plugins data store under a moodledata dir.
# eg: moodle.org/data/local_plugins/

#######
### Warning these commands are dangerous for production! Only use(uncomment) if you know what you're doing.
###
### rm -rf unzipped; # only needed to reset everything.
### rm -rf -d [0-9]* # only needed to clean up all the dirs.
#######

CODEDIR='plugincode';

if [ ! -d $CODEDIR ]; then
	mkdir $CODEDIR;
fi

for DIR in `ls -d [0-9]*/`;
	do
	echo $DIR;
	mkdir ./$CODEDIR/$DIR;
	cd $DIR;
	for FILE in `ls *.zip`;
		do
		echo 'unzipping' $FILE;
		unzip -ou $FILE -d ../$CODEDIR/$DIR$FILE;
	done;
	cd ..;
done;

cd $CODEDIR;
git init;
git add --all;
git commit -a -m'Added plugins.'
cd ..;

