#!/bin/sh
##########################################################################
##                                                                      ##
##       this script searches for the necessary binaries and            ##
##       aborts if something isn't found                                ##   
##                                                                      ##
##                                                                      ##
## This program is free software; you can redistribute it and/or modify ##
## it under the terms of the GNU General Public License as published by ##
## the Free Software Foundation; either version 2 of the License, or    ##
## (at your option) any later version.                                  ##
##                                                                      ##
##########################################################################

. config_build
. $SCRIPTS/misc/lib/lib_fail

FILES="mkcramfs tune2fs cp mv gunzip gzip umount mount cat mkisofs dd mke2fs rmdir tar"
FAILED="false"

# if we use a compressed ISO9660 we need that too
if [ "$COMPRESSEDFS" = "yes" ]; then
    FILES="$FILES mkzftree"
fi

# we need create_compressed_fs if we use cloop
if [ "$CLOOP" = "yes" ]; then
	FILES="$FILES create_compressed_fs"
fi

# we do not need cdrecord if we just want the image
if [ "$ISOIMAGEONLY" = "no" ]; then
    FILES="$FILES cdrecord"
fi

# Lets look if everything is in the path we need
for i in $FILES; do
    if ! which $i >> /dev/null; then
	echo "Sorry, can't find $i !"
	FAILED="true"
    fi
done

# if something was not found we fail
if [ $FAILED = "true" ]; then
    fail
fi

if [ "$CRAMFS" = "yes" ]; then
	if [ "$COMPRESSEDFS" = "yes" ] || [ "$CLOOP" = "yes" ]; then
		echo "Only one of COMPRESSEDFS, CRAMFS and CLOOP can be set to yes." 
		fail
	fi
fi

if [ "$CLOOP" = "yes" ]; then
	if [ "$COMPRESSEDFS" = "yes" ] || [ "$CRAMFS" = "yes" ]; then
		echo "Only one of COMPRESSEDFS, CRAMFS and CLOOP can be set to yes." 
		fail
	fi
fi

if [ "$COMPRESSEDFS" = "yes" ]; then
	if [ "$CLOOP" = "yes" ] || [ "$CRAMFS" = "yes" ]; then
		echo "Only one of COMPRESSEDFS, CRAMFS and CLOOP can be set to yes." 
		fail
	fi
fi

exit 0
