zip2img

A small utility to converts ZIP archives to MS-DOS compatible disk images (virtual floppies) 💾️

zip2img (1047B)

 1 #!/bin/sh
 2 #      _        _____ _                 
 3 #     (_)      / __  (_)                
 4 #  _____ _ __  `' / /'_ _ __ ___   __ _ 
 5 # |_  / | '_ \   / / | | '_ ` _ \ / _` |
 6 #  / /| | |_) |./ /__| | | | | | | (_| |
 7 # /___|_| .__/ \_____/_|_| |_| |_|\__, |
 8 #       | |                        __/ |
 9 #       |_|                       |___/ 
10 #
11 # Converts ZIP archives to MS-DOS compatible disk images (virtual floppies)
12 #
13 # Pablo (C) 2021
14 
15 zip="$1"
16 img="$2"
17 dir="$(mktemp)"
18 
19 if [ -z "$zip" ]
20 then
21   echo 'zip2img zipfile [imagefile]'
22   exit 0
23 fi
24 
25 # Generate the default filename for the output if it isn't set by the user
26 if [ -z "$img" ]
27 then
28   fname="$(echo "$zip" | sed 's/\.[^.]*$//g')"
29   fdir="$(dirname "$zip")"
30   img="$fdir/$fname.img"
31 fi
32 
33 # Extract the contents of the archive to a temporary directory
34 unzip "$zip" -d "$dir/"
35 
36 # Create the disk image and copy the contents of the archive to it
37 dd if=/dev/zero of="$img" count=1440 bs=1k
38 /sbin/mkfs.msdos "$img"
39 mcopy -i "$img" "$dir/"* ::/
40 
41 # Delete the temporary directory
42 rm "${dir:?}" -rf
43