Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #./bin/TileMolester/${version}/resources
- version[0]="v0.15a"
- version[1]="v0.16"
- version[2]="v0.17a"
- version[3]="v0.18"
- version[4]="v0.19"
- version[5]="v0.20"
- global_args="$*"
- THIS_DIR=""
- function printTMversions() {
- for v in "${version[@]}"
- do
- echo "$v"
- done
- }
- function showVersion() {
- cat << VERSION_EOF
- Bookmarks Installation Script by Europia79
- version 0.20 compiled on December 23th, 2021
- supports TileMolester versions:
- VERSION_EOF
- printTMversions
- }
- function showHelp() {
- cat << HELP_EOF
- Installs bookmarks for your romhack for every version of TileMolester.
- You can install bookmarks 4 ways:
- (1) Drag N Drop either your romhack or bookmark onto this script.
- (2) CLI (Command Line Interface):
- Usage:
- ./bookmarks_install.sh [options] [--] <parameters>
- Options:
- -b the bookmark XML file to install
- -f the romhack file that needs bookmarks
- -h display this help
- -l list all bookmarks installed
- -u uninstall all bookmarks
- -v display the version
- Examples:
- ./bookmarks_install.sh -a NHL94-Example-RomHack.bin -b bookmarks.nhl94.xml
- (3) Declare missing argument parameters when prompted.
- Or simply input null parameter(s) to abort installation.
- (4) Manually copy & paste booksmarks.nhl94.xml (for example) into the folder:
- ./bin/TileMolester/${version}/resources/
- then rename the XML file with the same name as your romhack.
- Example:
- If the name of your romhack is "NHL94-Example-RomHack.bin" (or any other extension),
- then run the following command to get bookmarks in TileMolester v0.15a:
- cp ./bookmarks.nhl94.xml ./bin/TileMolester/v0.15a/resources/NHL94-Example-RomHack.xml
- HELP_EOF
- }
- # CLOSE
- function close() {
- exit 0
- }
- # PAUSE
- function pause() {
- read -rsn1 -p "Press any key to continue..."
- }
- # DIE
- function die() {
- local reason="$1"
- printf "Installation aborted: %s" "${reason}"; echo ""
- pause
- exit 1
- }
- # Null Check for function arguments: $* $1 $2 etc.
- function parseInput() {
- local PARSED_INPUT=""
- if [ -n "$*" ]
- then
- PARSED_INPUT="$*"
- else
- PARSED_INPUT="${global_args}"
- fi
- echo "${PARSED_INPUT}"
- }
- # $(parseFullpath _RETURN_VAR __INPUT_VAL)
- # _RETURN_VAR: $1 = the array used to store the return values
- # __INPUT_VAL: $2 = the input string
- function parseFullpath() {
- local -n returnval=$1
- local input_path=$(parseInput $2)
- # Convert backslashes on \Windows\ to foward slashes: /Windows/
- local FULLPATH="${input_path//\\//}"
- # [0] Strip longest match of */ from start
- file="${FULLPATH##*/}"
- # [1] Substring from 0 thru pos of filename
- dir="${FULLPATH:0:${#FULLPATH} - ${#file}}"
- # [2] Strip shortest match of . plus at least one non-dot char from end
- base="${file%.[^.]*}"
- # [3] If we have an extension and no base, it's really the base
- ext="${file:${#base} + 1}"
- if [ -z "${base}" ] && [ -n "${ext}" ]
- then
- base=".$ext"
- ext=""
- fi
- returnval[0]="${file}"
- returnval[1]="${dir}"
- returnval[2]="${base}"
- returnval[3]="${ext}"
- }
- # gets the entire Filename including extention.
- function getFile() {
- local -a path_array=()
- local file_input=$(parseInput "$*")
- parseFullpath path_array "${file_input}"
- echo "${path_array[0]}"
- }
- # gets the Directory.
- function getDirectory() {
- local -a path_array=()
- local dir_input=$(parseInput "$*")
- parseFullpath path_array "${dir_input}"
- echo "${path_array[1]}"
- }
- # get only the base Filename without the extention.
- function getBase() {
- local -a path_array=()
- local base_input=$(parseInput "$*")
- parseFullpath path_array "${base_input}"
- echo "${path_array[2]}"
- }
- # gets the Extention without the period.
- function getExtention() {
- local -a path_array=()
- local ext_input=$(parseInput "$*")
- parseFullpath path_array "${ext_input}"
- echo "${path_array[3]}"
- }
- function parseBookmark() {
- local input=$(parseInput "$*")
- if [ "xml" = $(getExtention "${input}") ] && [ -f "${input}" ] && [ -z "${bookmark}" ]
- then
- bookmark="${input}"
- fi
- }
- function parseRomhack() {
- local input=$(parseInput "$*")
- if [[ "xml" != $(getExtention "${input}") ]] && [ -f "${input}" ] && [ -z "${romhack}" ]
- then
- romhack="${input}"
- fi
- }
- function promptRomhack() {
- if [ -n "${romhack}" ] ; then return 0; fi
- find . -type f -name '*.md' -exec echo {} \;
- find . -type f -name '*.smd' -exec echo {} \;
- find . -type f -name '*.bin' -exec echo {} \;
- find . -type f -name '*.32x' -exec echo {} \;
- echo "What romhack are you working on ? (Press [Enter] to input or exit)"
- read -p "" romhack
- if [ -z "${romhack}" ]
- then
- die "NULL input."
- elif [ ! -f "${romhack}" ]
- then
- printf "Invalid file: %s" "${romhack}"; echo ""
- die "Please create your romhack file before installing TM Bookmarks for it."
- elif [ -f "${romhack}" ]
- then
- echo "Romhack successfuly found: "
- printf "%s" "${romhack}"; echo ""
- fi
- }
- function promptBookmark() {
- if [ -n "${bookmark}" ] ; then return 0; fi
- find . -maxdepth 1 -type f -name '*.xml' -exec echo {} \;
- echo "What bookmark do you want to use ? (Press [Enter] to input or exit)"
- read -p "" bookmark
- if [ -z "${bookmark}" ]
- then
- die "NULL input."
- elif [ ! -f "${bookmark}" ]
- then
- echo "BAD input: Installation aborted..."
- printf "Invalid file: %s" "${bookmark}"; echo ""
- die "BAD input."
- elif [ -f "${bookmark}" ]
- then
- echo "Bookmark successfully found: "
- printf "%s" "${bookmark}"; echo ""
- fi
- }
- # List all bookmarks installed to
- # ./bin/TileMolester/${version}/resources/*.xml
- function listBookmarks() {
- local total=0
- for v in "${version[@]}"
- do
- local count=0
- local dir="./bin/TileMolester/${v}/resources/"
- find "${dir}" -type f -name '*.xml' -exec echo {} \;
- count=$(find ${dir} -type f -name '*.xml' | wc -l)
- total=$(( total + count ))
- done
- printf "%s total bookmarks installed." "${total}"; echo ""
- }
- # Deletes all bookmarks installed to
- # ./bin/TileMolester/${version}/resources/*.xml
- function _DELETE_ALL_BOOKMARKS() {
- for v in "${version[@]}"
- do
- local dir="./bin/TileMolester/${v}/resources/"
- find "${dir}" -type f -name '*.xml' -exec rm -vf {} \;
- done
- }
- function getFinalConfirmation() {
- local result_C=""
- read -p "FINAL WARNING: Are you absolutely sure that you want to DELETE them ALL ? (Y/n) " result_C
- local C="${result_C}"
- if [[ "$C" = "Y" || "$C" = "y" || "$C" = "YES" || "$C" = "Yes" || "$C" = "yes" ]]
- then
- _DELETE_ALL_BOOKMARKS
- else
- echo "Uninstall aborted..."
- close
- fi
- }
- function getConfirmation() {
- local result_B=""
- read -p "WARNING: Are you sure that you want to uninstall ALL bookmarks ? (Y/n) " result_B
- local B="${result_B}"
- if [[ "$B" = "Y" || "$B" = "y" || "$B" = "YES" || "$B" = "Yes" || "$B" = "yes" ]]
- then
- getFinalConfirmation
- else
- echo "Uninstall aborted..."
- close
- fi
- }
- # Removes all bookmarks installed to
- # ./bin/TileMolester/${version}/resources/*.xml
- function removeBookmarks() {
- listBookmarks
- local result_A=""
- read -p "WARNING: You are about to DELETE all these files: (Y/n) ? " result_A
- local A="${result_A}"
- if [[ "$A" = "Y" || "$A" = "y" || "$A" = "YES" || "$A" = "Yes" || "$A" = "yes" ]]
- then
- getConfirmation
- else
- echo "Uninstall aborted..."
- close
- fi
- }
- # Installs bookmarks for your romhack into
- # ./bin/TileMolester/${version}/resources/
- function doInstallation() {
- for v in "${version[@]}"
- do
- local dir="./bin/TileMolester/${v}/resources/"
- local filename=$(getBase "${romhack}")
- local new_xml="${dir}${filename}.xml"
- echo "dir=${dir}"
- echo "filename=${filename}"
- echo "new_xml=${new_xml}"
- cp --verbose -- "${bookmark}" "${new_xml}"
- done
- }
- ##########################################
- # START #
- ##########################################
- romhack=""
- bookmark=""
- options=":b:f:hluv"
- while getopts "${options}" flag
- do
- case "${flag}" in
- b) bookmark=${OPTARG};;
- f) romhack=${OPTARG};;
- h) showHelp; close;;
- l) listBookmarks; close;;
- u) removeBookmarks; close;;
- v) showVersion; close;;
- *) showHelp; die "Unknown argument: ${flag}";;
- esac
- done
- # Fixes an error on Windows:
- # where Drag N Drop changes the working directory to
- # C:\Windows\system32
- # This changes it back to the directory of this script.
- if [ -n "${global_args}" ] && [ -d $(getDirectory "${global_args}") ]
- then
- THIS_DIR=$(getDirectory "${global_args}")
- cd ${THIS_DIR}
- fi
- # NULL check $romhack file:
- if [ -z "${romhack}" ] && [ -n "$*" ] && [[ "xml" != $(getExtention "$*") ]]
- then
- parseRomhack "${global_args}"
- fi
- if [ -z "${romhack}" ]
- then
- promptRomhack
- fi
- # NULL check $bookmark file:
- if [ -z "${bookmark}" ] && [ -n "$*" ] && [[ "xml" = $(getExtention "$*") ]]
- then
- parseBookmark "${global_args}"
- fi
- if [ -z "${bookmark}" ]
- then
- promptBookmark
- fi
- # INSTALL $bookmark for $romhack
- if [ -f "${bookmark}" ] && [ -f "${romhack}" ]
- then
- echo "Installation started..."
- doInstallation
- echo "Installation complete."
- pause
- close
- fi
- echo "END of script."
- die "Unknown error"
Advertisement
Add Comment
Please, Sign In to add comment