Skip to content

Instantly share code, notes, and snippets.

@konfou
Last active May 16, 2017 12:04
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 konfou/632d03052b654d83f2b5eefb996e9fb0 to your computer and use it in GitHub Desktop.
Save konfou/632d03052b654d83f2b5eefb996e9fb0 to your computer and use it in GitHub Desktop.
convert *.cbr to *.cbz
#!/usr/bin/env bash
#
# Convert cbr files to cbz.
# depends
type -p 7z >/dev/null || exit 3
# trap SIGINT
trap 'trap - INT; kill -s INT "$$"' INT
file() {
local base=$(basename $1 '.cbr')
7z x "$1" -o "${temp}/${base}"
7z a -tzip "${base}.cbz" "${temp}/${base}"
}
usage() {
cat <<EOF
$(basename $0) <mode> <source>
Usage:
$(basename $0) --file/-f <target> convert <target> file
$(basename $0) --dir/-d <target> convert all files in <target>
$(basename $0) --all same thing as doing --dir .
EOF
}
main() {
temp=$(mktemp -d)
case $1 in
--file|-f) file "$2" ;;
--dir|-d)
find "$2" -type f -name '*.cbr' | while read f; do
file "$f"
done ;;
--all|-a) main --dir . ;;
*) usage ;;
esac
rm -r ${temp}
}
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment