Last active
May 16, 2017 12:04
-
-
Save konfou/632d03052b654d83f2b5eefb996e9fb0 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
#!/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