wok-6.x view memtest/stuff/pack @ rev 13287
memtest: lzma compression
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Sun Aug 26 00:21:22 2012 +0200 (2012-08-26) |
parents | 18d1dc85701e |
children | e76c37f7bfe6 |
line source
1 #!/bin/sh
2 if [ "$1" == "--build" ]; then
3 cat >> $0 <<EOM
4 $(gzip -9 < ${2:-unpack.bin} | uuencode -m -)
5 EOT
6 EOM
7 sed -i '/--build/,/^fi/d' $0
8 exit
9 fi
11 store()
12 {
13 n=$1
14 for i in $(seq 1 $4); do
15 printf '\\\\x%02X' $(($n & 255))
16 n=$(($n >> 8))
17 done | xargs echo -en | dd conv=notrunc bs=1 of=$2 seek=$3
18 }
20 compress()
21 {
22 lzma e -si -so
23 }
25 main()
26 {
27 dd if=$1 bs=512 count=1 >$2
28 uudecode | gunzip >>$2
29 setup="$( echo $(od -j 497 -N 1 -dAn $1))"
30 syssize="$(echo $(od -j 500 -N 2 -dAn $1))"
31 dd if=$1 bs=512 count=$setup skip=1 | compress >>$2
32 dd if=$1 bs=16 count=$syssize skip=$((32*(1+$setup))) | compress >>$2
33 size=$(stat -c %s $2)
34 store $((($size-512)/16)) $2 520 2
35 store $((($size-2560)/16)) $2 500 2
36 store 4 $2 497 1
37 }
39 main $1 $2 2>/dev/null <<EOT