wok-current view BootProg/stuff/bootprog.sh @ rev 24942

BootProg: clear cmdline
author Pascal Bellard <pascal.bellard@slitaz.org>
date Wed Apr 20 15:10:50 2022 +0000 (2022-04-20)
parents 89c8d8b6cf48
children 810e3d0a38f7
line source
1 #!/bin/sh
3 [ ! -e "$1" ] && cat <<EOT && exit 2
4 Usage: [FAT=<FAT12|FAT16|FAT32|EXFAT>] $0 device [file]
5 Example: $0 /dev/fd0 STARTUP.BIN
6 EOT
8 ddo="dd of=$1 bs=1 conv=notrunc"
9 while read c o b f; do
10 [ "${FAT:-$(dd if="$1" bs=1 count=5 skip=$c)}" = "$f" ] || continue
11 echo "Install $f bootsector on $1."
12 for a in "$((o+b)) seek=$o count=$((512-o))" "$b count=11"; do
13 sed '1,/^exit 1/d' $0 | unlzma | $ddo skip=$a
14 done
15 [ "$2" ] && echo "Set boot file '$2'" && echo -n "$2" | case "$f" in
16 E*) sed 's| |.|;s| ||g' | cat - /dev/zero;;
17 *) tr a-z A-Z | sed 's|\.| |;s|^\(.\{8\}\) *|\1|;s|$| |'
18 esac | $ddo seek=499 count=11
19 [ "$f" = "EXFAT" ] && dd if="$1" bs=512 count=11 | od -v -An -t u1 -w1 - | LANG=C awk '
20 BEGIN { a=0;i=-1;m=0xFFFFFFFE }
21 { if (++i!=106 && i!=107 && i!=112) a=or(and(lshift(a,31),m),and(rshift(a,1),m/2))+$1 }
22 END { b=a/256;c=b/256; for (i=0;i<128;i++) printf "%c%c%c%c",a%256,b%256,c%256,(c/256)%256 }' | $ddo seek=5632
23 exit 0
24 done 2>/dev/null <<EOT
25 54 62 0 FAT12
26 54 62 0 FAT16
27 82 90 512 FAT32
28 3 113 1024 EXFAT
29 EOT
30 exit 1