#!/bin/sh
# [Pluma Tool]
# Name=New Bash Script
# Applicability=all
# Input=document
# Output=replace-document
# Save-files=nothing

INSTALLED=$(type -p hostname)
if [[ "${INSTALLED}" ]]; then
	HOSTNAME=$(hostname)
else
	HOSTNAME="ultimateedition.info"
fi
WEBSITE="${HOSTNAME}"
IUSER=${SUDO_USER:-$USER}
IHOME="/home/${IUSER}"
MUSER=$(users | awk '{print $1}')
TUSER=$(grep -i "${USER}" "/etc/passwd" | cut -d ":" -f5 | sed "s/,//g")
TDATE=$(date +"%m/%d/%Y")

echo "#!/bin/bash"
echo "# This script was auto generated using the code-cleanup package http://forumubuntusoftware.info/viewtopic.php?f=23&t=9480"
echo "# Do a search and replace for ultimateedition.info followed by a search and replace REPLACEME with the name of your program & delete this line."
echo "
# ==============================================================================
# title			:REPLACEME
# description	:YOURDESCRIPTION
# author		:${USER} <${USER}@${WEBSITE}>
# date			:${TDATE}
# version		:1.0
# usage			:REPLACEME --help
# manual		:man REPLACEME
# 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."
echo 'APPNAME="Application-Name"'
echo 'PROGNAME="REPLACEME"'
echo "PROGRAMMER=\"${TUSER}\""
echo 'BUILDDATE="'`date +"%m/%d/%Y"`'"'
echo 'VERSION="1.0"'
echo 'DOMAIN="'${WEBSITE}'"'
echo 'WEBSITE="${DOMAIN}"'
echo 'EMAIL="<${PROGRAMMER}@${DOMAIN}>"'
echo '

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."
	if [[ "${ISARCH}" ]]; then
		Encapsulate "sudo pacman -Syuu ultimate-edition-common"
	else
		Encapsulate "sudo apt-get install ultimate-edition-common"
	fi
	exit 0;
fi

Exit () {
	if ! [[ "${SUPPRESS}" ]]; then
		Timer "Stop" "${APPNAME}"
		FullBar
	fi
}

trap Exit EXIT

# Turn off end user prompting non Arch
export DEBIAN_FRONTEND=noninteractive

# 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 "  -t       --test        test functions."
		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;;

		# Test functions
		ALL|t|test)
		Encapsulate "Usage test;"
		FullBar
		Center "${PROGNAME} -t"
		FullBar
		Encapsulate "Tests a few functions such as Progress bar, Download, Spinner, O/S detection, Root Detection and Timer for ${PROGNAME}s 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
}

TestBar () {
	Encapsulate "Testing Progress bar"
	i=0
	while [[ $i -ne 100 ]]
	do
		i=$(($i+1))
		ProgressBar "$i" "Testing Progress bar"
		sleep .1
	done
	Encapsulate "Testing NetInfo function ..."
	NetInfo
	Encapsulate "Testing SysInfo function ..."
	SysInfo
	Center "Testing Download Function & Center"
	Download "http://os-builder.com/UETOYS/ultimate-edition-animated-1.0_all.deb"
}

# Command line pre-processor - this section of code is where your functions are called.
shopt -u nullglob
Timer "Start" "${APPNAME}"

case "${1}" in
	-t|--test) VersionDump "$@"; CheckRoot "$@"; TestBar "$@"; exit 0;; # Hidden switch to increase program advancement
	-h|--help|-\?) Help "$@"; exit 0;; # TODO: Enhance this section.
	-v|--version) VersionDump "$@"; exit 0;;
	*) Help; exit 0;;
esac
'
