#!/bin/bash

hata_olustu(){
	if [ ! -z "$1" ];then 
		echo "$1"
		exit 1
	fi
}

# Ön sistemin sıkıştırılmadan önce hatalarının kontrolü
#grep -l 'compilation terminated' /tmp/*.log
#grep -l '.h: No such file or directory' /tmp/*.log

[ -z $ONSISTEM_CHROOT ] && hata_olustu "ONSISTEM_CHROOT tanmlı değil!"

rm -fv /tools

[ -d $ONSISTEM_CHROOT/tools ] && rm -rfv $ONSISTEM_CHROOT/tools

rm -rf ../tpaketler && mkdir ../tpaketler
rm -rf ../tlog && mkdir ../tlog

find $ONSISTEM_CHROOT/usr/milis/talimatname -name *.mps.lz -exec mv -v {} ../tpaketler/ \;
find $ONSISTEM_CHROOT/usr/milis/talimatname -name *.mps.lz.bilgi -exec mv -v {} ../tpaketler/ \;
find $ONSISTEM_CHROOT/usr/milis/talimatname -name *.yur -exec mv {} -v ../tpaketler/ \;

find $ONSISTEM_CHROOT/tmp -name *.log -exec mv {} -v ../tlog/ \;

[ -d $ONSISTEM_CHROOT/var/lib/mps/db.onsistem ] && rm -rfv $ONSISTEM_CHROOT/var/lib/mps/db.onsistem

rm -rvf $ONSISTEM_CHROOT/tmp/*.list

rm -rvf $ONSISTEM_CHROOT/root/.bash_history
 
mksquashfs $ONSISTEM_CHROOT ../temel-$(date --utc +"%F_%H-%M").sfs -comp xz
