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

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