|
|
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 mformat)" ] || [ -z "$(which mcopy)" ]; then
11: echo "ERROR: 'mformat' or 'mcopy' (from 'mtools' package) missing."
12: exit 2
13: fi
14:
15: # one ZIPFILE given?
16: if [ $# -lt 1 ] || [ -z "$1" ] || [ $# -gt 2 ]; then
17: name=${0##*/}
1.1.1.3 ! root 18: echo "Convert a .zip archive file to a .st disk image."
! 19: echo
! 20: echo "Single intermediate directories in the zip"
! 21: echo "file are skipped."
1.1 root 22: echo
23: echo "Usage:"
24: echo " $name srcname.zip [destname.st]"
25: echo
26: echo "Example:"
27: echo " for zip in *.zip; do $name \$zip; done"
28: echo
29: echo "ERROR: wrong number of argument(s)."
30: exit 1
31: fi
32:
33: ZIPFILE=$1
34: STFILE=$2
35: if [ -z "$STFILE" ]; then
36: # if no STFILE path given, save it to current dir (remove path)
37: # and use the ZIPFILE name with the extension removed.
38: # (done with POSIX shell parameter expansion)
39: BASENAME=${ZIPFILE##*/}
40: BASENAME=${BASENAME%.zip}
41: BASENAME=${BASENAME%.ZIP}
42: STFILE=$BASENAME.st
43: fi
44: if [ -f "$STFILE" ]; then
45: echo "ERROR: ST file '$STFILE' already exists, remove it first. Aborting..."
46: exit 1
47: fi
48:
1.1.1.2 root 49: step=0
1.1 root 50: TEMPDIR=`mktemp -d` || exit 2
51: echo "Converting" $ZIPFILE "->" $TEMPDIR "->" $STFILE
52:
1.1.1.2 root 53: # script exit/error handling
54: exit_cleanup ()
55: {
56: if [ $? -eq 0 ]; then
57: echo "$step) Cleaning up temporary files..."
58: else
59: echo
60: echo "ERROR, cleaning up..."
61: fi
62: echo "rm -rv $TEMPDIR"
63: rm -rv $TEMPDIR
64: echo "Done."
65: }
66: trap exit_cleanup EXIT
67:
1.1 root 68: echo
1.1.1.2 root 69: step=$(($step+1))
1.1 root 70: echo "$step) Unzipping..."
1.1.1.2 root 71: echo "unzip $ZIPFILE -d $TEMPDIR"
72: unzip "$ZIPFILE" -d "$TEMPDIR" || exit 2
1.1 root 73:
74: # .zip files created with STZip sometimes have wrong access rights...
1.1.1.2 root 75: echo "chmod -R u+rw $TEMPDIR/*"
1.1 root 76: chmod -R u+rw $TEMPDIR/*
77:
1.1.1.3 ! root 78: echo
! 79: step=$(($step+1))
! 80: echo "$step) Checking/skipping intermediate directories..."
! 81: ZIPDIR=$TEMPDIR
! 82: while true; do
! 83: count=$(ls $ZIPDIR|wc -l)
! 84: if [ $count -ne 1 ]; then
! 85: if [ $count -eq 0 ]; then
! 86: echo "ERROR: zip content is empty!"
! 87: exit 1
! 88: fi
! 89: # more than one dir/file
! 90: break
! 91: fi
! 92: dir=$(ls $ZIPDIR)
! 93: if [ \! -d "$ZIPDIR/$dir" ]; then
! 94: # not dir
! 95: break
! 96: fi
! 97: if [ -z "$(echo $dir|grep -v -i '^auto$')" ]; then
! 98: # don't skip AUTO dir
! 99: break
! 100: fi
! 101: echo "- $dir"
! 102: ZIPDIR=$ZIPDIR/$dir
! 103: done
1.1 root 104:
105: # size of reserved sectors, FATs & root dir + zip content size
1.1.1.3 ! root 106: size=$((24 + $(du -ks $ZIPDIR|awk '{print $1}')))
1.1 root 107:
108: # find a suitable disk size supported by mformat and Atari ST
109: disksize=0
110: for i in 360 400 720 800 1440 2880; do
111: if [ $i -gt $size ]; then
112: disksize=$i
113: break
114: fi
115: done
116:
117: if [ $disksize -gt 0 ]; then
118: echo
119: step=$(($step+1))
120: echo "$step) Creating $disksize KB disk image..."
1.1.1.2 root 121: echo "dd if=/dev/zero of=$STFILE bs=1024 count=$disksize"
122: dd if=/dev/zero of="$STFILE" bs=1024 count=$disksize
1.1 root 123:
124: echo
125: step=$(($step+1))
126: echo "$step) Formating disk image..."
127: case $disksize in
1.1.1.2 root 128: 360) format="-t 80 -h 1 -n 9" ;;
129: 400) format="-t 80 -h 1 -n 10" ;;
130: 800) format="-t 80 -h 2 -n 10" ;;
131: *) format="-f $disksize" ;;
1.1 root 132: esac
1.1.1.2 root 133: echo "mformat -a $format -i $STFILE ::"
134: mformat -a $format -i "$STFILE" ::
1.1 root 135:
136: echo
137: step=$(($step+1))
138: echo "$step) Copying data to disk image..."
1.1.1.3 ! root 139: echo "MTOOLS_NO_VFAT=1 mcopy -i $STFILE -spmv $ZIPDIR/* ::"
! 140: MTOOLS_NO_VFAT=1 mcopy -i "$STFILE" -spmv $ZIPDIR/* ::
1.1 root 141: else
142: echo "ERROR: zip contents don't fit to a floppy image ($size > 2880 KB)."
143: fi
144:
145: echo
146: step=$(($step+1))
1.1.1.2 root 147: # do cleanup in exit handler
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.