Created
August 27, 2017 18:59
-
-
Save milkfarm/4af2f15433361eaf369741e57ec988bb to your computer and use it in GitHub Desktop.
Unzip epub file, then check for version number
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
#! /bin/bash | |
# ======================================================================= | |
# | |
# Unzips epub file, then checks version number | |
# | |
# To invoke, type: | |
# $ epubversion.sh filename.epub | |
# | |
# ======================================================================= | |
# Changelog | |
#---------------------------------------------------------------------- | |
# | |
# v.0.1 (2017-08-27) by milkfarm | |
# - original version | |
# Binaries and Defaults | |
# ----------------------------------------------------------------------- | |
EPUBOPEN="epubopen.sh" | |
# Functions | |
# ----------------------------------------------------------------------- | |
error () { | |
echo "! Error: $*" | |
exit 1 | |
} | |
check_command () { | |
type "$1" &> /dev/null ; | |
} | |
# Process parameters | |
#---------------------------------------------------------------------- | |
source=`basename $1` | |
target=${source%%.*} | |
# Test | |
#---------------------------------------------------------------------- | |
# Source file | |
if [ ! -f "$@" ]; then | |
error "File does not exist: $@" | |
fi | |
# Target directory | |
if [ -d "$target" ]; then | |
error "Directory already exists: $target" | |
fi | |
# Command | |
if [ ! check_command $EPUBOPEN ] ; then | |
error "Command does not exist: $EPUBOPEN" | |
fi | |
# Main | |
#---------------------------------------------------------------------- | |
$EPUBOPEN "$@" | |
result=$(grep 'version="3.0"' ${target}/OEBPS/content.opf) | |
if [ -z "$result" ] ; then | |
error "Version flag not found" | |
fi | |
echo | |
echo $result | |
version=$(echo $result | sed 's/^.* version=[\x27"]//' | sed 's/[\x27"].*$//') | |
if [ -z "$version" ] ; then | |
error "Version definition not wrapped in quotes" | |
fi | |
echo | |
echo "=> Epub version: ${version}" | |
# Cleanup | |
rm -rf ${target} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment