#!/bin/bash
# Version Control
VERSION="2.1.4"
PROGNAME="IsBootable"
APPNAME="isbootable"
PROGRAMMER="TheeMahn"
BUILDDATE="05/19/2025"
WEBSITE="${APPNAME}.com"
EMAIL="<$PROGRAMMER@$WEBSITE>"
COMMANDEXEC="$*"

if [[ -f "/etc/os-release" ]]; then
	OS_NAME=$(grep -i "PRETTY_NAME" /etc/os-release | cut -d "=" -f2 | tr -d '"')
	OSTYPE=$(echo "${OS_NAME}" | grep -i "Ultimate")
else
	Error "This O/S  is unsupported. Exiting."
	exit 1;
fi
ULTIMATE_VERSION="Ultimate Edition"
ISULTIMATE=$(echo "${OS_NAME}" | grep -i "${ULTIMATE_VERSION}")
OS_VERSION=$(grep -i "VERSION_ID" /etc/os-release | cut -d "=" -f2 | tr -d '"')

# Create an array for DEB(s)
declare -a ISDEBS=();
if [[ -f "ultimate-common" ]]; then
	source ultimate-common
elif [[ -f "/usr/share/ultimate_edition/ultimate-common" ]]; then
	source /usr/share/ultimate_edition/ultimate-common
else
	echo "No Ultimate Edition common source. Please install ultimate-edition-common."
fi
VersionDump
Timer "Start" "${APPNAME}"
INCREMENT=0
FILES=();
declare -i NISOS
declare -a ISOINFO=('System id' 'Volume id' 'Publisher id' 'Data preparer' 'Volume size');
ISOS=(./*.iso)
NISOS="${#ISOS[@]}"
FILES=(*.*)
FS=$(type -p stat)
FormatNUM "${NISOS}"
Thousands "${NISOS}}"
Encapsulate "Begining scanning 1 of ${NISOS} ISO image(s)."
for EACH in "${ISOS[@]}"
do
	if [[ "${FS}" ]]; then
		FILESIZE=$(stat --printf="%s" "${EACH}")
		TC=$((FILESIZE + TC))
		Thousands "${FILESIZE}"
	fi
	BOOTABLE=$(file "${EACH}" | grep -i "boot")
	if [[ "${BOOTABLE}" ]]; then
		INCREMENT=$((INCREMENT + 1))
		FILESIZE="${FORMATTED}"
		Encapsulate "File: ${EACH} (${FILESIZE} bytes) is bootable."
	else
        Encapsulate "${EACH} is not bootable.  Deleteing: ${EACH}"
		#rm "${EACH}"
	fi
done
#Timer "Stop" "${APPNAME}"
Thousands "${TC}"
FormatNUM "${TC}"
TC="${FORMATTED}"
ISOS=(./*.iso)
NISOS="${#ISOS[@]}"
Center "Data scanned ${TC} bytes. Found ${NISOS} bootable ISO's"

