From 73c1fb480c6f12245d6dd1c65abf1cbd0ca7feaa Mon Sep 17 00:00:00 2001 From: Kroese Date: Thu, 2 Oct 2025 17:04:58 +0200 Subject: [PATCH] fix: Refactor basename function --- src/install.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/install.sh b/src/install.sh index e89f3c9..6abe518 100644 --- a/src/install.sh +++ b/src/install.sh @@ -31,8 +31,9 @@ if [ -n "$URL" ] && [ ! -s "$FILE" ] && [ ! -d "$DIR" ]; then BASE=$(basename "$URL" .pat) if [ ! -s "$STORAGE/$BASE.system.img" ]; then BASE=$(basename "${URL%%\?*}" .pat) - : "${BASE//+/ }"; printf -v BASE '%b' "${_//%/\\x}" - BASE=$(echo "$BASE" | sed -e 's/[^A-Za-z0-9._-]/_/g') + BASE="${BASE//+/ }" + printf -v BASE '%b' "${BASE//%/\\x}" + BASE="${BASE//[!A-Za-z0-9._-]/_}" fi if [[ "${URL,,}" != "http"* && "${URL,,}" != "file:"* ]] ; then [ ! -s "$STORAGE/$BASE.pat" ] && error "Invalid URL: $URL" && exit 65 @@ -65,8 +66,9 @@ fi if [ ! -s "$FILE" ]; then BASE=$(basename "${URL%%\?*}" .pat) - : "${BASE//+/ }"; printf -v BASE '%b' "${_//%/\\x}" - BASE=$(echo "$BASE" | sed -e 's/[^A-Za-z0-9._-]/_/g') + BASE="${BASE//+/ }" + printf -v BASE '%b' "${BASE//%/\\x}" + BASE="${BASE//[!A-Za-z0-9._-]/_}" fi if [[ "$URL" != "file://$STORAGE/$BASE.pat" ]]; then