Skip to content

Instantly share code, notes, and snippets.

@mofosyne
Last active March 10, 2025 20:39
Show Gist options
  • Save mofosyne/fcffaf4c25b0676857dd450f7580907b to your computer and use it in GitHub Desktop.
Save mofosyne/fcffaf4c25b0676857dd450f7580907b to your computer and use it in GitHub Desktop.
hybrid ISO image with dvdisaster enhancement script (WIP Untested) (Suggestion Welcomed)
#!/bin/bash
#
# This script creates a hybrid ISO image (UDF + ISO9660/Rock Ridge/Joliet)
# using genisoimage. Although the UDF part is included, the volume label is
# subject to the ISO9660 limit (32 characters).
#
# Usage: ./create_iso.sh <source_folder> [<destination_iso_image>]
# Check for required dependencies
for cmd in genisoimage dvdisaster; do
if ! command -v "$cmd" &> /dev/null; then
echo "Error: $cmd is not installed. Please install it."
exit 1
fi
done
# Check for at least one argument
if [ "$#" -lt 1 ]; then
echo "Got $# args"
echo "Usage: $0 <source_folder> [<destination_iso_image>]"
exit 1
fi
# Get Source Folder
SOURCE_FOLDER="$1"
# Derive default folder name from source folder
DEFAULT_FOLDER_NAME=${SOURCE_FOLDER%/}
DEFAULT_FOLDER_NAME=${DEFAULT_FOLDER_NAME##*/}
# Generate a default disc title from the folder name
# Expects Example: 2024-12-16_Projects_2000_-_2024
DEST_LABEL=${DEFAULT_FOLDER_NAME#*-*-*_}
DEST_LABEL=$(echo "$DEST_LABEL" | sed 's/[^_]\+/\L\u&/g' | sed 's/_/ /g')
DEST_DATE=${DEFAULT_FOLDER_NAME%%_*}
echo "SOURCE_FOLDER = $SOURCE_FOLDER"
echo "DEFAULT_FOLDER_NAME = $DEFAULT_FOLDER_NAME"
echo "DEST_LABEL = $DEST_LABEL"
echo "DEST_DATE = $DEST_DATE"
# Limit the volume label to 32 characters (ISO9660 limit)
MAX_VOLID_LEN=32
if [ ${#DEST_LABEL} -gt $MAX_VOLID_LEN ]; then
echo "Volume label is longer than $MAX_VOLID_LEN characters; '$DEST_LABEL'. exiting..."
exit 1
fi
echo "Using volume label = $DEST_LABEL"
# Get destination image filename; default extension is .iso
DEST_IMAGE=${2:-${DEFAULT_FOLDER_NAME}.iso}
echo "DEST_IMAGE = $DEST_IMAGE"
# Create the ISO image using genisoimage.
# -udf enables UDF support, -R adds Rock Ridge (for Unix), and -J adds Joliet (for Windows).
echo "Creating hybrid ISO image..."
genisoimage -udf -R -J -joliet-long -allow-lowercase -allow-multidot -V "$DEST_LABEL" -o "$DEST_IMAGE" "$SOURCE_FOLDER"
if [ $? -ne 0 ]; then
echo "Error: Failed to create ISO image with genisoimage."
exit 1
fi
echo "ISO image created at $DEST_IMAGE"
# Optional: Enhance the image with error correction using dvdisaster
echo "Enhancing image with error correction using dvdisaster..."
dvdisaster -i "$DEST_IMAGE" -mRS02 -n 15% -o image
if [ $? -ne 0 ]; then
echo "Warning: Failed to add error correction."
else
echo "Protected ISO image created successfully."
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment