Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

lsinitramfs: add compression ratio and decomp time

  • Loading branch information...
commit e35b298bb4a9b8b6e2f44b15dc5a7946555a851c 1 parent 6cf8c15
@falconindy authored
Showing with 22 additions and 4 deletions.
  1. +22 −4 lsinitramfs
View
26 lsinitramfs
@@ -75,17 +75,29 @@ declare image=$1
if (( analyze )); then
declare -a binaries explicitmod modules foundhooks hooks
- declare kernver compress
+ declare kernver compress ratio
# read compression type
case "$(file -b "$image")" in
data|lzma*) compress=LZMA ;;
- ASCII*) compress=none ;;
gzip*) compress=gzip ;;
bzip2*) compress=bzip2 ;;
XZ*) compress=XZ ;;
esac
+ # calculate compression ratio
+ if [[ $compress ]]; then
+ divide() {
+ local A=$1 B=$2 ratio=
+
+ ratio=$(( A * 10000 / B % 10000 ))
+ printf '%s.%s%%\n' "${ratio:0:2}" "${ratio:2}"
+ }
+
+ TIMEFORMAT=%R decomptime=$({ time bsdtar Oxf "$image" >/dev/null; } 2>&1 )
+ ratio=$(divide "$(stat -c %s "$image")" "$(bsdtar Oxf "$image" | wc -c)")
+ fi
+
# read contents of image
while read -r line; do
if [[ $line = *.ko?(.gz) ]]; then # module
@@ -112,11 +124,17 @@ if (( analyze )); then
;;
"%MODULES%") explicitmod=("${line[@]:2}") ;;
esac
- done < <(bsdtar Oxf "$image" config)
+ done < <(bsdtar xOf "$image" config)
# print results
+ printf '==> Image: %s\n' "$(readlink -e "$image")"
printf '==> Kernel: %s\n' "${kernver:-unknown}"
- printf '==> Compressed with: %s\n' "${compress:-unknown}"
+
+ if [[ $compress ]]; then
+ printf '==> Compressed with: %s\n' "$compress"
+ printf ' -> Compression ratio: %s\n' "$ratio"
+ printf ' -> Estimated decompression time: %ss\n' "$decomptime"
+ fi
printf '\n'
printf '==> Included modules:\n'
Please sign in to comment.
Something went wrong with that request. Please try again.