Last active
March 5, 2020 12:06
-
-
Save gaborbata/d0263b6f5ea20dab34219e1e60f225bc to your computer and use it in GitHub Desktop.
Convert cbr to cbz
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 | |
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