Skip to content

Commit

Permalink
Fix redis-cli carriage-return in output (#508)
Browse files Browse the repository at this point in the history
* redis-cli. Fix output with --raw option

Prevent TTY output format if -r or --raw flags are present. This is
necessary to avoid $'\r' in the output, that breaks shell scripts.

* redis-cli. Use same Redis image version of core
  • Loading branch information
DavidePrincipi committed Nov 6, 2023
1 parent e95a2e8 commit d12ecae
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions core/imageroot/usr/local/sbin/redis-cli
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,20 @@
# along with NethServer. If not, see COPYING.
#

# shellcheck shell=bash

set -e

if [[ -t 0 ]]; then
has_no_raw_option() {
for arg in "${@}"; do
if [[ ${arg} == "-r" || ${arg} == "--raw" ]]; then
return 1
fi
done
return 0
}

if [[ -t 0 ]] && has_no_raw_option "${@}"; then
with_tty=1
fi

Expand All @@ -36,6 +47,7 @@ if [[ $(id -u) == 0 ]]; then
# For the root user, spawn a redis-cli command in the rootfull Redis container
exec podman exec -e REDISCLI_AUTH -i ${with_tty:+-t} redis redis-cli -h "${redis_host}" --user "${redis_user}" "${@}"
else
source /etc/nethserver/core.env
# For non-root users, run a temporary container
exec podman run -e REDISCLI_AUTH -i ${with_tty:+-t} --network=host --rm ghcr.io/nethserver/redis:latest redis-cli -h "${redis_host}" --user "${redis_user}" "${@}"
exec podman run -e REDISCLI_AUTH -i ${with_tty:+-t} --network=host --rm "${REDIS_IMAGE:?}" redis-cli -h "${redis_host}" --user "${redis_user}" "${@}"
fi

0 comments on commit d12ecae

Please sign in to comment.