#!/bin/sh
#
# Creates an archive for the labs
# Run this from the parent directory
#
output=felabs-$USER.tar.lzma
readme=felabs/README.txt

echo "Archive lab archive..."
echo "Making all files belong to user (need root permissions)"
sudo chown -R $USER:$USER felabs /usr/local/xtools

rm -rf $readme
cat << EOF >> $readme
Free Electrons lab directory archive
------------------------------------

This is your training lab directory

To save space, we removed downloaded sources
(like the Linux kernel sources), but you could
download them again. Of course, we kept
your own source and generated files (kernel
configuration, kernel images, etc.), so that
you can easily reuse your work.

The command_history file contains a history
of the commands you typed during the labs.

The cross-compiling toolchain has been archived in toolchain.tar
To reuse it, extract it in /usr/local/xtools
EOF

cp $HOME/.bash_history felabs/command_history 
cd felabs
echo "Cleaning lab directory"
./clean-labs

echo "Creating the toolchain archive"
tar cf toolchain.tar /usr/local/xtools

echo "Generating lab directory archive"
cd ..
./cleanlabs
tar --lzma -cvf $output felabs
md5sum $output > $output.md5 
