wok-tiny annotate linux/stuff/pack @ rev 142

Remove ashism ==
author Pascal Bellard <pascal.bellard@slitaz.org>
date Wed Feb 27 17:43:23 2019 +0100 (7 months ago)
parents d22f6fcf51da
children
rev   line source
pascal@139 1 #!/bin/sh
pascal@139 2
pascal@142 3 if [ "$1" = "--build" ]; then #install-begin
pascal@141 4 uuencode -m - < unpacklz4.bin | sed -e '/^unpacklz4\.bin$/r/dev/stdin' \
pascal@141 5 -e '/^unpacklz4\.bin$/d' -i $0
pascal@141 6 cat helper.bin 2>/dev/null | uuencode -m - | sed -e \
pascal@141 7 '/^helper\.bin$/r/dev/stdin' -e '/^helper\.bin$/d' -i $0
pascal@141 8 sed '/install-begin$/,/install-end$/d' -i $0
pascal@141 9 exit
pascal@141 10 fi #install-end
pascal@139 11 ddq()
pascal@139 12 {
pascal@139 13 dd "$@" 2> /dev/null
pascal@139 14 }
pascal@139 15
pascal@139 16 word()
pascal@139 17 {
pascal@139 18 n=$1; for i in $(seq 1 1 ${2:-2}); do
pascal@139 19 printf '\\\\x%02X' $(($n & 255))
pascal@139 20 n=$(($n >> 8))
pascal@139 21 done | xargs echo -en
pascal@139 22 }
pascal@139 23
pascal@139 24 store()
pascal@139 25 {
pascal@139 26 word $2 "$4" | ddq bs=1 conv=notrunc of="$3" seek=$(($1))
pascal@139 27 }
pascal@139 28
pascal@139 29 get()
pascal@139 30 {
pascal@139 31 echo $(od -j $(($1)) -N ${3:-2} -t u${3:-2} -An "$2")
pascal@139 32 }
pascal@139 33
pascal@141 34 helper()
pascal@141 35 {
pascal@141 36 uudecode << EOT
pascal@141 37 helper.bin
pascal@140 38 EOT
pascal@141 39 }
pascal@141 40
pascal@141 41 [ ! -s "$1" ] && echo "Usage: $0 bzImage" && exit 1
pascal@140 42
pascal@139 43 if which lz4 > /dev/null ; then
pascal@139 44
pascal@139 45 # boot + head param
pascal@139 46 param=$((514+$(get 0x201 $1 1)))
pascal@139 47 ddq if=$1 bs=1 count=$param > /tmp/setup$$
pascal@139 48
pascal@139 49 # unlz4 + data
pascal@141 50 uudecode >> /tmp/setup$$ << EOT
pascal@141 51 unpacklz4.bin
pascal@141 52 EOT
pascal@139 53 setupsz=$(get 0x1F1 $1 1)
pascal@139 54 ddq if=$1 bs=1 skip=$param count=$(($setupsz*512-$param+512)) | \
pascal@139 55 lz4 -l -12 | ddq bs=4 skip=1 >> /tmp/setup$$
pascal@139 56
pascal@139 57 # version string
pascal@139 58 word $(get 0x20E $1) >> /tmp/setup$$
pascal@139 59 word $setupsz 1 >> /tmp/setup$$
pascal@141 60 setupend=$(stat -Lc %s "/tmp/setup$$")
pascal@139 61 versionofs=
pascal@139 62 version="$(ddq if=$1 bs=1 skip=$((0x200+$(get 0x20E $1))) | strings | sed q)"
pascal@139 63 if grep --help 2>&1 | grep -q byte-offset; then
pascal@139 64 versionofs=$(grep -obaF "$version" /tmp/setup$$ | sed 's/:.*//')
pascal@139 65 fi
pascal@139 66 if [ -z "$versionofs" ]; then
pascal@139 67 versionofs=$(stat -c %s /tmp/setup$$)
pascal@139 68 echo -en "$version\0" >> /tmp/setup$$
pascal@139 69 fi
pascal@139 70 store 0x20E $(($versionofs-512)) /tmp/setup$$
pascal@139 71
pascal@141 72 helpersz=$(helper | wc -c)
pascal@139 73 newsetupsz=$((($(stat -c %s /tmp/setup$$)+$helpersz-1)/512))
pascal@139 74 [ $newsetupsz -lt 4 ] && newsetupsz=4
pascal@139 75
pascal@139 76 if [ $newsetupsz -lt $setupsz ]; then
pascal@141 77 while [ $(($setupend + $helpersz)) -gt $((512 + 512*$newsetupsz)) ]; do
pascal@141 78 newsetupsz=$(($newsetupsz+1))
pascal@141 79 done
pascal@141 80 # ddq of=/tmp/setup$$ bs=512 seek=$(($newsetupsz+1)) count=0
pascal@141 81 store 0x1F1 $newsetupsz /tmp/setup$$ 1
pascal@141 82 helper | ddq bs=1 of=/tmp/setup$$ \
pascal@139 83 seek=$((512 + 512*$newsetupsz - $helpersz))
pascal@139 84 ddq if=$1 bs=512 skip=$((1+$setupsz)) >> /tmp/setup$$
pascal@139 85 cp /tmp/setup$$ $1
pascal@139 86 fi
pascal@139 87 rm -f /tmp/setup$$
pascal@139 88
pascal@139 89 fi