Skip to content

Instantly share code, notes, and snippets.

@stripedpurple
Created April 18, 2019 02:49
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 stripedpurple/5b5e311d2ec7a8dc8f1ef574d0942dbf to your computer and use it in GitHub Desktop.
Save stripedpurple/5b5e311d2ec7a8dc8f1ef574d0942dbf to your computer and use it in GitHub Desktop.
Converts CBRs (Comic Book Archives) to PDFs
#!/bin/bash
[[ $(which unrar) != /* ]] && {
echo Please install unrar
exit 1
}
[[ $(which convert) != /* ]] && {
echo Please install imagemagick
exit 1
}
mkdir tmp
for f in "$@"; do
mv "$f" tmp
cd tmp
unrar e -x . > /dev/null 2>../error.log
[[ $? -eq 0 ]] && {
convert *.jpg "${f%.*}.pdf" > /dev/null 2>../error.log
[[ $? -eq 0 ]] && {
rm -rf *.jpg
mv "${f%.*}.pdf" ..
echo "Successfully created ${f%.*}.pdf"
} || {
echo "Error: An error occurred while trying to create ${f%.*}.pdf"
}
} || {
mv "$f" ..
echo "Error: An error occurred while extracting the archive for $f"
}
rm -rf "$f"
cd ..
done
rm -rf tmp
[ ! -s error.log ] && rm error.log
echo DONE!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment