From 7d585d67ccd9fc79b9cbc0f19680c292e0a4bdc8 Mon Sep 17 00:00:00 2001 From: bakkeby Date: Sat, 21 Mar 2020 14:44:23 +0100 Subject: [PATCH] Adding --output directory improvements ref. #1 --- README.md | 1 + flexipatch-finalizer.sh | 26 +++++++++++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f7aabc6..b79c6f9 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ This is a custom pre-processor designed to remove unused flexipatch patches and -r, --run include this flag to confirm that you really do want to run this script -d, --directory the flexipatch directory to process (defaults to current directory) + -o, --output the output directory to store the processed files -h, --help display this help section -k, --keep keep temporary files and do not replace the original ones -e, --echo echo commands that will be run rather than running them diff --git a/flexipatch-finalizer.sh b/flexipatch-finalizer.sh index 9209d58..bf2cf71 100755 --- a/flexipatch-finalizer.sh +++ b/flexipatch-finalizer.sh @@ -4,6 +4,7 @@ KEEP_FILES=0 ECHO_COMMANDS=0 RUN_SCRIPT=0 DIRECTORY=. +OUTPUT_DIRECTORY= DEBUG=0 if [[ $# = 0 ]]; then @@ -14,7 +15,12 @@ while (( $# )); do case "$1" in -d|--directory) shift - DIRECTORY=$1 + DIRECTORY=$1 # source directory + shift + ;; + -o|--output) + shift + OUTPUT_DIRECTORY=$1 shift ;; --debug) @@ -43,7 +49,8 @@ while (( $# )); do printf "\n\n" printf "$fmt" "-r, --run" "include this flag to confirm that you really do want to run this script" printf "\n" - printf "$fmt" "-d, --directory " "the flexipatch directory to process (defaults to current directory)" + printf "$fmt" "-d, --directory " "the flexipatch source directory to process (defaults to current directory)" + printf "$fmt" "-o, --output " "the output directory to store the processed files" printf "$fmt" "-h, --help" "display this help section" printf "$fmt" "-k, --keep" "keep temporary files and do not replace the original ones" printf "$fmt" "-e, --echo" "echo commands that will be run rather than running them" @@ -66,6 +73,19 @@ if [[ $RUN_SCRIPT = 0 ]]; then exit 1 fi +if [[ -z ${OUTPUT_DIRECTORY} ]]; then + echo "Output directory not specified, see -o" + exit 1 +fi + +DIRECTORY=$(readlink -f "${DIRECTORY}") +OUTPUT_DIRECTORY=$(readlink -f "${OUTPUT_DIRECTORY}") +if [[ $DIRECTORY != $OUTPUT_DIRECTORY ]]; then + mkdir -p "${OUTPUT_DIRECTORY}" + cp -r -f "${DIRECTORY}/." -t "${OUTPUT_DIRECTORY}" + DIRECTORY=${OUTPUT_DIRECTORY} +fi + if [[ ! -e ${DIRECTORY}/patches.h ]]; then printf "No patches.h file found. Make sure you run this script within a flexipatch source directory." exit 1 @@ -241,7 +261,7 @@ done # Delete unnecessary files if [[ $KEEP_FILES = 0 ]] || [[ $ECHO_COMMANDS = 1 ]]; then - for FILE in $FILES_TO_DELETE; do + for FILE in $FILES_TO_DELETE ${DIRECTORY}/patches.def.h; do if [[ $ECHO_COMMANDS = 1 ]]; then echo "rm $FILE" else