View Single Post
Old 11-11-2013, 02:29 PM   #18
aleyx
Addict
aleyx can self-interpret dreams as they happen.aleyx can self-interpret dreams as they happen.aleyx can self-interpret dreams as they happen.aleyx can self-interpret dreams as they happen.aleyx can self-interpret dreams as they happen.aleyx can self-interpret dreams as they happen.aleyx can self-interpret dreams as they happen.aleyx can self-interpret dreams as they happen.aleyx can self-interpret dreams as they happen.aleyx can self-interpret dreams as they happen.aleyx can self-interpret dreams as they happen.
 
Posts: 250
Karma: 20386
Join Date: Sep 2010
Location: France
Device: Bookeen Diva, Kobo Clara BW
Seems like calibre-debug returns 0 regardless of the way the script (or -c command) exits. All of those return 0:

Code:
aleyx@grey:~/bin$ calibre-debug -c "sys.exit(1)"; echo $?
0
aleyx@grey:~/bin$ calibre-debug -c "sys.exit(0)"; echo $?
0
aleyx@grey:~/bin$ calibre-debug -c "raise SystemExit(0)"; echo $?
0
aleyx@grey:~/bin$ calibre-debug -c "raise SystemExit(1)"; echo $?
0
So my calibre-check.py becomes:

Code:
#!/usr/bin/env python
## -*- coding: utf-8 -*-
import urllib as u
from calibre.constants import numeric_version

if numeric_version < tuple(map(int, u.urlopen('http://calibre-ebook.com/downloads/latest_version').read()[:-1].split("."))):
        print "obsolete"
        raise SystemExit(1)
else:
        print "up-to-date"
        raise SystemExit(0)
And calibre-update.sh becomes:
Code:
#!/bin/bash
if calibre-debug $HOME/bin/calibre-check.py | grep -q "obsolete"; then
        killall calibre-server
        sudo python -c "import sys; py3 = sys.version_info[0] > 2; u = __import__('urllib.request' if py3 else 'urllib', fromlist=1); exec(u.urlopen('http://status.cali
bre-ebook.com/linux_installer').read()); main(install_dir='/opt')"
        $HOME/bin/calibre-server.sh
else
        echo "Calibre is up-to-date"
fi
Seems to work so far.

EDIT: newer version of update code here

Last edited by aleyx; 11-19-2013 at 04:57 PM.
aleyx is offline   Reply With Quote