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