From bf4189c0dc1d752b7b24ed90aaed10f8558ecef7 Mon Sep 17 00:00:00 2001 From: Alexander Pivovarov Date: Mon, 18 Mar 2024 05:43:09 +0300 Subject: [PATCH] fix: update.sh adds multiple lines to supports.sh #155 (#156) * fix: update.sh adds multiple lines to supports.sh #155 * chore: added comment * chore: converted indentation to tabs --- support.sh | 21 +++++++++++++++++++-- update.sh | 11 ++++++++++- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/support.sh b/support.sh index 29b3ff9..d167638 100644 --- a/support.sh +++ b/support.sh @@ -18,6 +18,25 @@ do_sed () { fi } +# Reverse the file from filename or stdin +do_tac () { + if [ "$(uname)" == "Darwin" ]; then # Mac + # macOS doesn't have tac, so we use tail -r + if (( $# == 0 )) ; then + tail -r < /dev/stdin + else + tail -r "$1" + fi + else # Linux + # linux doesn't have -r option for tail + if (( $# == 0 )) ; then + tac < /dev/stdin + else + tac "$1" + fi + fi +} + set_node_version() { # Versions 1.9 through 2.2 need Node 12.22.1 @@ -61,9 +80,7 @@ set_node_version() { elif [[ "$1" == 2.11.0 ]]; then node_version='14.21.3' elif [[ "$1" == 2.12 ]]; then node_version='14.21.3' elif [[ "$1" == 2.13 ]]; then node_version='14.21.4' - elif [[ "$1" == 2.14 ]]; then node_version='14.21.4' elif [[ "$1" == 2.13.1 ]]; then node_version='14.21.4' - elif [[ "$1" == 2.14 ]]; then node_version='14.21.4' elif [[ "$1" == 2.13.3 ]]; then node_version='14.21.4' elif [[ "$1" == 2.14 ]]; then node_version='14.21.4' fi # End of versions diff --git a/update.sh b/update.sh index db7709c..d8e9c47 100755 --- a/update.sh +++ b/update.sh @@ -108,7 +108,16 @@ else fi -do_sed $"s|'${node_version}'|'${node_version}'\\n elif [[ \"\$1\" == ${new_meteor_version} ]]; then node_version='${new_node_version}'|" ./support.sh + +# Use cat here because the file is being written to in the same command +# Reverse the file, replace the first occurrence of the current node version with __XXXXXX__ as placeholder, +# reverse the file back, replace __XXXXXX__ back and add new line for the new Meteor version, and write the file back +cat ./support.sh \ + | do_tac \ + | sed "1,/'${node_version}'/s|'${node_version}'|'__XXXXXX__'|" \ + | do_tac \ + | sed "s|'__XXXXXX__'|'${node_version}'\\n elif [[ \"\$1\" == ${new_meteor_version} ]]; then node_version='${new_node_version}'|" \ + | tee -i ./support.sh > /dev/null # Update example app dependencies