diff --git a/podkop/files/usr/bin/podkop b/podkop/files/usr/bin/podkop index 0f4f2a4..6534f6a 100755 --- a/podkop/files/usr/bin/podkop +++ b/podkop/files/usr/bin/podkop @@ -1307,6 +1307,7 @@ import_domains_or_subnets_from_remote_file() { http_proxy_address="$(get_service_proxy_address)" download_to_file "$url" "$tmpfile" "$http_proxy_address" + convert_crlf_to_lf "$tmpfile" if [ $? -ne 0 ] || [ ! -s "$tmpfile" ]; then log "Download $url list failed" "error" diff --git a/podkop/files/usr/lib/helpers.sh b/podkop/files/usr/lib/helpers.sh index 7af83f2..5801fec 100644 --- a/podkop/files/usr/lib/helpers.sh +++ b/podkop/files/usr/lib/helpers.sh @@ -305,10 +305,17 @@ download_to_file() { log "Attempt $attempt/$retries to download $url failed" "warn" sleep "$wait" done +} + +# Converts Windows-style line endings (CRLF) to Unix-style (LF) +convert_crlf_to_lf() { + local filepath="$1" if grep -q $'\r' "$filepath"; then - log "Downloaded file has Windows line endings (CRLF). Converting to Unix (LF)" - sed -i 's/\r$//' "$filepath" + log "Downloaded file has Windows line endings (CRLF). Converting to Unix (LF)" "debug" + local tmpfile + tmpfile=$(mktemp) + tr -d '\r' < "$filepath" > "$tmpfile" && mv "$tmpfile" "$filepath" fi }