Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre

Notices

Reply
 
Thread Tools Search this Thread
Old 11-08-2012, 04:49 AM   #1
faraz
Junior Member
faraz began at the beginning.
 
Posts: 6
Karma: 10
Join Date: Oct 2012
Location: Right behind you...
Device: Nook
Talking Calibre Install/Update Script for OS X

Note: The script below is old and remains here for history's sake. You can find the latest version in the Related Tools section.

-----

I got fairly annoyed with having to download calibre manually every time there was an update. Here's a bash script I wrote that handles updates for OS X.

You can run the script from the terminal with `bash calibre-installer.sh` or change the file extension to `.command` and double click the file.

`calibre-install.sh`:
Code:
#! /bin/bash
#
# Install the latest version of calibre for OS X
# Replaces any existing version in /Applications or ~/Applications
#
# Copyright (C) 2012 Faraz Yashar
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of  MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# this program.  If not, see <http://www.gnu.org/licenses/>.

# Note: `set -e` is not included in order to provide custom error failures for
# failed cURL requests; with `set -e`, cURL the script will exit if returns `1`
# with a failed download

#
# Utility functions
#

# Exit with an optional [error message] and [exit status]
error_exit() {
  echo "Calibre install error: ${1:-"Unknown Error"}
You can manually download and install calibre from http://calibre-ebook.com/download_osx" 1>&2; exit "${2:-1}"
}

# GET a <URL> and write the output to <output file>; throw an error if the request fails
download_or_exit(){
  response_code=`curl --write-out %{http_code} --silent --output $2 $1`
  [ "$response_code" != "200" ] && error_exit "Failed HTTP request!
Server responded with a $response_code error when requesting \"$1\"
See $2 for the full output of the request"
}

#
# Main script
#

[ `uname` != 'Darwin' ] && error_exit "This installation script is incompatible with `uname` operating systems."

calibre_running=`pidof calibre`
if [ $calibre_running ]; then
  echo "Quitting calibre..."
  osascript -e "tell application \"calibre\" to quit" || error_exit "Calibre failed to quit!"
fi

release_url='http://code.google.com/feeds/p/calibre-ebook/downloads/basic'
echo "Downloading the calibre release feed from $release_url..."
download_or_exit $release_url /tmp/calibre-feed

calibre_download_url=`cat /tmp/calibre-feed | grep -o "http://calibre-ebook\.googlecode\.com/files/calibre.*\.dmg"`
# Raise an error if no download URL is found
if [ -z $calibre_download_url ]; then
  page_title=`cat /tmp/calibre-feed | grep "<title>.*</title>" | sed s/'<\/*title>'//g`
  error_exit "No download URL found at $release_url. Instead found page: $page_title
See /tmp/calibre-feed for the full contents of $release_url."
fi

echo "Downloading calibre image from $calibre_download_url..."
dmg=`basename $calibre_download_url` # The image filename (e.g. 'calibre-x.x.x.dmg')
download_or_exit $calibre_download_url /tmp/$dmg

mount_point="/Volumes/`basename $dmg .dmg`"
echo "Mounting /tmp/$dmg to $mount_point..."
hdiutil attach /tmp/$dmg
[ -e $mount_point/calibre.app ] || error_exit '"calibre.app" could not be found in the downloaded .dmg'

local_calibre="$HOME/Applications/calibre.app"
backup_dir="/tmp/calibre-`date +%s`.app.bak"

if [ -e local_calibre ]; then
  echo "Moving current calibre installation in ~/Applications to $backup_dir..."
  mv local_calibre backup_dir
elif [ -e /Applications/calibre.app ]; then
  echo "Moving current calibre installation in /Applications to $backup_dir..."
  mv /Applications/calibre.app backup_dir
fi

cp -R $mount_point/calibre.app /Applications/calibre.app
hdiutil detach `hdiutil info | grep $mount_point | grep -o "/dev/disk\d*s\d*"`

echo "Done! Launching calibre!"
osascript -e "tell application \"calibre\" to activate" || error_exit "Calibre failed to open!"

Last edited by faraz; 06-26-2013 at 03:57 PM. Reason: Update
faraz is offline   Reply With Quote
Old 11-11-2012, 12:14 PM   #2
manxam
Enthusiast
manxam can extract oil from cheesemanxam can extract oil from cheesemanxam can extract oil from cheesemanxam can extract oil from cheesemanxam can extract oil from cheesemanxam can extract oil from cheesemanxam can extract oil from cheesemanxam can extract oil from cheesemanxam can extract oil from cheese
 
Posts: 26
Karma: 1234
Join Date: Aug 2012
Device: Aura HD, Aura One (2nd warranty)
Neat little script and works perfectly. Modified it a little bit to delete the old copy instead of backing it up as I really saw no need for that feature on my end.

Think with a little bit of applescript one could:
Start Calibre
Wait for the new updates window.
-> if shown then download and install
-> if not shown then
-> do nothing
?

Thanks for sharing!
manxam is offline   Reply With Quote
Advert
Old 11-11-2012, 12:16 PM   #3
manxam
Enthusiast
manxam can extract oil from cheesemanxam can extract oil from cheesemanxam can extract oil from cheesemanxam can extract oil from cheesemanxam can extract oil from cheesemanxam can extract oil from cheesemanxam can extract oil from cheesemanxam can extract oil from cheesemanxam can extract oil from cheese
 
Posts: 26
Karma: 1234
Join Date: Aug 2012
Device: Aura HD, Aura One (2nd warranty)
Oh, as a note. 'pidof' is not installed by default on Darwin and I had to install via brew. Just a heads-up!
manxam is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Script to update to latest version squigish Calibre 11 09-29-2013 10:37 PM
Unable to update Calibre as original install file is missing? El_Splendido Calibre 1 08-24-2012 04:43 PM
Update script does not work rusHack Kindle Developer's Corner 9 06-21-2012 08:55 PM
install script iomari Calibre 4 09-25-2011 07:58 AM
calibre update 0.8.1 to 0.8.2 custom install directory Dopedangel Calibre 5 05-21-2011 01:15 PM


All times are GMT -4. The time now is 07:36 AM.


MobileRead.com is a privately owned, operated and funded community.