Last active
January 2, 2023 21:19
-
-
Save Calinou/4a7c96731aade5a06637192116280857 to your computer and use it in GitHub Desktop.
Compress ISO/CUE files to CHD on a remote filesystem accessible via SFTP/SSH
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -euo pipefail | |
IFS=$'\n\t' | |
# Compresses ISO/CUE files to CHD on a remote filesystem accessible via SFTP/SSH. | |
# Source ISO files on the remote host are not removed after conversion | |
# (you have to do this manually if desired). | |
# | |
# chdman must be installed (it's typically packaged as `mame-tools`). | |
# If it's not in your distribution repositories, build | |
# <https://github.com/CharlesThobe/chdman> from source. | |
# The SFTP host (user@host[:port]). | |
HOST="[email protected]" | |
# Path to the folder containing ISO/CUE files. Must not end with a trailing slash. | |
ISO_CUE_DIR="path/to/folder" | |
# Paths between SSH and SFTP may differ on some hosts. | |
# Set this to e.g. "/volume1/" if using a Synology NAS. | |
SSH_PATH_PREFIX="" | |
iso_cues=$(ssh $HOST "ls $SSH_PATH_PREFIX$ISO_CUE_DIR/*.{iso,cue}") | |
# Optimize each ISO/CUE individually to avoid running out of disk space or RAM. | |
for iso_cue in $iso_cues; do | |
input_iso_cue=$(basename "$iso_cue") | |
output_chd="${input_iso_cue%.*}.chd" | |
scp "$HOST:$ISO_CUE_DIR/$input_iso_cue" /tmp | |
if [[ "${input_iso_cue: -4}" == ".cue" ]]; then | |
# Transfer BIN file alongside the CUE sheet (as it contains the actual data). | |
scp "$HOST:$ISO_CUE_DIR/${input_iso_cue%.*}.bin" /tmp | |
fi | |
chdman createcd -i "/tmp/$input_iso_cue" -o "/tmp/$output_chd" | |
# ISO/CUE/BIN file is no longer needed locally after being converted to CHD. | |
rm -f "/tmp/$input_iso_cue" "/tmp/${input_iso_cue%.*}.bin" | |
scp "/tmp/$output_chd" "$HOST:$ISO_CUE_DIR" | |
# CHD file is no longer needed locally after being transferred. | |
rm -f "/tmp/$output_chd" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment