Skip to content

Instantly share code, notes, and snippets.

@sentient06
Created December 3, 2024 10:10
Show Gist options
  • Save sentient06/484a27b556777a35467b2e0a2c3edfe2 to your computer and use it in GitHub Desktop.
Save sentient06/484a27b556777a35467b2e0a2c3edfe2 to your computer and use it in GitHub Desktop.
Classic Macintosh Projects - Script for creating an HFS image
#!/bin/bash
if test "$#" -ne 1; then
echo "Syntax: $0 [input_file]"
exit 1
fi
if [ ! -f "$1" ]; then
echo "Input file not found!"
exit 1
fi
# Create R68Discs directory if it doesn't exist
mkdir -p R68Discs
# Get the filename without extension
input_file="$1"
filename=$(basename "$input_file")
filename_no_ext="${filename%.*}"
# Calculate size in KB and add 80KB
size_kb=$(du -k "$input_file" | cut -f1)
total_size=$((size_kb + 80))
# Ensure minimum size of 800KB
if [ $total_size -lt 800 ]; then
total_size=800
fi
# Create output filename with .img extension in R68Discs directory
output_file="R68Discs/${filename_no_ext}.img"
echo "Creating disk image '$output_file' with size ${total_size}KB..."
dd if=/dev/zero of="$output_file" bs=1024 count="$total_size"
hformat -l "$filename_no_ext" "$output_file"
hmount "$output_file"
hcopy "$input_file" ":$filename_no_ext"
humount "$output_file"
echo "Disk image created successfully in R68Discs directory!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment