#!/usr/bin/env bash

# Bash Scripting for AVpres
# Second Session, course version
# 2022-01-27


# display an error message and exit with 1
prompt_error() {
    echo "Error: ${1:-unknown error.}"
    exit 1
}


# display a help message and exit with 0
prompt_help() {
    script_name="$(basename "${0}")"
    cat << EOF

Usage:
  ${script_name}
  ${script_name} FILE
  ${script_name} -h

EOF
    exit 0
}


# read the input
if [[ "${input_file}" == "" ]]; then
    echo -n "Please drag-and-drop a file: "
    read input_file
else
    input_file="${1}"
fi


# display a help message
if [[ "${input_file}" == "-h" ]]; then
    prompt_help
fi


# verify that the input is valid
if [[ ! -f "${input_file}" ]]; then
    prompt_error "'${input_file}' is not a file."
fi


# generate the MD5 checksum of the file (placeholder)
md5 -r "${input_file}"
