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