#!/bin/sh

if [ 2 -ne $# ]
then
    echo 1
    exit
fi

iso_file=$1
check_file=$2

mount_dir=$(date "+%Y%m%d%H%M%S")
mkdir -p ${mount_dir} >/dev/null 2>&1
if [ 0 -ne $? ]
then
    mount_dir=$(date "+%Y%m%d%H%M%S")
    mkdir -p ${mount_dir} >/dev/null 2>&1
    if [ 0 -ne $? ]
    then
        echo 2
        exit
    fi
fi

mount -o loop "${iso_file}" "${mount_dir}" >/dev/null 2>error.log
if [ 0 -ne $? ]
then
    echo 3
    rm -rf ${mount_dir} >/dev/null 2>&1
    rm -f error.log >/dev/null 2>&1
    exit
fi

rm -f error.log >/dev/null 2>&1

path="${mount_dir}/${check_file}"

result=0
if [ ! -d ${path} ] && [ ! -f ${path} ]
then
    result=4
fi

umount ${mount_dir} >/dev/null 2>&1
rm -rf ${mount_dir} >/dev/null 2>&1

echo $result
