├── README.md ├── linux ├── calibre-installer.sh ├── calibre-upgrade.service ├── calibre-upgrade.sh └── calibre-upgrade.timer ├── osx ├── calibre-installer.sh ├── calibre-upgrade.sh └── com.calibre.updater.plist └── windows └── notes.txt /README.md: -------------------------------------------------------------------------------- 1 | # Fully Automatic Calibre installer/updater 2 | 3 | Growing out of this discussion: [Official Calibre PPA?](http://www.mobileread.com/forums/showthread.php?t=226228), here are some simple scripts to update calibre on different platforms. 4 | 5 | Note: This can also perform the first-time install, since the version check returns the same failure for out-of-date as it does if there is no calibre installed. 6 | 7 | Thanks to [aleyx](http://www.mobileread.com/forums/member.php?u=81327) for working out the version checking! ![2thumbsup](http://s.mobileread.com/i/smiliesadd1/2thumbsup.gif) 8 | 9 | To install the script on linux, run the following command: 10 | 11 | ```bash 12 | sudo -v && wget -nv -O- https://github.com/eli-schwartz/calibre-installer/raw/master/linux/calibre-installer.sh | sudo bash - 13 | ``` 14 | 15 | To install the script on OSX, run the following command: 16 | ```bash 17 | sudo -v && wget -nv -O- https://github.com/eli-schwartz/calibre-installer/raw/master/osx/calibre-installer.sh | sudo bash - 18 | ``` 19 | -------------------------------------------------------------------------------- /linux/calibre-installer.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ## Set defaults 4 | sourcefiles="https://github.com/eli-schwartz/calibre-installer/raw/master/linux/" 5 | destdir="" 6 | installwith="wget -nv -P" 7 | 8 | # Functions 9 | 10 | do_install() 11 | { 12 | ${installwith} "${destdir}${bindir}" "${sourcefiles}/calibre-upgrade.sh" 13 | chmod 755 "${destdir}${bindir}/calibre-upgrade.sh" 14 | } 15 | 16 | add_to_cron() 17 | { 18 | echo "Installing cron job..." 19 | # Don't add a duplicate job. http://stackoverflow.com/questions/11532157/unix-removing-duplicate-lines-without-sorting 20 | (crontab -l 2>/dev/null; echo "0 6 * * 5 ${bindir}/calibre-upgrade.sh > /dev/null 2>&1") | cat -n - |sort -uk2 |sort -nk1 | cut -f2-| crontab - 21 | } 22 | 23 | add_systemd_timer() 24 | { 25 | echo "Installing systemd timer..." 26 | ${installwith} "${destdir}/usr/lib/systemd/system" "${sourcefiles}/calibre-upgrade.timer" 27 | ${installwith} "${destdir}/usr/lib/systemd/system" "${sourcefiles}/calibre-upgrade.service" 28 | if [[ -z "${destdir}" ]]; then 29 | echo "Activating systemd timer..." 30 | systemctl enable calibre-upgrade.timer 31 | systemctl start calibre-upgrade.timer 32 | fi 33 | } 34 | 35 | usage() 36 | { 37 | cat <<- _EOF_ 38 | Usage: calibre-installer.sh [OPTIONS] 39 | Installs the calibre-upgrade command and creates a cron job to regularly update calibre. 40 | 41 | OPTIONS 42 | -h, --help Shows this help message. 43 | -l, --local Use currentdir for resource files. 44 | -d, --destdir Install root (for packaging purposes). 45 | _EOF_ 46 | } 47 | 48 | # Options 49 | while [ "$1" != "" ]; do 50 | case $1 in 51 | -h|--help) 52 | usage 53 | exit 54 | ;; 55 | -l|--local) 56 | installwith="install -Dm644 -t" 57 | sourcefiles="./" 58 | ;; 59 | -d|--destdir) 60 | shift 61 | destdir="${1}" 62 | ;; 63 | *) 64 | echo "calibre-installer.sh: unrecognized option '$1'" 65 | echo "Try 'calibre-installer.sh --help' for more information." 66 | exit 1 67 | ;; 68 | esac 69 | shift 70 | done 71 | 72 | # Main 73 | 74 | # Apparently Fedora demands you stick the script in /usr/local/sbin 75 | bindir="/usr/bin" 76 | if [[ -f /etc/redhat-release ]]; then 77 | bindir="/usr/local/sbin" 78 | fi 79 | 80 | ## Check that we are running as root 81 | if [[ ${EUID} -ne 0 ]]; then 82 | echo -e "You can only install calibre if you have root permission." 83 | exit 1 84 | fi 85 | 86 | do_install 87 | 88 | if [[ -d /usr/lib/systemd ]]; then 89 | add_systemd_timer 90 | elif (command -v crontab > /dev/null 2>&1);then 91 | echo "Systemd not found, falling back on cron for scheduling." 92 | add_to_cron 93 | else 94 | echo "Failed to install a systemd timer or cron job -- system does not have systemd or cron installed." 95 | fi 96 | -------------------------------------------------------------------------------- /linux/calibre-upgrade.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Upgrade calibre 3 | Requires=network-online.target 4 | After=network-online.target 5 | 6 | [Service] 7 | Type=oneshot 8 | ExecStart=/usr/bin/calibre-upgrade.sh 9 | StandardOutput=journal 10 | StandardError=journal 11 | -------------------------------------------------------------------------------- /linux/calibre-upgrade.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Unset git development source 4 | export CALIBRE_DEVELOP_FROM= 5 | # by default, switch is off 6 | force_upgrade=0 7 | 8 | 9 | # Functions 10 | 11 | calibre_is_installed() 12 | { 13 | command -v calibre >/dev/null 2>&1 14 | } 15 | 16 | usage() 17 | { 18 | cat <<- _EOF_ 19 | Usage: calibre-upgrade.sh [OPTIONS] 20 | Upgrades calibre installation. Automatically checks if the current version is up to date. 21 | Must be run as root. 22 | 23 | OPTIONS 24 | -f, --force Force an update. This is only useful if binaries 25 | were updated for a critical error. :shrug: 26 | -p, --prefix Root of installation. calibre is installed by default to /opt 27 | -h, --help Displays this help message. 28 | _EOF_ 29 | } 30 | 31 | do_upgrade() 32 | { 33 | if calibre_is_installed; then 34 | # shutdown calibre as each logged-in user. 35 | for i in $(users | tr ' ' '\n' | sort -u); do 36 | sudo -u ${i} calibre --shutdown-running-calibre 37 | done 38 | killall -q -v calibre-server && echo -e "Restart when upgrade is finished. ;)\n\n" || echo -e "No running calibre servers.\n\n" 39 | fi 40 | wget -nv -O- https://github.com/kovidgoyal/calibre/raw/master/setup/linux-installer.py | python -c "import sys; main=lambda x:sys.stderr.write('Download failed\n'); exec(sys.stdin.read()); main('${prefix}')" 41 | } 42 | 43 | # Options 44 | while [ "$1" != "" ]; do 45 | case $1 in 46 | -h|--help) 47 | usage 48 | exit 49 | ;; 50 | -f|--force) 51 | force_upgrade=1 52 | ;; 53 | -p|--prefix) 54 | shift 55 | prefix="${1}" 56 | ;; 57 | *) 58 | echo "calibre-upgrade.sh: unrecognized option '$1'" 59 | echo "Try 'calibre-upgrade.sh --help' for more information." 60 | exit 1 61 | esac 62 | shift 63 | done 64 | 65 | # Main 66 | 67 | ## Check that we are running as root 68 | if [[ ${EUID} -ne 0 ]]; then 69 | echo -e "You can only install calibre if you have root permission." 70 | exit 1 71 | fi 72 | 73 | 74 | 75 | if calibre_is_installed; then 76 | calibre-debug -c "from calibre.gui2.update import get_newest_version; from calibre.constants import numeric_version; raise SystemExit(int(numeric_version < get_newest_version()))" 77 | UP_TO_DATE=$? 78 | else 79 | echo -e "Calibre is not installed, installing...\n\n" 80 | UP_TO_DATE=1 81 | fi 82 | 83 | if [ "${UP_TO_DATE}" = 0 ]; then 84 | echo "Calibre is up-to-date" 85 | 86 | if [ "${force_upgrade}" = 1 ]; then 87 | echo "" 88 | echo "Forcing upgrade anyway -- are you sure you want to continue? [y/n]" 89 | read answer 90 | 91 | if [[ "${answer}" = "y" || "${answer}" = "yes" ]]; then 92 | do_upgrade 93 | else 94 | echo "Exiting..." 95 | exit 1 96 | fi 97 | fi 98 | else 99 | calibre_is_installed && echo -e "Calibre is out-of-date. Upgrading...\n\n" 100 | do_upgrade 101 | fi 102 | -------------------------------------------------------------------------------- /linux/calibre-upgrade.timer: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Timer to upgrade calibre 3 | 4 | [Timer] 5 | OnCalendar=Fri 06:00 6 | Persistent=True 7 | 8 | [Install] 9 | WantedBy=multi-user.target 10 | -------------------------------------------------------------------------------- /osx/calibre-installer.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Set the location of calibre-upgrade and launchd plist. 4 | upgrade_script=https://github.com/eli-schwartz/calibre-installer/raw/master/osx/calibre-upgrade.sh 5 | launchd_plist=https://github.com/eli-schwartz/calibre-installer/raw/master/osx/com.calibre.updater.plist 6 | 7 | # Functions 8 | 9 | do_install() 10 | { 11 | wget -nv -O /usr/local/bin/calibre-upgrade.sh $upgrade_script 12 | chmod 755 /usr/local/bin/calibre-upgrade.sh 13 | } 14 | 15 | add_launchd() 16 | { 17 | echo "Installing launchd global daemon..." 18 | wget -nv -O /Library/LaunchDaemons/com.calibre.updater.plist $launchd_plist 19 | chmod 644 /Library/LaunchDaemons/com.calibre.updater.plist 20 | } 21 | 22 | usage() 23 | { 24 | cat <<- _EOF_ 25 | Usage: calibre-installer.sh [OPTIONS] 26 | Installs the calibre-upgrade command and creates a Launchd daemon to regularly update calibre. 27 | 28 | OPTIONS 29 | -h, --help Shows this help message. 30 | _EOF_ 31 | } 32 | 33 | # Options 34 | while [ "$1" != "" ]; do 35 | case $1 in 36 | -h|--help) usage 37 | exit 38 | ;; 39 | *) echo "calibre-installer.sh: unrecognized option '$1'" 40 | echo "Try 'calibre-installer.sh --help' for more information." 41 | exit 1 42 | esac 43 | shift 44 | done 45 | 46 | # Main 47 | 48 | ## Check that we are running as root 49 | if [[ $EUID -ne 0 ]]; then 50 | echo -e "You can only install calibre if you have root permission." 51 | exit 1 52 | fi 53 | 54 | do_install 55 | add_launchd 56 | -------------------------------------------------------------------------------- /osx/calibre-upgrade.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Unset git development source 4 | export CALIBRE_DEVELOP_FROM= 5 | # by default, switch is off 6 | force_upgrade=0 7 | 8 | # OSX command-line-tools bin 9 | tools=/Applications/calibre.app/Contents/console.app/Contents/MacOS 10 | 11 | # Functions 12 | 13 | calibre_is_installed() 14 | { 15 | [[ -e /Applications/calibre.app ]] 16 | } 17 | 18 | usage() 19 | { 20 | cat <<- _EOF_ 21 | Usage: calibre-upgrade.sh [OPTIONS] 22 | Upgrades calibre installation. Automatically checks if the current version is up to date. 23 | 24 | OPTIONS 25 | -f, --force Force an update. This is only useful if binaries 26 | were updated for a critical error. :shrug: 27 | -h, --help Displays this help message. 28 | _EOF_ 29 | } 30 | 31 | install_command_line_tools() 32 | { 33 | ## Check that we are running as root 34 | if [[ $EUID -ne 0 ]]; then 35 | echo -e "You can only install the command-line tools if you have root permission." 36 | else 37 | #Symlink the command-line tools to /usr/local/bin 38 | ln -sf $tools/* /usr/local/bin/ 39 | fi 40 | } 41 | 42 | do_upgrade() 43 | { 44 | if calibre_is_installed; then 45 | # shutdown calibre as each logged-in user. 46 | for i in $(users | tr ' ' '\n' | sort -u); do 47 | sudo -u $i $tools/calibre --shutdown-running-calibre 48 | done 49 | killall $tools/calibre-server > /dev/null 2>&1 \ 50 | && echo -e "A running instance of calibre-server was killed. Restart when upgrade is finished. ;)\n\n" \ 51 | || echo -e "No running calibre servers.\n\n" 52 | fi 53 | 54 | # Download and copy the DMG into /Applications 55 | ver=$(wget -q -O- http://code.calibre-ebook.com/latest) 56 | 57 | wget --continue -O /tmp/calibre-${ver}.dmg http://code.calibre-ebook.com/dist/osx32 58 | hdiutil attach -mountpoint /Volumes/calibre-${ver} /tmp/calibre-${ver}.dmg 59 | cp -R /Volumes/calibre-${ver}/calibre.app /Applications 60 | hdiutil detach /Volumes/calibre-${ver} 61 | 62 | install_command_line_tools 63 | } 64 | 65 | # Options 66 | while [ "$1" != "" ]; do 67 | case $1 in 68 | -h|--help) usage 69 | exit 70 | ;; 71 | -f|--force) shift 72 | force_upgrade=1 73 | ;; 74 | *) echo "calibre-upgrade.sh: unrecognized option '$1'" 75 | echo "Try 'calibre-upgrade.sh --help' for more information." 76 | exit 1 77 | esac 78 | shift 79 | done 80 | 81 | # Main 82 | 83 | if calibre_is_installed; then 84 | $tools/calibre-debug -c "from calibre.gui2.update import get_newest_version; from calibre.constants import numeric_version; raise SystemExit(int(numeric_version < get_newest_version()))" 85 | 86 | UP_TO_DATE=$? 87 | else 88 | echo -e "Calibre is not installed, installing...\n\n" 89 | UP_TO_DATE=1 90 | fi 91 | 92 | if [ "$UP_TO_DATE" = 0 ]; then 93 | echo "Calibre is up-to-date" 94 | 95 | if [ "$force_upgrade" = 1 ]; then 96 | echo "" 97 | echo "Forcing upgrade anyway -- are you sure you want to continue? [y/n]" 98 | read answer 99 | 100 | if [[ "$answer" = "y" || "$answer" = "yes" ]]; then 101 | do_upgrade 102 | else 103 | echo "Exiting..." 104 | exit 1 105 | fi 106 | fi 107 | else 108 | calibre_is_installed && echo -e "Calibre is out-of-date. Upgrading...\n\n" 109 | do_upgrade 110 | fi 111 | -------------------------------------------------------------------------------- /osx/com.calibre.updater.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Label 6 | com.calibre.updater 7 | 8 | Program 9 | /usr/local/bin/calibre-upgrade.sh 10 | 11 | StartCalendarInterval 12 | 13 | Weekday 14 | 5 15 | Hour 16 | 06 17 | Minute 18 | 00 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /windows/notes.txt: -------------------------------------------------------------------------------- 1 | #####Command-line method of creating a task. 2 | 3 | --------------------------------------------------- 4 | 5 | /tn "Name of task" 6 | /tr command-to-run 7 | /sc scheule type is weekly task 8 | /d day of week for /sc 9 | /st run at time in HH:MM:SS 10 | 11 | /ru username 12 | /rp password -- will prompt if switch is named, if unnamed then "Run only when user is logged on" is used. 13 | /rl highest -- set privilege mode, equivalent to "Run as Administrator" 14 | 15 | ---------------------------------------------------- 16 | schtasks /create /rl highest /tn "Calibre Updater" /sc weekly /d FRI /st 6:00:00 /tr %PROGRAMFILES%\calibre-upgrade.bat /ru administrator /rp 17 | ---------------------------------------------------- 18 | 19 | #####powershell 2.0 download file 20 | 21 | ---------------------------------------------------- 22 | (new-object System.Net.WebClient).DownloadFile("http://www.google.com/search.html", "google.com.html") 23 | ---------------------------------------------------- 24 | 25 | 26 | :: one-liner needs work... 27 | 28 | :: Set the location of files 29 | set upgradeDownloadFile=https://github.com/eli-schwartz/calibre-installer/raw/master/calibre-installer.bat 30 | set installer=%TEMP%\calibre-installer.bat 31 | 32 | :: hallelujah we can download a file 33 | powershell -Command "(new-object System.Net.WebClient).DownloadFile(\"%upgradeDownloadFile%\", \"%installer%\");" 34 | 35 | 36 | 37 | 38 | :: calibre-installer 39 | 40 | :: Set the location of calibre-upgrade 41 | set upgrade_script=https://github.com/eli-schwartz/calibre-installer/raw/master/windows/calibre-upgrade.bat 42 | set install_to=%PROGRAMFILES%\calibre-upgrade.bat 43 | 44 | :: hallelujah we can download a file 45 | powershell -Command "(new-object System.Net.WebClient).DownloadFile(\"%upgrade_script%\", \"%install_to%\");" 46 | 47 | 48 | 49 | 50 | 51 | :: Create a task as an administrator 52 | schtasks /create /tn "Calibre Updater" /sc weekly /st 06:00 /tr %install_to% /d FRI /ru administrator /rp 53 | --------------------------------------------------------------------------------