Created
October 13, 2010 23:14
-
-
Save lgrz/625156 to your computer and use it in GitHub Desktop.
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 | |
# | |
# epub build script | |
# run from within the root folder of your epub | |
this=$(basename $0) | |
# Help | |
if [ "$1" == "-h" ]; then | |
shift; | |
echo "usage: $this [-d]" | |
exit 1 | |
fi | |
if [ ! -d "OEBPS" ]; then | |
echo "OEBPS folder does not exist" | |
exit 2 | |
fi | |
# Build development version | |
if [ "$1" == "-d" ]; then | |
shift; | |
ruby version.rb | |
echo "building devlopment version..." | |
fi | |
# Note the tab and space in sed's match | |
filename=$(grep '<dc:title>' OEBPS/content.opf | sed 's/^[ ]*<dc:title>\(.*\)<\/dc:title>/\1/') | |
echo "title: $filename" | |
if [ -f "$filename.epub" ]; then | |
echo "removing old file: $filename.epub" | |
rm -fr "$filename.epub" | |
fi | |
zip -0Xq "$filename.epub" mimetype | |
zip -Xr9Dq "$filename.epub" META-INF OEBPS | |
# Run epubcheck if available | |
which epubcheck > /dev/null | |
if [ $? -eq 0 ]; then | |
epubcheck "$filename.epub" | |
else | |
echo "epubcheck not available skipping..." | |
fi |
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 | |
# Put this file in a place where it will | |
# be included in your environment path | |
# eg. /usr/local/bin | |
this=$(basename $0) | |
if [ $# -ne 1 ]; then | |
echo "usage: $this file" | |
exit 1 | |
fi | |
# Update the path below to your copy of epubcheck | |
java -jar "$HOME/Downloads/epubcheck-1.0.5/epubcheck-1.0.5.jar" "`pwd`/$1" |
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 ruby | |
# -*- coding: utf-8 -*- | |
# Update version in the title tag of content.opf | |
# So you don't have to remember to change the title | |
# every time you want to test something in ibooks | |
# You must have a version number as the last part of | |
# your book title. eg My Book 1.0. | |
# Major versions must be updated manually | |
buffer = "" | |
File.open("OEBPS/content.opf", "r") do |toc| | |
while line = toc.gets | |
if line.include? "<dc:title>" | |
m1 = /<dc:title>([a-zA-Z0-9\s]+?)((\d+)\.?(\d+)?)?<\/dc:title>/.match line | |
# No version number | |
if $2 == nil | |
puts "No version number found" | |
exit 1 | |
end | |
# No minor version | |
if $4 == nil | |
puts "No minor version found." | |
exit 1 | |
end | |
$i = Integer($4) + 1 | |
$version = String($3) + "." + String($i) | |
$title = "#{$1.chop} #{$version}" | |
line.gsub!(/(<dc:title>)(.+?)(<\/dc:title>)/, "\\1#{$title}\\3") | |
end | |
buffer << line | |
end | |
end | |
File.open("OEBPS/content.opf", "w") do |toc| | |
toc.puts buffer | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment