From 96fb178dfbdcda3d6a2ebc68de18d0fcb44e11e3 Mon Sep 17 00:00:00 2001 From: AGG2017 Date: Fri, 16 Feb 2024 07:17:05 -0500 Subject: [PATCH] Support for option requirements --- .gitignore | 1 + options.cfg | 8 ++++++-- patch.sh | 40 ++++++++++++++++++++++++++++++++++------ 3 files changed, 41 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index b2a91cb..2740c18 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ FW/*.bin FW/*.swu FW/*.zip unpacked/* +installed_options.log \ No newline at end of file diff --git a/options.cfg b/options.cfg index 134b2f4..81923e1 100644 --- a/options.cfg +++ b/options.cfg @@ -1,9 +1,13 @@ -#--------------------------------------------------------------------------------------- +#------------------------------------------------------------------------------------------------ # 'options.cfg' is the default configuration file used by 'patch.sh' # You can provide another configuration file as a parameter to 'patch.sh' # All available patching options are listed below # Disable patching an option by using '#' or ';' as a first caracter in the option line -#--------------------------------------------------------------------------------------- +# Use single or double quotes for the option value. Do not use spaces inside the quotes. +# Use list of values separated by a space if needed because suplicated option are not supported +# In square brackets you may place the name(s) of other option(s) required by a given option. +# This will not auto include the required option(s) but will be used to validate the option integrity. +#------------------------------------------------------------------------------------------------- # Enable the custom updates by using the provided public key # @ will be replaced by the working folder root diff --git a/patch.sh b/patch.sh index 3b203fa..fc480a6 100755 --- a/patch.sh +++ b/patch.sh @@ -3,6 +3,9 @@ # the default options file optionsfile="options.cfg" +# the result of installed options log +installed_options="installed_options.log" + # global definitions: RED='\033[0;31m' GREEN='\033[0;32m' @@ -39,6 +42,9 @@ while [ $i -lt $((part_num)) ]; do i=$(($i + 1)) done +# remove the old result file for the installed options +rm -f "$installed_options" + # parse the enabled options that have a set value options=$(awk -F '=' '{if (! ($0 ~ /^;/) && ! ($0 ~ /^#/) && ! ($0 ~ /^$/) && ! ($2 == "")) print $1}' "$optionsfile") @@ -63,17 +69,39 @@ for option in $options; do param=$(echo "$parameter" | sed -e 's/^"//' -e 's/"$//') # remove the leading and ending single quotes par=$(echo "$param" | sed -e 's/^'\''//' -e 's/'\''$//') - "$opt_script" "$project_root" "$par" - if [ $? -ne 0 ]; then - # errors found, exit - echo "Errors found! The patching has been canceled." - exit 4 + # remove the leading and ending square brackets + req_option=$(echo "$par" | sed -e 's/^\[//' -e 's/\]$//') + if [ "$par" == "$req_option" ]; then + # current parameter requires processing + "$opt_script" "$project_root" "$par" + if [ $? -ne 0 ]; then + # errors found, exit + echo "Errors found! The patching has been canceled." + exit 4 + fi + # set this option as already installed + echo "$opt_script" >>"$installed_options" + else + # this is an option requirement that needs validation + found="" + for opt in $options; do + if [ "$opt" == "$req_option" ]; then + found="$opt" + break + fi + done + if [ -z "$found" ]; then + # required option is missing or not enabled + echo -e "${RED}ERROR: Option '$option' requires option '$req_option' which is missing or not enabled. ${NC}" + exit 5 + fi + echo -e "${GREEN}Option '$option' requires option '$req_option'. This requirement was successfuly validated. ${NC}" fi done done echo "" -echo -e "${GREEN}DONE! THE SELECTED OPTIONS ARE IMPLEMENTED. IF NEEDED, ADD MORE OPTIONS MANUALLY.${NC}" +echo -e "${GREEN}DONE! The selected options are successfuly processed.${NC}\nYou may do manually more changes in the 'unpacked' folder if needed." echo "" exit 0