From 2c86415cb439dc296e6b110fea02097dd07bb40c Mon Sep 17 00:00:00 2001 From: Kadic Mirzet Date: Sun, 22 Feb 2026 10:29:17 +0100 Subject: [PATCH] fix: use portable file size detection Replace ls -lh parsing with stat-based approach that works across macOS (BSD) and Linux (GNU), with wc fallback. Generated with [Z.ai](https://z.ai/subscribe?ic=JGTYCX7ZO7) Co-Authored-By: Z.ai GLM-5 --- install.sh | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/install.sh b/install.sh index 4b3595fd3..d13f4f50c 100755 --- a/install.sh +++ b/install.sh @@ -105,6 +105,34 @@ download_file() { fi } +# Get file size in bytes (portable across macOS/Linux) +get_file_size() { + local file="$1" + local size + + # Try stat (macOS/BSD format) + size=$(stat -f%z "$file" 2>/dev/null) && echo "$size" && return 0 + + # Try stat (Linux/GNU format) + size=$(stat -c%s "$file" 2>/dev/null) && echo "$size" && return 0 + + # Fallback to wc + wc -c < "$file" 2>/dev/null | tr -d ' ' +} + +# Format bytes to human readable +format_size() { + local bytes="$1" + + if [ "$bytes" -ge 1048576 ]; then + echo "$((bytes / 1048576))MB" + elif [ "$bytes" -ge 1024 ]; then + echo "$((bytes / 1024))KB" + else + echo "${bytes}B" + fi +} + # Get JSON value (using jq if available, otherwise grep) get_json_value() { local json="$1" @@ -350,7 +378,7 @@ download_picoclaw() { # Show success message local file_size - file_size=$(ls -lh "$dest_path" | awk '{print $5}') + file_size=$(format_size "$(get_file_size "$dest_path")") echo "" msg "$GREEN" "✓ Download complete!"