Last active
December 28, 2015 05:29
-
-
Save matthew-macgregor/4e0b9c875b99443135cf to your computer and use it in GitHub Desktop.
Alternate Calibre Install.sh for Linux
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 | |
# Description | |
# ---------------------------------------------------------------------- | |
# Installs the binary of the Calibre ebook software on Linux. | |
# https://github.com/kovidgoyal/calibre | |
# | |
# Tested only on Ubuntu version 15.10. If you run this on another | |
# version of Linux, let me know the results! | |
# | |
# This script only supports downloading the 64-bit version! | |
# | |
# As you may well know, Calibre provides a python script which will | |
# install the calibre software on the Linux OS. This script has some | |
# advantages (such as checking signatures on the file) but it requires | |
# to be run as sudo. I'm not thrilled with that, because the python | |
# installer calls binaries in the Calibre bundle as post-install steps | |
# and these are non-transparent. It seems wholly unnecessary given that | |
# Calibre appears to run perfectly well when untarred into a local | |
# directory. | |
# | |
# This script downloads and unpacks the software to /usr/local and | |
# creates an open desktop launcher. Yes, installation to /usr/local also | |
# requires elevated privileges, but the only commands that this script | |
# executes are trusted system commands -- nothing from Calibre itself. | |
# This means that we can "install" and "uninstall" with privileges, but | |
# run with non-elevated privileges. Common sense tells me that this is | |
# the right way to do things. | |
# | |
# Here's a good description of how to do this the very manual way: | |
# http://gerg.ca/blog/post/2014/installing-calibre/ | |
# | |
# Usage | |
# ---------------------------------------------------------------------- | |
# sudo ./calibre-install.sh --install | |
# sudo ./calibre-install.sh --uninstall | |
# | |
# MIT License: | |
# ---------------------------------------------------------------------- | |
# Copyright (c) 2015 Matthew MacGregor | |
# | |
# Permission is hereby granted, free of charge, to any person obtaining | |
# a copy of this software and associated documentation files (the | |
# "Software"), to deal in the Software without restriction, including | |
# without limitation the rights to use, copy, modify, merge, publish, | |
# distribute, sublicense, and/or sell copies of the Software, and to | |
# permit persons to whom the Software is furnished to do so, subject to | |
# the following conditions: | |
# | |
# The above copyright notice and this permission notice shall be | |
# included in all copies or substantial portions of the Software. | |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | |
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | |
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | |
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | |
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
#Checksum and version are paired | |
VERSION=2.47.0 | |
CHECKSUM=e1b7b1b48aee98bb79d21b7949869ce01b4477dbe3e30f10fee97cc71210a9f18e251d2d991d3f59a71ce9261957c236486e1ac784c54dfbb2a1f681ef57ca90 | |
ARCH=x86_64 | |
CALIBRE_CHECKSUM_URL=https://code.calibre-ebook.com/tarball-info/$ARCH | |
CALIBRE_INSTALL_DIR=/usr/local/calibre | |
CALIBRE_BIN=/usr/local/bin/calibre | |
CALIBRE_DESKTOP_DIR=/usr/share/applications | |
CALIBRE_DESKTOP_FILE=$CALIBRE_DESKTOP_DIR/calibre-local.desktop | |
DOWNLOAD_URL=https://github.com/kovidgoyal/calibre/releases/download/v$VERSION/calibre-$VERSION-$ARCH.txz | |
CALIBRE_DIR=/tmp/calibre_$VERSION | |
echo "Calibre Install Script: Version 0.1.2" | |
remove_download() { | |
echo "Removing downloaded package" | |
if [ -e calibre-$VERSION-$ARCH.txz ]; then | |
rm calibre-$VERSION-$ARCH.txz | |
fi | |
} | |
# Make sure only root can run our script | |
if [ $(id -u) -ne 0 ]; then | |
echo "This script must be run as root." 1>&2 | |
exit 1 | |
fi | |
if [ "$1" = "--uninstall" ] | |
then | |
echo "Removing calibre" | |
echo "----------------------------------------------------------------------" | |
if [ -e $CALIBRE_INSTALL_DIR ]; then | |
echo "Removing $CALIBRE_INSTALL_DIR" | |
rm -rf $CALIBRE_INSTALL_DIR | |
fi | |
if [ -e $CALIBRE_BIN ]; then | |
echo "Removing $CALIBRE_BIN" | |
rm $CALIBRE_BIN | |
fi | |
if [ -e $CALIBRE_DESKTOP_DIR/calibre-local.desktop ]; then | |
echo "Removing $CALIBRE_DESKTOP_DIR/calibre-local.desktop" | |
rm $CALIBRE_DESKTOP_DIR/calibre-local.desktop | |
fi | |
exit 0 | |
fi | |
if [ -e $CALIBRE_INSTALL_DIR ] || | |
[ -e $CALIBRE_BIN ] || | |
[ -e $CALIBRE_DESKTOP_FILE ]; then | |
echo "It appears that calibre may already be installed!" | |
echo "Check the following:" | |
echo "$CALIBRE_INSTALL_DIR" | |
echo "$CALIBRE_BIN" | |
echo "$CALIBRE_DESKTOP_FILE" | |
echo "You may need to uninstall first: " | |
echo "sudo ./calibre-install.sh --uninstall" | |
exit 1 | |
fi | |
# if [ "$1" = "--install" ] && [ -z $(echo $2 | awk /[0-9]\.[0-9]/) ]; | |
# then | |
# echo "Must supply a version like 2.42.0" | |
# exit 1 | |
# fi | |
echo "Installs Calibre locally." | |
echo "----------------------------------------------------------------------" | |
mkdir $CALIBRE_DIR | |
if [ ! -e calibre-$VERSION-$ARCH.txz ] | |
then | |
wget $DOWNLOAD_URL | |
#wget $DOWNLOAD_URL 2>&1 | grep --line-buffered "%" | |
test_sum=$(sha512sum calibre-$VERSION-$ARCH.txz) | |
echo "Downloaded checksum:" | |
echo "$test_sum" | |
echo "Original: $CHECKSUM" | |
if [ ! "$(echo $test_sum | grep $CHECKSUM)" = "$CHECKSUM" ]; then | |
echo "Checksum matched." | |
if [ $? -ne 0 ]; | |
then | |
echo "Download failed." | |
remove_download | |
exit 1 | |
fi | |
else | |
echo "Checksum for the downloaded file don't match. Aborting..." | |
remove_download | |
exit 1 | |
fi | |
fi | |
echo "Extracting calibre to $CALIBRE_DIR..." | |
tar xJof calibre-$VERSION-$ARCH.txz -C $CALIBRE_DIR | |
echo "Moving $CALIBRE_DIR to /usr/local/calibre/" | |
mv $CALIBRE_DIR /usr/local/calibre/ | |
echo "Creating symlink $CALIBRE_BIN" | |
if [ ! -e $CALIBRE_BIN ]; then | |
ln -s /usr/local/calibre/calibre $CALIBRE_BIN | |
fi | |
echo "Creating OpenDesktop file $CALIBRE_DESKTOP_DIR/calibre-local.desktop" | |
if [ ! -e $CALIBRE_DESKTOP_DIR/calibre-local.desktop ]; then | |
cat > $CALIBRE_DESKTOP_DIR/calibre-local.desktop <<EOL | |
[Desktop Entry] | |
Name=Calibre Ebook Manager | |
Version=$VERSION | |
Comment=Manage your ebooks with style | |
Exec=$CALIBRE_BIN | |
Terminal=false | |
Type=Application | |
Icon=/usr/local/calibre/resources/images/lt.png | |
Categories=Utility;Office | |
StartupNotify=true | |
EOL | |
fi | |
echo "Creating permissions for calibre-local.desktop" | |
chmod +x $CALIBRE_DESKTOP_DIR/calibre-local.desktop | |
echo "Removing temp directory" | |
if [ -d $CALIBRE_DIR ]; then | |
rm -rf $CALIBRE_DIR | |
fi | |
remove_download |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A few things....
1.) You might write some logic around the call to tar, to check for errors, to halt and exit with a useful error message, else, we hit item number two-
2.) If the call to tar errors out, the script continues, along its merry way, and creates the symlink and desktop file, anyhow, as well as copies the empty calibre directory to /usr/local. I found this out, as I had neglected to install xz. After installing xz, your script worked, only to throw an error, because the symlink, desktop file, and /usr/local/calibre already existed.
3.) There are references to "calibre-local.desktop" throughout the script. This should probably be assigned a variable, so, if someone wants to change the name, they need to do so in only one place. Also, does the directory for calibre-local.desktop need its own variable? The only times it's used, it's used with the file name. They should probably be stored toegether, in one variable.
4.) Likewise, there are references to the install location, /usr/local/calibre, which could also be assigned to a variable, in case anyone wants to change that.
4.) (Mayhaps a bit nit-picky) An app packaged with all of its dependiencies, such as Calibre, probably ought to go into /opt, instead of /usr/local (but, keep the symlnk in /usr/local/bin), which is intended for user/administrator-compiled programs and libraries.
5.) (CERTAINLY nit-picky) As you're linking to the binary in /usr/local/bin, wouldn't make sense to place the desktop file under /usr/local/share/applications?
Else, this runs fine on Void Linux, and the aforementioned changes, to my local copy of the script, were easy enough to make.