#!/bin/bash
# This script was auto generated using the code-cleanup package http://forumubuntusoftware.info/viewtopic.php?f=23&t=9480
# Do a search and replace for ultimateedition.info followed by a search and replace man-maker with the name of your program & delete this line.

# ==============================================================================
# title			:man-maker
# description	:YOURDESCRIPTION
# author		:theemahn <theemahn@ultimateedition.info>
# date			:01/23/2022
# version		:1.0
# usage			:man-maker --help
# manual		:man man-maker
# 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="Man Maker"
PROGNAME="man-maker"
PROGRAMMER="TheeMahn"
BUILDDATE="01/23/2022"
VERSION="1.0"
DOMAIN="ultimateedition.info"
WEBSITE="http://${DOMAIN}/"
EMAIL="<${PROGRAMMER}@${DOMAIN}>"


source /usr/share/ultimate_edition/ultimate-common

# Turn off end user prompting
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 "  -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
}

ManUp () {
	echo "@: $@ 1:${1} 2:${2} 3:${3}"
	APP=$(type -p "${2}")
	if [[ "${APP}" ]]; then
		HELPSYSTEM=$(${APP} --help)
		echo "${HELPSYSTEM}"
	fi
}

TestBar () {
	Encapsulate "Testing Progress bar"
	i=0
	while [[ $i -ne 100 ]]
	do
        i=$(($i+1))
        ProgressBar "$i" "Testing Progress bar"
		sleep .1
	done
	Center "Testing Download Function"
	Download "http://os-builder.com/UETOYS/ultimate-edition-animated-1.0_all.deb"
	CURRENTBRANCH=$(lsb_release -c | cut -d ":" -f2 | sed "s/ //g" | sed "s/	//g")
	if [[ "${CURRENTBRANCH}" ]]; then
		Encapsulate "Replacing ${CURRENTBRANCH} with Jammy sources to get the latest kernel."
		sudo sed -i "s/${CURRENTBRANCH}/jammy/g" "/etc/apt/sources.list"
		Encapsulate "Running apt-get update..."
		sudo apt-get update >/dev/null & Spinner "Running apt-get update..."
		Encapsulate "Installing latest low-latency kernel..."
		sudo apt-get install -f -y linux-lowlatency linux-headers-lowlatency linux-image-lowlatency & Spinner "Installing latest low-latency kernel..."
		Encapsulate "Replacing jammy sources back to ${CURRENTBRANCH}."
		sudo sed -i "s/jammy/${CURRENTBRANCH}/g" "/etc/apt/sources.list"
		Encapsulate "Running apt-get update..."
		sudo apt-get update >/dev/null & Spinner "Running apt-get update..."
	else
		Error "Current Branch not detected, exiting."
		exit 1;
	fi
}

CONTAINS=$(echo "$@" | grep -i "suppress")
if ! [[ "${CONTAINS}" ]]; then
	VersionDump "$@"
fi
Timer "Start" "${APPNAME}"

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


