wok view memtest/stuff/pack @ rev 15193
Add larch
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Fri Aug 30 11:24:48 2013 +0000 (2013-08-30) |
parents | 20fd4e3d8970 |
children | 8267887ae7af |
line source
1 #!/bin/sh
2 if [ "$1" == "--build" ]; then
3 set -- ${2:-bootloader.bin} ${3:-unpack.bin}
4 cat >> $0 <<EOM
5 $(dd if=$1 bs=512 count=1 conv=sync | cat - $2 | gzip -9 | uuencode -m -)
6 EOT
7 EOM
8 x=$(grep -s packed_syssize ${2/.bin/.lst}|sed '$!d;s/.*t:\([^ ]*\).*/\1/')
9 [ -n "$x" ] && sed -i "s/XXXP/$((513+0x$x))/" $0 || sed -i s="/XXXP$/d" $0
10 x=$(grep -s original_syssize ${2/.bin/.lst}|sed '$!d;s/.*t:\([^ ]*\).*/\1/')
11 [ -n "$x" ] && sed -i "s/XXXO/$((513+0x$x))/" $0 || sed -i s="/XXXO$/d" $0
12 x=$(grep -s original_setupsize ${2/.bin/.lst}|sed '$!d;s/.*t:\([^ ]*\).*/\1/')
13 [ -n "$x" ] && sed -i "s/XXXS/$((516+0x$x))/" $0 || sed -i s="/XXXS$/d" $0
14 helpmsg=$(sed '/helpmsg:/!d{n;s/ [0-9]* \([^ ]*\).*/\1/}' ${1/.bin/.lst} | sed '$!d')
15 sed -i "s/YYY/$((0x$helpmsg))/" $0
16 sed -i "s/ZZZ/$((496-0x$helpmsg))/" $0
17 sed -i '/--build/,/^fi/d' $0
18 exit
19 fi
21 store()
22 {
23 n=$1
24 for i in $(seq 1 ${4:-2}); do
25 printf '\\\\x%02X' $(($n & 255))
26 n=$(($n >> 8))
27 done | xargs echo -en | dd conv=notrunc bs=1 of=$2 seek=$3
28 }
30 compress()
31 {
32 xz -z -e --format=lzma --lzma1=mode=normal --stdout
33 }
35 main()
36 {
37 uudecode | gunzip >$2
38 dd if=$1 bs=1 skip=497 seek=497 count=15 of=$2 conv=notrunc
39 setup="$(echo $(od -j 497 -N 1 -dAn $1))"
40 syssize="$(echo $(od -j 500 -N 2 -dAn $1))"
41 store $syssize $2 XXXO
42 store $setup $2 XXXS 1
43 [ $syssize -eq 0 ] && syssize=$((($(stat -c %s $1) + 15 - 512*($setup + 1))/16))
44 dd if=$1 bs=512 count=$setup skip=1 | compress >>$2
45 dd if=$1 bs=16 count=$syssize skip=$((32*(1+$setup))) | compress >>$2
46 size=$(stat -c %s $2)
47 store $((($size-2560+15)/16)) $2 XXXP
48 store $((($size-2560+15)/16)) $2 500
49 store 4 $2 497 1
50 store $((($size+511)/512)) $2 4
51 store $((($size+15)/16)) $2 14
52 echo -en "$3" | dd conv=notrunc bs=1 seek=YYY of=$2 count=ZZZ
53 }
55 HELP="$(unix2dos <<EOT
56 Memtest86+ is an endless advanced memory diagnostic tool released under the
57 terms of the Gnu Public License (GPL).
59 EOT
60 )"
61 main $1 ${2:-$1.packed} "${3:-$HELP}" 2>/dev/null <<EOT