wok-6.x annotate memtest/stuff/pack @ rev 19403

isolinux/iso2exe: fix copycmdline()
author Pascal Bellard <pascal.bellard@slitaz.org>
date Mon Sep 05 18:15:15 2016 +0200 (2016-09-05)
parents 50b423f7711b
children 4ebd023252ac
rev   line source
pascal@13269 1 #!/bin/sh
pascal@13269 2 if [ "$1" == "--build" ]; then
pascal@15188 3 set -- ${2:-bootloader.bin} ${3:-unpack.bin}
pascal@19391 4 x=$(grep -s packed_syssize$ ${2/.bin/.lst}|sed '$!d;s/.*t:\([^ ]*\).*/\1/')
pascal@19391 5 [ -n "$x" ] && sed -i "s/XXXP/$((513+0x$x))/" $0 || sed -i "/XXXP$/d" $0
pascal@19391 6 x=$(grep -s original_syssize$ ${2/.bin/.lst}|sed '$!d;s/.*t:\([^ ]*\).*/\1/')
pascal@19391 7 [ -n "$x" ] && sed -i "s/XXXO/$((513+0x$x))/" $0 || sed -i "/XXXO$/d" $0
pascal@19391 8 x=$(grep -s original_setupsize$ ${2/.bin/.lst}|sed '$!d;s/.*t:\([^ ]*\).*/\1/')
pascal@19391 9 [ -n "$x" ] && sed -i "s/XXXS/$((516+0x$x))/" $0 || sed -i "/XXXS$/d" $0
pascal@19403 10 grep -q 83C60D ${3/.bin/.lst} && sed -i 's/ | dd bs=1 skip=13//' $0
pascal@15188 11 helpmsg=$(sed '/helpmsg:/!d{n;s/ [0-9]* \([^ ]*\).*/\1/}' ${1/.bin/.lst} | sed '$!d')
pascal@17223 12 helpend=$(sed '/helpend:/!d{n;s/ [0-9]* \([^ ]*\).*/\1/}' ${1/.bin/.lst} | sed '$!d')
pascal@15188 13 sed -i "s/YYY/$((0x$helpmsg))/" $0
pascal@19196 14 sed -i "s/ZZZ/$((0x$helpend-0x$helpmsg-1))/" $0
pascal@17223 15 cat >> $0 <<EOM
pascal@17223 16 $(dd if=$1 bs=512 count=1 conv=sync | cat - $2 | gzip -9 | uuencode -m -)
pascal@17223 17 EOT
pascal@17223 18 EOM
pascal@13269 19 sed -i '/--build/,/^fi/d' $0
pascal@13269 20 exit
pascal@13269 21 fi
pascal@13269 22
pascal@13269 23 store()
pascal@13269 24 {
pascal@13269 25 n=$1
pascal@15188 26 for i in $(seq 1 ${4:-2}); do
pascal@13269 27 printf '\\\\x%02X' $(($n & 255))
pascal@13269 28 n=$(($n >> 8))
pascal@13269 29 done | xargs echo -en | dd conv=notrunc bs=1 of=$2 seek=$3
pascal@13269 30 }
pascal@13269 31
pascal@13269 32 compress()
pascal@13269 33 {
pascal@19403 34 xz -z -e --format=lzma --lzma1=mf=bt2 --stdout | dd bs=1 skip=13
pascal@13269 35 }
pascal@13269 36
pascal@13269 37 main()
pascal@13269 38 {
pascal@15188 39 uudecode | gunzip >$2
pascal@15188 40 dd if=$1 bs=1 skip=497 seek=497 count=15 of=$2 conv=notrunc
pascal@13289 41 setup="$(echo $(od -j 497 -N 1 -dAn $1))"
pascal@15480 42 [ $setup -eq 0 ] && setup=4
pascal@13287 43 syssize="$(echo $(od -j 500 -N 2 -dAn $1))"
pascal@15480 44 [ $syssize -eq 0 ] && syssize=$((($(stat -c %s $1) + 15 - 512*($setup + 1))/16))
pascal@15193 45 store $syssize $2 XXXO
pascal@15193 46 store $setup $2 XXXS 1
pascal@13269 47 dd if=$1 bs=512 count=$setup skip=1 | compress >>$2
pascal@13269 48 dd if=$1 bs=16 count=$syssize skip=$((32*(1+$setup))) | compress >>$2
pascal@13269 49 size=$(stat -c %s $2)
pascal@15189 50 store $((($size-2560+15)/16)) $2 XXXP
pascal@15189 51 store $((($size-2560+15)/16)) $2 500
pascal@13269 52 store 4 $2 497 1
pascal@15188 53 store $((($size+511)/512)) $2 4
pascal@15188 54 store $((($size+15)/16)) $2 14
pascal@15480 55 echo -e "$3" | dd conv=notrunc bs=1 seek=YYY of=$2 count=ZZZ
pascal@13269 56 }
pascal@13269 57
pascal@15188 58 HELP="$(unix2dos <<EOT
pascal@19399 59 Memtest86+ VERSION is an endless advanced memory diagnostic tool (GPL).
pascal@15188 60 EOT
pascal@15188 61 )"
pascal@15188 62 main $1 ${2:-$1.packed} "${3:-$HELP}" 2>/dev/null <<EOT