Skip to content

Instantly share code, notes, and snippets.

@dannofx
Last active October 6, 2017 17:37
Show Gist options
  • Save dannofx/fc1e059b04ba809e5840b20da6f05211 to your computer and use it in GitHub Desktop.
Save dannofx/fc1e059b04ba809e5840b20da6f05211 to your computer and use it in GitHub Desktop.
Join several cbr or cbz files within in one single big cbz file, the order of the files in the final file will be determined alphabetically.
#!/bin/bash
if [ -z "$1" ]
then
echo "Specify the name of the file to create and the directory with the cbr files."
echo "./joincbr.sh YOUR_COMIC_FILE SOURCE_DIRECTORY"
exit 0
fi
TARGET_NAME=$1
SOURCE_DIRECTORY=$2
export count=0
find -E "$SOURCE_DIRECTORY" -regex '.*\.(cbr|cbz)' -type f -print0 | sort -z |while IFS= read -r -d '' file; do
extension=${file/*./}
dest=$(printf %06d $count)/
if [ "$extension" == "cbr" ]; then
unrar x "$file" "$dest"
else
unzip -a "$file" -d "$dest"
fi
((count++))
zip -ur "$TARGET_NAME.cbz" "$dest"
rm -fr "$dest"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment