slitaz-forge view mirror/floppies/sets.sh @ rev 716
mirror/floppies: multi-format support
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Fri Jul 23 16:41:12 2021 +0000 (2021-07-23) |
parents | |
children |
line source
1 #!/bin/sh
3 get()
4 {
5 hexdump -v -s $1 -n ${4:-${3:-2}} -e "\"\" 1/${3:-2} \" %u\n\"" "$2"
6 }
8 n=$((1 + $(get 497 $1/fd001.img 1) + 1 + ($(get 500 $1/fd001.img 4)-1)/32))
9 last=$(($n*512))
10 first=$last
11 dir=$1
12 n=$((512*$(get 497 $1/fd001.img 1) + 512 - 20))
13 SET=""
14 if [ -s $1/fd100.img ]; then
15 for i in 0 1 2 3; do
16 x=$(get $n $1/fd001.img 4)
17 last=$(($last+$x))
18 [ $x -eq 0 ] && SET="" && break
19 SET="$SET $last"
20 n=$(($n+4))
21 done
22 file=$1/fd.img
23 cat $1/fd???.img > $file
24 set -- $first $SET
25 while [ -n "$2" ]; do
26 n=$(get $1 $file)
27 shift
28 case $n in
29 \ 14128|\ 93) continue ;;
30 esac
31 rm $file
32 SET=""
33 break
34 done
35 else
36 if [ $(get 494 $1/fd001.img) -eq 490 ]; then
37 SET="$(($first+$(get 490 $1/fd001.img 4)))"
38 cat $1/fd???.img > $1/fd.img
39 set -- $SET
40 fi
41 fi
42 if [ -n "$SET" ]; then
43 size=$1
44 best=$1
45 cd $dir
46 for i in $(sed '/option value/!d;s|.*value=.||;s|. title.*||' ../format.js); do
47 s=$((((($size-1)/$i)+1)*$i))
48 [ $s -gt $best ] && best=$s
49 dd of=fd.img bs=1 count=0 seek=$s 2> /dev/null
50 [ -d $i ] || mkdir $i
51 cd $i
52 split -b $i ../fd.img xx
53 set -- $SET
54 n=1; sz=0
55 ls xx* | while read x; do
56 mv $x $(printf "fd%03d.img" $n)
57 n=$(($n+1))
58 sz=$(($sz+$i))
59 if [ $sz -ge $1 ]; then
60 n=$(($n-($n%100)+100))
61 shift
62 [ -n "$1" ] || break
63 fi
64 done
65 md5sum fd* > md5sum
66 rm fd*
67 cd ..
68 done
69 dd of=fd.img bs=1 count=0 seek=$best 2> /dev/null
70 cd ..
71 echo $SET
72 fi