#!/usr/bin/env bash
###################################################################
#
#	File    : Bashie
#	Author  : adb <alex@alexdball.dev>
#	Created : 22-12-31
#
###################################################################
#
clear

# Set the usage message
Usage() {
	printf "\n[-] Lua script header template\n\n"
	printf "[?] Usage : $(basename "$0") SCRIPT_NAME\n"
	printf "[?] SCRIPT_NAME = The name of the script to be created\n"
}

# Set the file exists message
FileExists() {
    printf "[!] File $1 already exists!\n"
    printf "Are you sure you want to replace it? (y/N)\n"
}


if [ -z "$1" ]; then
    Usage
    exit 1
fi

NEWSCRIPT=$1
FILE_EXISTS=0

if [ -f $1 ]; then FILE_EXISTS=1; fi

if [ "$FILE_EXISTS" = 1 ]; then
	FileExists
	read ANSW
	if [ ! "$ANSW" = y ]; then printf "\n[x] User aborted..."; exit 2; fi
	printf "\n"
fi

# Output the contents of the new script's header
printf "[-] Creating bash script '$1'...\n"

USR_FULL=""

if [ -f /usr/bin/finger ]; then
	USR_FULL=$(finger `whoami` | grep Name | awk '{print ""$NF""}')
fi

cat > $1 << OUTPUT
#!/usr/bin/env lua
--###################################################################
--#
--#     File    : $(basename "$1")
--#     Author  : $(whoami) $USR_FULL
--#     Created : $(date +%y-%m-%d)
--#
--###################################################################

OUTPUT

# Set the script to executable
printf "[-] Making '$1' executable..\n"
chmod +x $1


# Process complete
printf "[!] Process Complete...\n"
