From 879862f9ef73b6882797a407d0e2bb76a845b37e Mon Sep 17 00:00:00 2001 From: angrybayblade Date: Wed, 5 Jun 2024 21:08:03 +0530 Subject: [PATCH] fix: script multiline --- electron/scripts.js | 85 ++++++++++++-------------------- electron/scripts/install_brew.sh | 3 +- 2 files changed, 33 insertions(+), 55 deletions(-) diff --git a/electron/scripts.js b/electron/scripts.js index 35886641..d3f388aa 100644 --- a/electron/scripts.js +++ b/electron/scripts.js @@ -5,8 +5,7 @@ const BrewScript = "# We don't need return codes for \"$(command)\", only stdout "set -u\n" + "\n" + "abort() {\n" + -" printf \"%s\n" + -"\" \"$@\" >&2\n" + +" printf \"%s\\n\" \"$@\" >&2\n" + " exit 1\n" + "}\n" + "\n" + @@ -63,7 +62,7 @@ const BrewScript = "# We don't need return codes for \"$(command)\", only stdout "# string formatters\n" + "if [[ -t 1 ]]\n" + "then\n" + -" tty_escape() { printf \"[%sm\" \"$1\"; }\n" + +" tty_escape() { printf \"\\033[%sm\" \"$1\"; }\n" + "else\n" + " tty_escape() { :; }\n" + "fi\n" + @@ -81,23 +80,20 @@ const BrewScript = "# We don't need return codes for \"$(command)\", only stdout " for arg in \"$@\"\n" + " do\n" + " printf \" \"\n" + -" printf \"%s\" \"${arg// /\ }\"\n" + +" printf \"%s\" \"${arg// /\\ }\"\n" + " done\n" + "}\n" + "\n" + "chomp() {\n" + -" printf \"%s\" \"${1/\"$'\n" + -"'\"/}\"\n" + +" printf \"%s\" \"${1/\"$'\\n'\"/}\"\n" + "}\n" + "\n" + "ohai() {\n" + -" printf \"${tty_blue}==>${tty_bold} %s${tty_reset}\n" + -"\" \"$(shell_join \"$@\")\"\n" + +" printf \"${tty_blue}==>${tty_bold} %s${tty_reset}\\n\" \"$(shell_join \"$@\")\"\n" + "}\n" + "\n" + "warn() {\n" + -" printf \"${tty_red}Warning${tty_reset}: %s\n" + -"\" \"$(chomp \"$1\")\" >&2\n" + +" printf \"${tty_red}Warning${tty_reset}: %s\\n\" \"$(chomp \"$1\")\" >&2\n" + "}\n" + "\n" + "# Check if script is run non-interactively (e.g. CI)\n" + @@ -290,7 +286,7 @@ const BrewScript = "# We don't need return codes for \"$(command)\", only stdout " # Use the shell's audible bell.\n" + " if [[ -t 1 ]]\n" + " then\n" + -" printf \"\"\n" + +" printf \"\\a\"\n" + " fi\n" + "}\n" + "\n" + @@ -299,13 +295,7 @@ const BrewScript = "# We don't need return codes for \"$(command)\", only stdout " echo\n" + " echo \"Press ${tty_bold}RETURN${tty_reset}/${tty_bold}ENTER${tty_reset} to continue or any other key to abort:\"\n" + " getc c\n" + -" # we test for \n" + -" and \n" + -" because some stuff does \n" + -" instead\n" + -" if ! [[ \"${c}\" == $'\n" + -"' || \"${c}\" == $'\n" + -"' ]]\n" + +" if ! [[ \"${c}\" == $'\\r' || \"${c}\" == $'\\n' ]]\n" + " then\n" + " exit 1\n" + " fi\n" + @@ -389,7 +379,9 @@ const BrewScript = "# We don't need return codes for \"$(command)\", only stdout " return 1\n" + " fi\n" + "\n" + -" \"$1\" --enable-frozen-string-literal --disable=gems,did_you_mean,rubyopt -rrubygems -e \"abort if Gem::Version.new(RUBY_VERSION.to_s.dup).to_s.split('.').first(2) != Gem::Version.new('${REQUIRED_RUBY_VERSION}').to_s.split('.').first(2)\" 2>/dev/null\n" + +" \"$1\" --enable-frozen-string-literal --disable=gems,did_you_mean,rubyopt -rrubygems -e \\\n" + +" \"abort if Gem::Version.new(RUBY_VERSION.to_s.dup).to_s.split('.').first(2) != \\\n" + +" Gem::Version.new('${REQUIRED_RUBY_VERSION}').to_s.split('.').first(2)\" 2>/dev/null\n" + "}\n" + "\n" + "test_curl() {\n" + @@ -455,7 +447,7 @@ const BrewScript = "# We don't need return codes for \"$(command)\", only stdout "\n" + "outdated_glibc() {\n" + " local glibc_version\n" + -" glibc_version=\"$(ldd --version | head -n1 | grep -o '[0-9.]*$' | grep -o '^[0-9]\+\.[0-9]\+')\"\n" + +" glibc_version=\"$(ldd --version | head -n1 | grep -o '[0-9.]*$' | grep -o '^[0-9]\\\+\\\.[0-9]\\\+')\"\n" + " version_lt \"${glibc_version}\" \"${REQUIRED_GLIBC_VERSION}\"\n" + "}\n" + "\n" + @@ -497,7 +489,7 @@ const BrewScript = "# We don't need return codes for \"$(command)\", only stdout "then\n" + " abort \"$(\n" + " cat <> ${shell_rcfile}\n" + -" eval \"\$(${HOMEBREW_PREFIX}/bin/brew shellenv)\"\n" + +" (echo; echo 'eval \"\\$(${HOMEBREW_PREFIX}/bin/brew shellenv)\"') >> ${shell_rcfile}\n" + +" eval \"\\$(${HOMEBREW_PREFIX}/bin/brew shellenv)\"\n" + "EOS\n" + "fi\n" + "\n" + @@ -1070,14 +1057,10 @@ const BrewScript = "# We don't need return codes for \"$(command)\", only stdout " then\n" + " plural=\"s\"\n" + " fi\n" + -" printf -- \"- Run these commands in your terminal to add the non-default Git remote%s for %s:\n" + -"\" \"${plural}\" \"${non_default_repos}\"\n" + -" printf \" echo '# Set PATH, MANPATH, etc., for Homebrew.' >> %s\n" + -"\" \"${shell_rcfile}\"\n" + -" printf \" echo '%s' >> ${shell_rcfile}\n" + -"\" \"${additional_shellenv_commands[@]}\"\n" + -" printf \" %s\n" + -"\" \"${additional_shellenv_commands[@]}\"\n" + +" printf -- \"- Run these commands in your terminal to add the non-default Git remote%s for %s:\\n\" \"${plural}\" \"${non_default_repos}\"\n" + +" printf \" echo '# Set PATH, MANPATH, etc., for Homebrew.' >> %s\\n\" \"${shell_rcfile}\"\n" + +" printf \" echo '%s' >> ${shell_rcfile}\\n\" \"${additional_shellenv_commands[@]}\"\n" + +" printf \" %s\\n\" \"${additional_shellenv_commands[@]}\"\n" + "fi\n" + "\n" + "if [[ -n \"${HOMEBREW_ON_LINUX-}\" ]]\n" + @@ -1112,8 +1095,4 @@ const BrewScript = "# We don't need return codes for \"$(command)\", only stdout " ${tty_underline}https://docs.brew.sh${tty_reset}\n" + "\n" + "EOS\n" - - -module.exports = { - BrewScript -} \ No newline at end of file +module.exports = {BrewScript} diff --git a/electron/scripts/install_brew.sh b/electron/scripts/install_brew.sh index 580936c1..46c41f31 100644 --- a/electron/scripts/install_brew.sh +++ b/electron/scripts/install_brew.sh @@ -295,7 +295,6 @@ wait_for_user() { echo echo "Press ${tty_bold}RETURN${tty_reset}/${tty_bold}ENTER${tty_reset} to continue or any other key to abort:" getc c - # we test for \r and \n because some stuff does \r instead if ! [[ "${c}" == $'\r' || "${c}" == $'\n' ]] then exit 1 @@ -1095,4 +1094,4 @@ cat <