Skip to content

Instantly share code, notes, and snippets.

@Shahor
Last active August 29, 2015 14:05
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 Shahor/953b60a48a2621c8d3ff to your computer and use it in GitHub Desktop.
Save Shahor/953b60a48a2621c8d3ff to your computer and use it in GitHub Desktop.
ebook converter
#!/usr/bin/env bash
if ! type "ebook-convert" > /dev/null; then
echo "ebook-convert tool not found in your PATH. Please install it (via Calibre) and re-run this script";
exit
fi
# Pass a path as first argument
function convert {
for file in "$1"/*
do
if [ -d "$file" ]
then
convert "$file"
else
fileExtension=`echo "$file" | awk -F . '{print $NF}'`
if [ "$fileExtension" = "epub" ]
then
mobiname=`dirname "$file"`/`basename "$file" .epub`.mobi
if [ ! -f "$mobiname" ]
then
ebook-convert "$file" "$mobiname"
fi
fi
fi
done
}
cd `dirname $0`
convert .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment