Skip to content

Commit

Permalink
v6.35
Browse files Browse the repository at this point in the history
+ DietPi-Globals | G_EXEC: Use a backslash-escaped command string whenever it is printed through G_DIETPI-NOTIFY to avoid expansion for escape sequences like colour codes and especially newlines
  • Loading branch information
MichaIng authored Jan 25, 2021
1 parent 94ebce5 commit 13a0edf
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions dietpi/func/dietpi-globals
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,7 @@ $grey─────────────────────────
# - $G_ECEC_ARRAY_ACTION[] | Associative array, containing uneven $G_EXEC_ARRAY_TEXT[] values as keys and related commands as values
G_EXEC(){

local exit_code fp_log='/tmp/G_EXEC_LOG' attempt=1 acommand=("$@")
local exit_code fp_log='/tmp/G_EXEC_LOG' attempt=1 acommand=("$@") ecommand=${*//\\/\\\\}

# Enter retry loop
while :
Expand All @@ -877,7 +877,7 @@ $grey─────────────────────────
if [[ $G_EXEC_OUTPUT == 1 ]]; then

# Print $G_EXEC_DESC if given, else raw input command string and show current non-interactive attempt count if $G_EXEC_RETRIES is given
G_DIETPI-NOTIFY 2 "${G_EXEC_DESC:-$*}, please wait...${G_EXEC_RETRIES:+ ($attempt/$((G_EXEC_RETRIES+1)))}"
G_DIETPI-NOTIFY 2 "${G_EXEC_DESC:-$ecommand}, please wait...${G_EXEC_RETRIES:+ ($attempt/$((G_EXEC_RETRIES+1)))}"
[[ $G_EXEC_OUTPUT_COL ]] && echo -ne "$G_EXEC_OUTPUT_COL"
"${acommand[@]}" 2>&1 | tee $fp_log
exit_code=${PIPESTATUS[0]}
Expand All @@ -886,7 +886,7 @@ $grey─────────────────────────
# - Else print animated processing message only
else

G_DIETPI-NOTIFY -2 "${G_EXEC_DESC:-$*}${G_EXEC_RETRIES:+ ($attempt/$((G_EXEC_RETRIES+1)))}"
G_DIETPI-NOTIFY -2 "${G_EXEC_DESC:-$ecommand}${G_EXEC_RETRIES:+ ($attempt/$((G_EXEC_RETRIES+1)))}"
"${acommand[@]}" &> $fp_log
exit_code=$?

Expand All @@ -898,15 +898,15 @@ $grey─────────────────────────
[[ $G_EXEC_NOFAIL == 1 ]] && exit_code=0

### Success: Print OK and exit retry loop
[[ $exit_code == 0 ]] && { G_DIETPI-NOTIFY 0 "${G_EXEC_DESC:-$*}"; break; }
[[ $exit_code == 0 ]] && { G_DIETPI-NOTIFY 0 "${G_EXEC_DESC:-$ecommand}"; break; }

### Error

# Retry non-interactively if current $attempt is <= $G_EXEC_RETRIES
[[ $attempt -le $G_EXEC_RETRIES ]] && { ((attempt++)) && continue; }

# Print FAILED, append raw command string if $G_EXEC_DESC is given
G_DIETPI-NOTIFY 1 "${G_EXEC_DESC:+$G_EXEC_DESC\n - Command: }$*"
G_DIETPI-NOTIFY 1 "${G_EXEC_DESC:+$G_EXEC_DESC\n - Command: }$ecommand"

# Exit retry loop if $G_EXEC_NOHALT=1 is given
[[ $G_EXEC_NOHALT == 1 ]] && break
Expand Down Expand Up @@ -1018,7 +1018,7 @@ $log_content" || break # Exit error handler menu loop on cancel
\nNB: Please only use this solution if you know for sure that it will not cause follow up issues from the originating script. It will e.g. allow you to continue a certain software install, but if you edit the download link, the originating script might expect files which are not present.
\nUse this work caution!'; then

G_DIETPI-NOTIFY 2 "Executing alternative command: $G_WHIP_RETURNED_VALUE"
G_DIETPI-NOTIFY 2 "Executing alternative command: ${G_WHIP_RETURNED_VALUE//\\/\\\\}"
$G_WHIP_RETURNED_VALUE
exit_code=$?
G_DIETPI-NOTIFY -1 $exit_code 'Alternative command execution'
Expand Down

0 comments on commit 13a0edf

Please sign in to comment.