Fixes and changes to calibre-portable.sh

Fixes #1426222 [Updated version of calibre-portable.sh](https://bugs.launchpad.net/calibre/+bug/1426222)
This commit is contained in:
Eli Schwartz 2015-02-15 18:36:27 -06:00 committed by Kovid Goyal
parent 00b21d8d71
commit 973e0e9d6f

View File

@ -1,6 +1,6 @@
#!/bin/sh
# Calibre-Portable.sh
# ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
#!/bin/bash
# Calibre-Portable.sh
# ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
#
# Shell script File to start a Calibre configuration on Linux
# giving explicit control of the location of:
@ -18,155 +18,167 @@
#
# If trying to run off a USB stick then the folder structure
# shown below is recommended (relative to the location of
# this script file). This can structure can also be used
# when running of a local hard disk if you want to get the
# level of control this script file provides.
# - Calibre Location of linux program files
# - CalibreConfig Location of Configuration files
# - CalibreLibrary Location of Books and metadata
# - CalibreSource Location of Calibre Source files (Optional)
# this script file). This structure can also be used when
# running of a local hard disk if you want to get the level
# of control this script file provides.
# - Calibre Location of linux program files
# - CalibreConfig Location of Configuration files
# - CalibreLibrary Location of Books and metadata
# - CalibreSource Location of Calibre Source files (Optional)
#
# This script file is designed so that if you create the recommended
# folder structure then it can be used 'as is' without modification.
# To use your own structure, simply set the variables at the head of each block.
#
# More information on the Environment Variables used by Calibre can
# be found at:
# http://manual.calibre-ebook.com/customize.html#environment-variables
#
# The documentation for this file in the Calibre manual can be found at:
# http://manual.calibre-ebook.com/portable.html
# http://manual.calibre-ebook.com/customize.html#environment-variables
#
# NOTE: It is quite possible to have both Windows and Linux binaries on the same
# USB stick but set up to use the same calibre settings otherwise.
# In this case you use:
# - calibre-portable.bat to run the Windows version
# = calibre-portable.sh to run the Linux version
# USB stick but set up to use the same calibre settings otherwise.
# In this case you use:
# - calibre-portable.bat to run the Windows version
# - calibre-portable.sh to run the Linux version
#
# CHANGE HISTORY
# ¬¬¬¬¬¬¬¬¬¬¬¬¬¬
# 22 Jan 2012 itimpi - First version based on the calibre-portable.bat file for Windows
# It should have identical functionality but for a linux environment.
# It might work on MacOS but that has not been validated
# 22 Jan 2012 itimpi ----- First version based on the calibre-portable.bat file for Windows
# It should have identical functionality but for a linux environment.
# It might work on MacOS but that has not been validated.
#
# 02 Feb 2015 eschwartz -- Fix path issues, allow setting each location in one variable, allow
# specifying a list of libraries in descending order of priority.
# -------------------------------------
# ------------------------------------------------
# Set up Calibre Config folder
#
# This is where user specific settings
# are stored.
# -------------------------------------
# This is where user specific settings are stored.
# ------------------------------------------------
if [ -d CalibreConfig ]
then
CALIBRE_CONFIG_DIRECTORY=`pwd`/CalibreConfig
echo "CONFIG FILES: "`pwd`"/CalibreConfig"
export CALIBRE_CONFIG_DIRECTORY
CONFIG_DIR="$(pwd)/CalibreConfig"
if [[ -d "${CONFIG_DIR}" ]]; then
export CALIBRE_CONFIG_DIRECTORY="${CONFIG_DIR}"
echo "CONFIG FILES: ${CONFIG_DIR}"
else
echo -e "\033[0;31mCONFIG FILES: Not found\033[0m"
fi
echo "--------------------------------------------------"
# --------------------------------------------------------------
# Specify Location of ebooks
#
# Location where Book files are located
# Location where Book files are located.
# Either set explicit path, or if running from a USB stick
# a relative path can be used to avoid need to know the
# drive letter of the USB stick.
#
# Comment out any of the following that are not to be used
# (although leaving them in does not really matter)
# Specify a list of libraries here, by adding new elements to the
# array. The first value of LIBRARY_DIRS that is an existing directory
# will be used as the current calibre library.
# --------------------------------------------------------------
if [ -d /eBooks/CalibreLibrary ]
then
SET CALIBRE_LIBRARY_DIRECTORY=/eBOOKS/CalibreLibrary
echo "LIBRARY FILES: /eBOOKS/CalibreLibrary"
export LIBRARY_FILES
fi
if [ -d `pwd`/CalibreLibrary ]
then
CALIBRE_LIBRARY_DIRECTORY=`pwd`/CalibreLibrary
echo "LIBRARY FILES: "`pwd`"/CalibreLibrary"
export LIBRARY_FILES
fi
LIBRARY_DIRS[0]="/path/to/first/CalibreLibrary"
LIBRARY_DIRS[1]="/path/to/second/CalibreLibrary"
LIBRARY_DIRS[2]="$(pwd)/CalibreLibrary"
for LIBRARY_DIR in "${LIBRARY_DIRS[@]}"; do
if [[ -d "${LIBRARY_DIR}" ]]; then
export CALIBRE_LIBRARY_DIRECTORY="${LIBRARY_DIR}"
echo "LIBRARY FILES: ${CALIBRE_LIBRARY_DIRECTORY}"
break
fi
done
[[ -z "${CALIBRE_LIBRARY_DIRECTORY}" ]] && echo -e "\033[0;31mLIBRARY FILES: Not found\033[0m"
echo "--------------------------------------------------"
# --------------------------------------------------------------
# Specify Location of metadata database (optional)
#
# Location where the metadata.db file is located. If not set
# then the same location as Books files will be assumed. This.
# options is typically used to get better performance when the
# Library is on a (slow) network drive. Putting the metadata.db
# Location where the metadata.db file is located. If not set
# then the same location as Book files will be assumed. This
# option is typically used to get better performance when the
# Library is on a (slow) network drive. Putting the metadata.db
# file locally then makes gives a big performance improvement.
#
# NOTE. If you use this option, then the ability to switch
# libraries within Calibre will be disabled. Therefore
# you do not want to set it if the metadata.db file
# is at the same location as the book files.
# NOTE. If you use this option, then the ability to switch
# libraries within Calibre will be disabled. Therefore
# you do not want to set it if the metadata.db file
# is at the same location as the book files.
#
# Another point to watch is that plugins can cause problems
# as they often store absolute path information
# Another point to watch is that plugins can cause problems
# as they often store absolute path information.
# --------------------------------------------------------------
if [ -d `pwd`/CalibreMetadata/metadata.db ]
then
if [ $CALIBRE_LIBRARY_DIRECTORY != `pwd`/CalibreMetadata ]
then
CALIBRE_OVERRIDE_DATABASE_PATH=`pwd`/CalibreMetadata/metadata.db
echo DATABASE: `pwd`"/CalibreMetadata/metadata.db"
export CALIBRE_OVERRIDE_DATABASE
echo
echo "***CAUTION*** Library Switching will be disabled"
echo
fi
METADATA_DIR="$(pwd)/CalibreMetadata"
if [[ -f "${METADATA_DIR}/metadata.db" && "$CALIBRE_LIBRARY_DIRECTORY" != "${METADATA_DIR}" ]]; then
export CALIBRE_OVERRIDE_DATABASE_PATH="${METADATA_DIR}/metadata.db"
echo "DATABASE: ${METADATA_DIR}/metadata.db"
echo
echo -e "\033[0;31m***CAUTION*** Library Switching will be disabled\033[0m"
echo
echo "--------------------------------------------------"
fi
# --------------------------------------------------------------
# Specify Location of source (optional)
#
# It is easy to run Calibre from source
# Just set the environment variable to where the source is located
# When running from source the GUI will have a '*' after the version.
# It is easy to run Calibre from source.
# Just set the environment variable to where the source is located.
# When running from source the GUI will have a '*' after the version
# number that is displayed at the bottom of the Calibre main screen.
#
# More information on setting up a development environment can
# be found at:
# http://manual.calibre-ebook.com/develop.html#develop
# http://manual.calibre-ebook.com/develop.html#develop
# --------------------------------------------------------------
if [ -d CalibreSource/src ]
then
CALIBRE_DEVELOP_FROM=`pwd`/CalibreSource/src
echo "SOURCE FILES: "`pwd`"/CalibreSource/src"
export CALIBRE_DEVELOP_FROM
SRC_DIR="$(pwd)/CalibreSource/src"
if [[ -d "${SRC_DIR}" ]]; then
export CALIBRE_DEVELOP_FROM="${SRC_DIR}"
echo "SOURCE FILES: ${SRC_DIR}"
else
echo "SOURCE FILES: *** Not being Used ***"
echo "SOURCE FILES: *** Not being Used ***"
fi
echo "--------------------------------------------------"
# --------------------------------------------------------------
# Specify Location of calibre linux binaries (optional)
#
# To avoid needing Calibre to be set in the search path, ensure
# that Calibre Program Files is current directory when starting.
# The following test falls back to using search path.
# that if Calibre Program Files exists, we manually specify the
# location of the binary.
# The following test falls back to using the search path, or you
# can specifically use the search path by leaving the BIN_DIR blank.
#
# This folder can be populated by copying the /opt/calibre folder
# from an existing installation or by installing direct to here.
#
# NOTE. Do not try and put both Windows and Linux binaries into
# same folder as this can cause problems.
# NOTE. Do not try and put both Windows and Linux binaries into
# the same folder as this can cause problems.
# --------------------------------------------------------------
if [ -d `pwd`/Calibre ]
then
cd `pwd`/Calibre
echo "PROGRAM FILES: "`pwd`
else
echo "PROGRAM FILES: *** Using System search path ***"
fi
BIN_DIR="$(pwd)/calibre"
if [[ -d "${BIN_DIR}" ]]; then
CALIBRE="${BIN_DIR}/calibre"
echo "PROGRAM FILES: ${BIN_DIR}"
elif [[ -z "${BIN_DIR}" ]]; then
CALIBRE="calibre"
echo "PROGRAM FILES: Using System search path"
else
CALIBRE="calibre"
echo "PROGRAM FILES: No portable copy found."
echo "To intall a portable copy, run the following command:"
echo "wget -nv -O- https://raw.githubusercontent.com/kovidgoyal/calibre/master/setup/linux-installer.py" \
"| python -c \"import sys; main=lambda x,y:sys.stderr.write('Download failed\n'); exec(sys.stdin.read()); main('$(pwd)/calibre', True)\""
echo -e "\033[0;31m*** Using System search path instead***\033[0m"
fi
echo "--------------------------------------------------"
# --------------------------------------------------------------
# Location of Calibre Temporary files (optional)
@ -174,19 +186,18 @@ fi
# Calibre creates a lot of temporary files while running
# In theory these are removed when Calibre finishes, but
# in practise files can be left behind (particularly if
# a crash occurs). Using this option allows some
# a crash occurs). Using this option allows some
# explicit clean-up of these files.
# If not set Calibre uses the normal system TEMP location
# --------------------------------------------------------------
CALIBRE_TEMP_DIR=/tmp/CALIBRE_TEMP
echo "TEMPORARY FILES: $CALIBRE_TEMP_DIR"
CALIBRE_TEMP_DIR="/tmp/CALIBRE_TEMP"
echo "TEMPORARY FILES: ${CALIBRE_TEMP_DIR}"
echo "--------------------------------------------------"
rm -rf "${CALIBRE_TEMP_DIR}"
mkdir "${CALIBRE_TEMP_DIR}"
if [ -d "$CALIBRE_TEMP_DIR" ]
then
rm -fr "$CALIBRE_TEMP_DIR"
fi
mkdir "$CALIBRE_TEMP_DIR"
# set the following for any components that do
# not obey the CALIBRE_TEMP_DIR setting
@ -194,16 +205,17 @@ mkdir "$CALIBRE_TEMP_DIR"
# --------------------------------------------------------------
# Set the Interface language (optional)
#
# If not set Calibre uses the language set in Preferences
# Remove the if test to use this. ;)
# --------------------------------------------------------------
CALIBRE_OVERRIDE_LANG=EN
echo "INTERFACE LANGUAGE: $CALIBRE_OVERRIDE_LANG"
export CALIBRE_OVERRIDE_LANG
if false; then
export CALIBRE_OVERRIDE_LANG="EN"
echo "INTERFACE LANGUAGE: ${CALIBRE_OVERRIDE_LANG}"
fi
# ----------------------------------------------------------
# The following gives a chance to check the settings before
# starting Calibre. It can be commented out if not wanted.
# starting Calibre. It can be commented out if not wanted.
# ----------------------------------------------------------
echo
@ -215,6 +227,5 @@ read DUMMY
# Start up the calibre program.
# --------------------------------------------------------
echo "Starting up Calibre"
echo `pwd`
calibre --with-library "$CALIBRE_LIBRARY_DIRECTORY"
echo "Starting up Calibre from portable directory \"$(pwd)\""
$CALIBRE --with-library "$CALIBRE_LIBRARY_DIRECTORY"