#!/bin/bash
# ==============================================================================
# title			:Ram Booter
# desoftwareion	:Boots your Entire O/S from RAM.
# author		:theemahn <theemahn@ultimateedition.info>
# date			:06/22/2021
# version		:1.0
# usage			:Ram Booter --help
# manual		:man Ram Booter
# notes			:See change-log below for further information.
# ==============================================================================
# Change-log: 1.0: unreleased
# ==============================================================================

# Modify the below information to correlate with the software you are designing.
APPNAME="fs"
PROGNAME="File Size"
PROGRAMMER="TheeMahn"
BUILDDATE="05/19/2025"
VERSION="2.1.4"
DOMAIN="ultimateedition.info"
WEBSITE="http://${DOMAIN}/"
EMAIL="<${PROGRAMMER}@${DOMAIN}>"

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."
	exit 1;
fi

# Help system - I have re-wrote this section to work with code-cleanup.
Help () {

	if [[ "${2}" == "" ]]; then
		VersionDump
		PRAM="ALL"
	else
		if ! [[ "${3}" ]]; then
			VersionDump
			PRAM="${2}"
		else
			PRAM="${2}"
		fi
	fi

	case "${PRAM}" in
		ALL)
			Encapsulate "Usage: ${PROGNAME} -<-COMMAND> [OPTION]"
			FullBar
			Encapsulate "Mandatory arguments to long options are identical for short options."
			Encapsulate "  possible commands..."
			Encapsulate " "
			Encapsulate "  -h       --help          this help message."
			Encapsulate "  -v       --version       dump version info and exit."
			Encapsulate " "
			FullBar
			Center "${PROGNAME} --help [COMMAND] for further information."
		FullBar;;

		# Version Help
		ALL|v|version)
			Encapsulate "Usage version;"
			FullBar
			Center "${PROGNAME} -v"
			FullBar
			Encapsulate "Displays ${PROGNAME}s version number and exits."
		FullBar;;

		# Help Help
		ALL|h|help|\?)
			Encapsulate "Usage Help [COMMAND]"
			FullBar
			Center "${PROGNAME} -h [COMMAND]"
			FullBar
			Encapsulate "Displays this message. For futher information ${PROGNAME} help [COMMAND]"
			Encapsulate "or refer to the manpages."
			Encapsulate " "
			Encapsulate "man ${PROGNAME}"
			Encapsulate " "
			Encapsulate "Example: ${PROGNAME} -h version"
			Encapsulate "Will display help about the command switch version"
			FullBar
	esac
	exit 0
}

ParseFilez () {
	shopt -s nullglob
	declare -a TFTP=();
	declare -i NFTP
	if [[ "${1}" == "" ]]; then
		EXTENSION="*"
	else
		EXTENSION="${1}"
	fi
	TFTP=(./*.${EXTENSION})
	NFTP="${#TFTP[@]}"
	if [[ "${NFTP}" -gt 0 ]]; then
		Center "Files found matching ${EXTENSION}: ${NFTP}"
		EColumnize -t "File" "Size in bytes" "Human Readable"
		FullBar
	else
		Encapsulate "No files found matiching: ${EXTENSION}"
	fi
	for EACH in "${TFTP[@]}"
	do
		BASEFILE=$(basename "${EACH}")
		FileSize "${EACH}"
		GRANDTOTAL=$(( GRANDTOTAL + TOTALSIZE ))
		EColumnize "${BASEFILE}" "${FORMATTED}" "(${TRUESIZE})"
	done
	FullBar
	Thousands "${GRANDTOTAL}"
	EColumnize "Files: ${NFTP}" "${FORMATTED}" "(${TRUESIZE})"
	FullBar
}
CONTAINS=$(echo "$@" | grep -i "suppress")
if ! [[ "${CONTAINS}" ]]; then
	VersionDump "$@"
fi
Timer "Start" "${APPNAME}"
	case "${1}" in
		-h|--help|-\?) Help "$@"; exit 0;; # TODO: Enhance this section.
		-v|--version) VersionDump "$@"; exit 0;;
		*) VersionDump "$@"; ParseFilez "$@"; exit 0;;
	esac
Timer "Stop" "${APPNAME}"

