summaryrefslogtreecommitdiffstats
path: root/lsinitcpio
diff options
context:
space:
mode:
authorDave Reisner <dreisner@archlinux.org>2012-04-19 00:47:08 +0200
committerDave Reisner <dreisner@archlinux.org>2012-04-22 05:43:52 +0200
commitd13917104528fba28cd110373f130b3149002782 (patch)
tree6748155a2892866b7b7869be2e0a576db643a265 /lsinitcpio
parent29625b7bdb80289a0609bdd0f53b6a71dd2f5ab1 (diff)
downloadmkinitcpio-d13917104528fba28cd110373f130b3149002782.tar.gz
mkinitcpio-d13917104528fba28cd110373f130b3149002782.tar.xz
lsinitcpio: show file sizes in analyze output
Always display the file size on disk, but also display the uncompressed size for compressed images. Borrows my own size_to_human function from paccache and elsewhere. Before: ==> Compressed with: gzip -> Compression ratio: .377 -> Estimated decompression time: 0.058s After: ==> Size: 2.67 MiB ==> Compressed with: gzip -> Uncompressed size: 7.07 MiB (.377 ratio) -> Estimated decompression time: 0.059s Signed-off-by: Dave Reisner <dreisner@archlinux.org>
Diffstat (limited to 'lsinitcpio')
-rwxr-xr-xlsinitcpio31
1 files changed, 28 insertions, 3 deletions
diff --git a/lsinitcpio b/lsinitcpio
index aa97df7..55ce1e8 100755
--- a/lsinitcpio
+++ b/lsinitcpio
@@ -39,6 +39,28 @@ die() {
exit 1
}
+size_to_human() {
+ awk -v size="$1" '
+ BEGIN {
+ suffix[1] = "B"
+ suffix[2] = "KiB"
+ suffix[3] = "MiB"
+ suffix[4] = "GiB"
+ suffix[5] = "TiB"
+ count = 1
+
+ while (size > 1024) {
+ size /= 1024
+ count++
+ }
+
+ sizestr = sprintf("%.2f", size)
+ sub(/\.?0+$/, "", sizestr)
+ printf("%s %s", sizestr, suffix[count])
+ }'
+}
+
+
OPT_SHORT='ahnvx'
OPT_LONG=('analyze' 'help' 'nocolor' 'verbose' 'extract')
@@ -105,11 +127,13 @@ if (( analyze )); then
declare -a binaries explicitmod modules foundhooks hooks
declare kernver ratio columns=$(tput cols)
+ zsize=$(stat -c %s "$image")
+
# calculate compression ratio
if [[ $compress ]]; then
TIMEFORMAT=%R decomptime=$({ time decomp "$image" >/dev/null; } 2>&1 )
- ratio=.$(( $(stat -c %s "$image") * 1000 /
- $(decomp "$image" | bsdtar xOf - | wc -c) % 1000 ))
+ fullsize=$(decomp "$image" | bsdtar xOf - | wc -c)
+ ratio=.$(( zsize * 1000 / fullsize % 1000 ))
fi
# read contents of image
@@ -141,10 +165,11 @@ if (( analyze )); then
msg 'Image: %s %s' "$imagename"
[[ $version ]] && msg 'Created with mkinitcpio %s' "$version"
msg 'Kernel: %s' "${kernver:-unknown}"
+ msg 'Size: %s' "$(size_to_human "$zsize")"
if [[ $compress ]]; then
msg 'Compressed with: %s' "$compress"
- msg2 'Compression ratio: %s' "$ratio"
+ msg2 'Uncompressed size: %s (%s ratio)' "$(size_to_human "$fullsize")" "$ratio"
msg2 'Estimated decompression time: %ss' "$decomptime"
fi
printf '\n'