From f0561d1ebe060b0d8a624cb9ce631ddc225faa8d Mon Sep 17 00:00:00 2001 From: Aaron Fiore Date: Mon, 15 Jul 2024 18:10:52 -0700 Subject: [PATCH] client: lib_gen: superscript: append subprofile before generating - Append new subprofile before potentially generating new file - Simplifies backup/writing process - Related refactoring --- client/src/docker/lib/internal/lib_gen.bash | 31 ++++++++------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/client/src/docker/lib/internal/lib_gen.bash b/client/src/docker/lib/internal/lib_gen.bash index a09b969..8f331b0 100644 --- a/client/src/docker/lib/internal/lib_gen.bash +++ b/client/src/docker/lib/internal/lib_gen.bash @@ -461,40 +461,31 @@ function lib_gen::__gen_shell() local _file="$global_shell_file" if [ -f "$_file" ]; then - # Backup - lib_utils::print_custom " \e[32m│ │ └─\e[34m Shell superscript found, backup before continuing? [Y/n] \e[0m" + # Append subprofile source to existing file + lib_utils::print_custom " \e[32m│ │ └─\e[34m Shell superscript found, append new subprofile to existing file? [Y/n] \e[0m" read -p "" _read local _confirm="${_read:-y}" + if [[ "$_confirm" == [yY] ]]; then + grep "$_source" "$_file" >&/dev/null || sed -i "$(wc -l <$_file)i\\$_source\\" "$_file" + fi + # Or generate new file + lib_utils::print_custom " \e[32m│ │ └─\e[34m Backup existing superscript and generate a new one? [N/y] \e[0m" + read -p "" _read + local _confirm="${_read:-n}" if [[ "$_confirm" == [yY] ]]; then # Backup local -r _backup=("cp" "-a" "$_file" "${_file}_${global_suffix}") lib_utils::print_debug "${_backup[@]}" "${_backup[@]}" || lib_utils::die_fatal - fi - - lib_utils::print_custom " \e[32m│ │ └─\e[34m Overwrite existing file? [Y/n] \e[0m" - read -p "" _read - local _confirm="${_read:-y}" - if [[ "$_confirm" == [yY] ]]; then - # Overwrite existing file + # Write lib_gen::__gen_shell_write - else - # Append subprofile source to existing file - lib_utils::print_custom " \e[32m│ │ └─\e[34m Append to existing file? [Y/n] \e[0m" - read -p "" _read - local _confirm="${_read:-y}" - if [[ "$_confirm" == [yY] ]]; then - grep "$_source" "$_file" >&/dev/null || sed -i "$(wc -l <$_file)i\\$_source\\" "$_file" - fi fi - local _print_custom=" \e[32m│ │ └─\e[34m Edit (new) superscript now? [Y/n] \e[0m" else - # Create new file + # Generate new default file lib_gen::__gen_shell_write local _print_custom=" \e[32m│ │ └─\e[34m Edit (new) superscript now? [Y/n] \e[0m" fi - lib_utils::print_custom "$_print_custom" read -p "" _read local _confirm="${_read:-y}"