User File #638314431260324188

Upload All User Files

#638314431260324188 - bash script for creating reproducible .ISO images

create_iso.sh
System: Linux
1 comment, 327 downloads
Uploaded 9/27/2023 8:25 PM by feos (see all 204)
Script for creating reproducible .ISO images from a specified path.
Path can be specified as user input after running the script, or passed as an argument from the terminal.
Resulting file will be created near the script and called TAS_CD.iso.
To make it reproducible, we force date (2001-01-01) and mode (0444) on all files.
At the end we print paths and hashes of all packaged files (MD5 and SHA-1).

WARNING: We noticed that different versions of xorriso may sort the files differently, resulting in different hashes of the final image. However actual behavior is not expected to change, things should sync regardless.
#!/bin/bash

# Script for creating reproducible .ISO images from a specified path.
# Path can be specified as user input after running the script,
# or passed as an argument from the terminal.
# Resulting file will be created near the script and called 'TAS_CD.iso'.
# To make it reproducible, we force date (2001-01-01) and mode (0444) on all files.
# At the end we print paths and hashes of all packaged files (MD5 and SHA-1).

export SOURCE_DATE_EPOCH="$(date -d20010101 -u +%s)"
output_filename=TAS_CD # also used as volume ID, so must be [A-Z_]+
file_mode=0444

folder="$1"
while [ ! -d "$folder" ]; do
	[ -z "$folder" ] || printf "'%s' not a directory?\n" "$folder"
	read -p "Enter path to dir containing source files: " folder
done
list="$(mktemp)"
(cd "$folder"; for f in *; do printf "%s\n" "$f=$PWD/$f"; done) \
	| LC_ALL=C sort >"$list"

xorriso \
	-preparer_id xorriso \
	-volume_date 'all_file_dates' "=$SOURCE_DATE_EPOCH" \
	-as mkisofs \
	-iso-level 3 \
	-volid "$output_filename" \
	-graft-points \
	-full-iso9660-filenames \
	-joliet \
	-file-mode $file_mode \
	-uid 0 \
	-gid 0 \
	-path-list "$list" \
	-output "$output_filename".iso

rm -f "$list"
cd "$folder"

echo "MD5:"
find . -type f -exec md5sum {} \;
echo
echo "SHA-1:"
find . -type f -exec sha1sum {} \;

Dimon12321
on 4/20/2025 5:25 PM
As mentioned in the Discord channel, it requires Linux or mingw, or msys2, or cygwin to make an image using this script.
Download the script! Don't copy paste it, or else you may mess with line-endings. dos2unix utility and sed -i 's/\r$//' create_iso.sh won't fix it.
If you're using Linux (Ubuntu WSL, for example), you may need to install xorriso app first:
sudo apt update
sudo apt install xorriso