|
|
1.1 root 1: #!/bin/sh
2: # Script for converting .ZIP archives to Atari .ST disk images
3: # (for the Hatari emulator).
4:
5: # tools are present?
6: if [ -z "$(which unzip)" ]; then
7: echo "ERROR: 'unzip' missing."
8: exit 2
9: fi
10: if [ -z "$(which rename)" ]; then
11: echo "ERROR: 'rename' script (from 'util-linux' package) missing."
12: exit 2
13: fi
14: if [ -z "$(which mformat)" ] || [ -z "$(which mcopy)" ]; then
15: echo "ERROR: 'mformat' or 'mcopy' (from 'mtools' package) missing."
16: exit 2
17: fi
18:
19: # one ZIPFILE given?
20: if [ $# -lt 1 ] || [ -z "$1" ] || [ $# -gt 2 ]; then
21: name=${0##*/}
22: echo "Convert .ZIP files to .ST disk images."
23: echo "This script requires the mtools package."
24: echo
25: echo "Usage:"
26: echo " $name srcname.zip [destname.st]"
27: echo
28: echo "Example:"
29: echo " for zip in *.zip; do $name \$zip; done"
30: echo
31: echo "ERROR: wrong number of argument(s)."
32: exit 1
33: fi
34:
35: ZIPFILE=$1
36: STFILE=$2
37: if [ -z "$STFILE" ]; then
38: # if no STFILE path given, save it to current dir (remove path)
39: # and use the ZIPFILE name with the extension removed.
40: # (done with POSIX shell parameter expansion)
41: BASENAME=${ZIPFILE##*/}
42: BASENAME=${BASENAME%.zip}
43: BASENAME=${BASENAME%.ZIP}
44: STFILE=$BASENAME.st
45: fi
46: if [ -f "$STFILE" ]; then
47: echo "ERROR: ST file '$STFILE' already exists, remove it first. Aborting..."
48: exit 1
49: fi
50:
51: TEMPDIR=`mktemp -d` || exit 2
52: echo "Converting" $ZIPFILE "->" $TEMPDIR "->" $STFILE
53:
54: echo
55: step=1
56: echo "$step) Unzipping..."
57: unzip $ZIPFILE -d $TEMPDIR || exit 2
58:
59: # .zip files created with STZip sometimes have wrong access rights...
60: chmod -R u+rw $TEMPDIR/*
61:
62: WORKINGDIR=`pwd`
63:
64: echo
65: step=$(($step+1))
66: echo "$step) Changing file names to upper case..."
67: for i in `find $TEMPDIR/* -depth` ; do
68: cd `dirname $i`
69: rename -v 'y/a-z/A-Z/' `basename $i`
70: done
71:
72: cd $WORKINGDIR
73:
74: # size of reserved sectors, FATs & root dir + zip content size
75: size=$((24 + $(du -ks $TEMPDIR|awk '{print $1}')))
76:
77: # find a suitable disk size supported by mformat and Atari ST
78: disksize=0
79: for i in 360 400 720 800 1440 2880; do
80: if [ $i -gt $size ]; then
81: disksize=$i
82: break
83: fi
84: done
85:
86: if [ $disksize -gt 0 ]; then
87: echo
88: step=$(($step+1))
89: echo "$step) Creating $disksize KB disk image..."
90: dd if=/dev/zero of=$STFILE bs=1024 count=$disksize
91:
92: echo
93: step=$(($step+1))
94: echo "$step) Formating disk image..."
95: case $disksize in
96: 360) mformat -i $STFILE -t 80 -h 1 -n 9 -a :: ;;
97: 400) mformat -i $STFILE -t 80 -h 1 -n 10 -a :: ;;
98: 800) mformat -i $STFILE -t 80 -h 2 -n 10 -a :: ;;
99: *) mformat -i $STFILE -f $disksize -a :: ;;
100: esac
101:
102: echo
103: step=$(($step+1))
104: echo "$step) Copying data to disk image..."
105: mcopy -i $STFILE -spmv $TEMPDIR/* ::
106: else
107: echo "ERROR: zip contents don't fit to a floppy image ($size > 2880 KB)."
108: fi
109:
110: echo
111: step=$(($step+1))
112: echo "$step) Cleaning up temporary files..."
113: rm -rv $TEMPDIR
114:
115: echo "Done."
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.