add release update
This commit is contained in:
parent
f1ed503cb4
commit
81e29d1fc2
4 changed files with 121 additions and 22 deletions
32
ctl
32
ctl
|
@ -87,20 +87,24 @@ if [ "$1" == "ui" ]; then
|
||||||
exit $?
|
exit $?
|
||||||
fi
|
fi
|
||||||
if [ "$1" == "update" ]; then
|
if [ "$1" == "update" ]; then
|
||||||
cd "$BASE/$NAME"
|
if [ -e $BASE/$NAME/.git ]; then
|
||||||
OLD=`"$0" version`
|
cd "$BASE/$NAME"
|
||||||
cd "$BASE/platform"
|
OLD=`"$0" version`
|
||||||
echo Update platform..
|
cd "$BASE/platform"
|
||||||
git pull
|
echo Update platform..
|
||||||
echo Update $NAME..
|
git pull
|
||||||
cd "$BASE/$NAME"
|
echo Update $NAME..
|
||||||
git pull
|
cd "$BASE/$NAME"
|
||||||
find . -name '*.pyc' -exec rm "{}" \;
|
git pull
|
||||||
$0 setup
|
find . -name '*.pyc' -exec rm "{}" \;
|
||||||
$0 update_static > /dev/null
|
$0 setup
|
||||||
NEW=`"$0" version`
|
$0 update_static > /dev/null
|
||||||
$0 postupdate -o $OLD -n $NEW
|
NEW=`"$0" version`
|
||||||
exit
|
$0 postupdate -o $OLD -n $NEW
|
||||||
|
exit
|
||||||
|
else
|
||||||
|
python2 oml update
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
if [ "$1" == "python" ]; then
|
if [ "$1" == "python" ]; then
|
||||||
cd "$BASE/$NAME"
|
cd "$BASE/$NAME"
|
||||||
|
|
|
@ -27,14 +27,16 @@ def r(*cmd):
|
||||||
return subprocess.call(cmd)
|
return subprocess.call(cmd)
|
||||||
|
|
||||||
def version(module):
|
def version(module):
|
||||||
os.chdir(join(root_dir, module))
|
if os.path.exists(join(root_dir, module, '.git')):
|
||||||
version = get('git', 'log', '-1', '--format=%cd', '--date=iso').split(' ')[0].replace('-', '')
|
os.chdir(join(root_dir, module))
|
||||||
version += '-' + get('git', 'rev-list', 'HEAD', '--count').strip()
|
version = get('git', 'log', '-1', '--format=%cd', '--date=iso').split(' ')[0].replace('-', '')
|
||||||
version += '-' + get('git', 'describe', '--always').strip()
|
version += '-' + get('git', 'rev-list', 'HEAD', '--count').strip()
|
||||||
os.chdir(root_dir)
|
version += '-' + get('git', 'describe', '--always').strip()
|
||||||
|
os.chdir(root_dir)
|
||||||
|
else:
|
||||||
|
version = settings.release['modules'][module]['version']
|
||||||
return version
|
return version
|
||||||
|
|
||||||
|
|
||||||
class Version(Command):
|
class Version(Command):
|
||||||
"""
|
"""
|
||||||
Print current version
|
Print current version
|
||||||
|
@ -68,7 +70,11 @@ class Update(Command):
|
||||||
Update to latest development version
|
Update to latest development version
|
||||||
"""
|
"""
|
||||||
def run(self):
|
def run(self):
|
||||||
pass
|
import update
|
||||||
|
if update.update():
|
||||||
|
print "OK"
|
||||||
|
else:
|
||||||
|
print "FAILED"
|
||||||
|
|
||||||
class PostUpdate(Command):
|
class PostUpdate(Command):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -10,7 +10,7 @@ from pdict import pdict
|
||||||
|
|
||||||
base_dir = os.path.normpath(os.path.join(os.path.abspath(os.path.dirname(__file__)), '..'))
|
base_dir = os.path.normpath(os.path.join(os.path.abspath(os.path.dirname(__file__)), '..'))
|
||||||
static_path = os.path.join(base_dir, 'static')
|
static_path = os.path.join(base_dir, 'static')
|
||||||
updates_path = os.path.join(base_dir, 'updates')
|
updates_path = os.path.normpath(os.path.join(base_dir, '..', 'updates'))
|
||||||
|
|
||||||
oml_config_path = os.path.join(base_dir, 'config.json')
|
oml_config_path = os.path.join(base_dir, 'config.json')
|
||||||
|
|
||||||
|
@ -65,6 +65,7 @@ else:
|
||||||
os.chmod(key_path, 0400)
|
os.chmod(key_path, 0400)
|
||||||
|
|
||||||
USER_ID = vk.to_ascii(encoding='base64')
|
USER_ID = vk.to_ascii(encoding='base64')
|
||||||
|
OML_UPDATE_KEY='K55EZpPYbP3X+3mA66cztlw1sSaUMqGwfTDKQyP2qOU'
|
||||||
|
|
||||||
if 'modules' in release and 'openmedialibrary' in release['modules']:
|
if 'modules' in release and 'openmedialibrary' in release['modules']:
|
||||||
MINOR_VERSION = release['modules']['openmedialibrary']['version']
|
MINOR_VERSION = release['modules']['openmedialibrary']['version']
|
||||||
|
|
88
oml/update.py
Normal file
88
oml/update.py
Normal file
|
@ -0,0 +1,88 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# vi:si:et:sw=4:sts=4:ts=4
|
||||||
|
from __future__ import division, with_statement
|
||||||
|
|
||||||
|
from contextlib import closing
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
import tarfile
|
||||||
|
import urllib2
|
||||||
|
import shutil
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
import requests
|
||||||
|
import ed25519
|
||||||
|
import ox
|
||||||
|
|
||||||
|
import settings
|
||||||
|
|
||||||
|
ENCODING='base64'
|
||||||
|
RELEASE_URL = "http://downloads.openmedialibrary.com/release.json"
|
||||||
|
|
||||||
|
def verify(release):
|
||||||
|
vk = ed25519.VerifyingKey(settings.OML_UPDATE_KEY, encoding=ENCODING)
|
||||||
|
value = []
|
||||||
|
for module in sorted(release['modules']):
|
||||||
|
value += [str('%s/%s' % (release['modules'][module]['version'], release['modules'][module]['sha1']))]
|
||||||
|
value = '\n'.join(value)
|
||||||
|
sig = str(release['signature'])
|
||||||
|
try:
|
||||||
|
vk.verify(sig, value, encoding=ENCODING)
|
||||||
|
except ed25519.BadSignatureError:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
def download(self, url, filename):
|
||||||
|
dirname = os.path.dirname(filename)
|
||||||
|
if dirname and not os.path.exists(dirname):
|
||||||
|
os.makedirs(dirname)
|
||||||
|
with open(filename, 'w') as f:
|
||||||
|
with closing(urllib2.urlopen(url)) as u:
|
||||||
|
data = u.read(4096)
|
||||||
|
while data:
|
||||||
|
f.write(data)
|
||||||
|
data = u.read(4096)
|
||||||
|
|
||||||
|
def new_version():
|
||||||
|
if settings.release:
|
||||||
|
r = requests.get(RELEASE_URL)
|
||||||
|
release_data = r.content
|
||||||
|
release = json.loads(release_data)
|
||||||
|
old = settings.release['modules']['openmedialibrary']['version']
|
||||||
|
new = release['modules']['openmedialibrary']['version']
|
||||||
|
return verify(release) and old < new
|
||||||
|
|
||||||
|
def update():
|
||||||
|
r = requests.get(RELEASE_URL)
|
||||||
|
release_data = r.content
|
||||||
|
release = json.loads(release_data)
|
||||||
|
old = settings.release['modules']['openmedialibrary']['version']
|
||||||
|
new = release['modules']['openmedialibrary']['version']
|
||||||
|
if verify(release) and old < new:
|
||||||
|
with open(os.path.join(settings.updates_path, 'release.json'), 'w') as fd:
|
||||||
|
fd.write(release_data)
|
||||||
|
os.chdir(settings.base_dir)
|
||||||
|
for module in release['modules']:
|
||||||
|
package_tar = os.path.join(settings.updates_path, release['modules'][module]['name'])
|
||||||
|
url = RELEASE_URL.replace('release.json', package_tar)
|
||||||
|
download(url, package_tar)
|
||||||
|
if ox.sha1sum(package_tar) == release['modules'][module]['sha1']:
|
||||||
|
shutil.move(module, '%s_old' % module)
|
||||||
|
tar = tarfile.open(package_tar)
|
||||||
|
tar.extractall()
|
||||||
|
tar.close()
|
||||||
|
shutil.rmtree('%s_old' % module)
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
os.unlink(package_tar)
|
||||||
|
with open(os.path.join(settings.config_dir, 'release.json'), 'w') as fd:
|
||||||
|
fd.write(release_data)
|
||||||
|
cmd = ['./ctl', 'stop']
|
||||||
|
subprocess.call(cmd)
|
||||||
|
cmd = ['./ctl', 'setup']
|
||||||
|
subprocess.call(cmd)
|
||||||
|
cmd = ['./ctl', 'postupdate', '-o', old, '-n', new]
|
||||||
|
subprocess.call(cmd)
|
||||||
|
cmd = ['./ctl', 'start']
|
||||||
|
return True
|
||||||
|
return True
|
Loading…
Reference in a new issue