wok view memtest/stuff/pack @ rev 15806
Up: sudoku to 2.3. Fixed WEB_SITE and WGET_URL so we get the app and not a error page.
author | Christopher Rogers <slaxemulator@gmail.com> |
---|---|
date | Fri Jan 24 01:35:01 2014 +0000 (2014-01-24) |
parents | d39aa07ef47c |
children | 99c5dab1a371 |
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=mf=bt2 --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 [ $setup -eq 0 ] && setup=4
41 syssize="$(echo $(od -j 500 -N 2 -dAn $1))"
42 [ $syssize -eq 0 ] && syssize=$((($(stat -c %s $1) + 15 - 512*($setup + 1))/16))
43 store $syssize $2 XXXO
44 store $setup $2 XXXS 1
45 dd if=$1 bs=512 count=$setup skip=1 | compress >>$2
46 dd if=$1 bs=16 count=$syssize skip=$((32*(1+$setup))) | compress >>$2
47 size=$(stat -c %s $2)
48 store $((($size-2560+15)/16)) $2 XXXP
49 store $((($size-2560+15)/16)) $2 500
50 store 4 $2 497 1
51 store $((($size+511)/512)) $2 4
52 store $((($size+15)/16)) $2 14
53 echo -e "$3" | dd conv=notrunc bs=1 seek=YYY of=$2 count=ZZZ
54 }
56 HELP="$(unix2dos <<EOT
57 Memtest86+ is an endless advanced memory diagnostic tool released under the
58 terms of the Gnu Public License (GPL).
60 EOT
61 )"
62 main $1 ${2:-$1.packed} "${3:-$HELP}" 2>/dev/null <<EOT