Skip to content

Instantly share code, notes, and snippets.

@gaborbata
Last active March 5, 2020 12:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gaborbata/d0263b6f5ea20dab34219e1e60f225bc to your computer and use it in GitHub Desktop.
Save gaborbata/d0263b6f5ea20dab34219e1e60f225bc to your computer and use it in GitHub Desktop.
Convert cbr to cbz
#!/bin/bash
exit_with_error() {
if [ -n "$1" ]; then
echo "ERROR: $1"
else
echo "ERROR: could not convert file"
fi
exit 1
}
for FILE in *{.cbr,.CBR}
do
[ -e "$FILE" ] || continue
echo "Converting '$FILE' to cbz format."
DIR="${FILE%.*}"
mkdir "$DIR"
[ $? -eq 0 ] || exit_with_error "Could not create directory: $DIR"
unrar x -inul ./"$FILE" "$DIR"
[ $? -eq 0 ] || exit_with_error "Could not unrar file: $FILE"
cd "$DIR"
[ $? -eq 0 ] || exit_with_error "Could not change directory: $DIR"
zip -0 -q -r "../$DIR.cbz" .
[ $? -eq 0 ] || exit_with_error "Could not zip file: $DIR.cbz"
cd ..
[ $? -eq 0 ] || exit_with_error "Could not change directory: $DIR/.."
rm -r "$DIR"
[ $? -eq 0 ] || exit_with_error "Could not delete directory: $DIR"
#Uncomment the following lines if you do not want to keep original cbr files
#rm "$FILE"
#[ $? -eq 0 ] || exit_with_error "Could not delete file: $FILE"
echo "Conversion of '$FILE' was successful!"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment