commit c72189069e50363e9fa9feb437f5889df0b7c7ff Author: j Date: Mon Aug 4 21:41:30 2014 +0200 Open Media Library.app diff --git a/Open Media Library.app/Contents/Info.plist b/Open Media Library.app/Contents/Info.plist new file mode 100644 index 0000000..54bb3a1 --- /dev/null +++ b/Open Media Library.app/Contents/Info.plist @@ -0,0 +1,26 @@ + + + + + CFBundleExecutable + Open Media Library + CFBundleGetInfoString + Open Media Library + CFBundleIconFile + Open Media Library.icns + CFBundleIdentifier + com.openmedialibrary.app + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + Open Media Library + CFBundlePackageType + APPL + CFBundleShortVersionString + 0.0.1 + CFBundleSignature + OML + CFBundleVersion + 0.0.20140804 + + diff --git a/Open Media Library.app/Contents/MacOS/Open Media Library b/Open Media Library.app/Contents/MacOS/Open Media Library new file mode 100755 index 0000000..3aa6868 --- /dev/null +++ b/Open Media Library.app/Contents/MacOS/Open Media Library @@ -0,0 +1,10 @@ +#!/bin/sh +cd "`dirname "$0"`" +BASE="$HOME/Library/Application Support/Open Media Library/" +if [ -e "$BASE" ]; then + launchctl start com.openmedialibrary.loginscript + open "$BASE/openmedialibrary/static/html/load.html" +else + python install.py "$BASE" & + open ../Resources/static/install.html +fi diff --git a/Open Media Library.app/Contents/MacOS/install.py b/Open Media Library.app/Contents/MacOS/install.py new file mode 100755 index 0000000..bee733d --- /dev/null +++ b/Open Media Library.app/Contents/MacOS/install.py @@ -0,0 +1,150 @@ +#!/usr/bin/env python +from __future__ import division, with_statement + +from contextlib import closing +import json +import os +import sys +import tarfile +import urllib2 +import SimpleHTTPServer +import SocketServer +from threading import Thread + +release_url = "http://downloads.openmedialibrary.com/release.json" +PORT = 9842 + + +static_dir = os.path.normpath(os.path.join(os.path.abspath(os.path.dirname(__file__)), '..', 'Resources', 'static')) + +class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler): + def do_OPTIONS(self): + self.send_response(200, 'OK') + self.send_header('Allow', 'GET, POST, OPTIONS') + self.send_header('Access-Control-Allow-Origin', '*') + self.send_header('Access-Control-Allow-Headers', 'X-Requested-With') + self.send_header('Content-Length', '0') + self.end_headers() + + def do_GET(self): + + if self.path == '/status': + content = json.dumps(self.server.install.status) + self.send_response(200, 'OK') + else: + path = os.path.join(static_dir, 'index.html' if self.path == '/' else self.path[1:]) + if os.path.exists(path): + with open(path) as fd: + content = fd.read() + self.send_response(200, 'OK') + else: + self.send_response(404, 'not found') + content = '404 not found' + self.send_header('Access-Control-Allow-Origin', '*') + self.send_header('Content-Length', str(len(content))) + self.end_headers() + self.wfile.write(content) + +def get_release(): + with closing(urllib2.urlopen(release_url)) as u: + data = json.load(u) + return data + + +class Install(Thread): + status = {} + + def __init__(self, target, httpd): + self.target = target + self.httpd = httpd + Thread.__init__(self) + self.daemon = True + self.start() + + def run(self): + target = self.target + target = os.path.normpath(os.path.join(os.path.abspath(target))) + if not os.path.exists(target): + os.makedirs(target) + os.chdir(target) + release = get_release() + self.status["release"] = release + for module in release['modules']: + self.status["installing"] = module + self.status["progress"] = 0 + self.status["size"] = 0 + package_tar = release['modules'][module]['name'] + url = release_url.replace('release.json', package_tar) + self.download(url, package_tar) + tar = tarfile.open(package_tar) + tar.extractall() + tar.close() + os.unlink(package_tar) + os.symlink('openmedialibrary/ctl', 'ctl') + self.status["progress"] = 0 + self.status["installing"] = "setup" + os.system("./ctl setup") + self.status["progress"] = 1 + with open('config/release.json', 'w') as fd: + json.dump(release, fd, indent=2) + if sys.platform == 'darwin': + self.install_launchd() + elif sys.platform == 'linux2': + #fixme, do only if on debian/ubuntu + os.sysrem('sudo apt-get install python-imaging python-setproctitle python-simplejson') + self.status = json.dumps({"done": True}) + self.httpd.shutdown() + + def download(self, url, filename): + dirname = os.path.dirname(filename) + if dirname and not os.path.exists(dirname): + os.makedirs(dirname) + print url, filename + with open(filename, 'w') as f: + with closing(urllib2.urlopen(url)) as u: + size = int(u.headers.get('content-length', 0)) + self.status["size"] = size + available = 0 + data = u.read(4096) + while data: + if size: + available += len(data) + self.status["progress"] = available/size + f.write(data) + data = u.read(4096) + + def install_launchd(self): + plist = os.path.expanduser('~/Library/LaunchAgents/com.openmedialibrary.loginscript.plist') + with open(plist, 'w') as f: + f.write(''' + + + + Label + com.openmedialibrary.loginscript + ProgramArguments + + %s/ctl + start + + RunAtLoad + + +''' % self.target) + os.system('launchctl load "%s"' % plist) + os.system('launchctl start com.openmedialibrary.loginscript') + + +if __name__ == '__main__': + if len(sys.argv) == 1: + target = os.path.join(os.curdir, 'openmedialibrary') + elif len(sys.argv) != 2: + print "usage: %s [target]" % sys.argv[0] + sys.exit(1) + else: + target = sys.argv[1] + SocketServer.TCPServer.allow_reuse_address = True + httpd = SocketServer.TCPServer(("", PORT), Handler) + install = Install(target, httpd) + httpd.install = install + httpd.serve_forever() diff --git a/Open Media Library.app/Contents/Resources/Open Media Library.icns b/Open Media Library.app/Contents/Resources/Open Media Library.icns new file mode 100644 index 0000000..b38e05b Binary files /dev/null and b/Open Media Library.app/Contents/Resources/Open Media Library.icns differ diff --git a/Open Media Library.app/Contents/Resources/static/index.html b/Open Media Library.app/Contents/Resources/static/index.html new file mode 100644 index 0000000..cb02249 --- /dev/null +++ b/Open Media Library.app/Contents/Resources/static/index.html @@ -0,0 +1,10 @@ + + + Open Media Library + + + Installing Open Media Library...
+
+ + + diff --git a/Open Media Library.app/Contents/Resources/static/install.html b/Open Media Library.app/Contents/Resources/static/install.html new file mode 100644 index 0000000..29461f7 --- /dev/null +++ b/Open Media Library.app/Contents/Resources/static/install.html @@ -0,0 +1,24 @@ + + + + + Open Media Library + + + + + diff --git a/Open Media Library.app/Contents/Resources/static/js/install.js b/Open Media Library.app/Contents/Resources/static/js/install.js new file mode 100644 index 0000000..9e586c3 --- /dev/null +++ b/Open Media Library.app/Contents/Resources/static/js/install.js @@ -0,0 +1,38 @@ +function load() { + var base = 'http://[::1]:9842', + img = new Image(); + img.onload = function(event) { + document.location.href = base; + }; + img.src = base + '/static/oxjs/build/Ox.UI/png/transparent.png?' + new Date; +}; + +function update() { + var xhr = new XMLHttpRequest(); + xhr.onload = function() { + var response = JSON.parse(this.responseText); + if (response.installing) { + var status = response.installing; + if (response.progress) { + status = parseInt(response.progress * 100) + '% ' + status; + } + document.getElementById('status').innerHTML = status; + setTimeout(update, 1000); + } else { + document.getElementById('status').innerHTML = "done"; + load(); + } + }; + xhr.onerror = function() { + var status = document.getElementById('status').innerHTML; + if (['done', 'setup'].indexOf(status) == -1) { + document.getElementById('status').innerHTML = "error"; + } + load(); + } + xhr.open('get', '/status'); + xhr.send(); + +} + +update(); diff --git a/README b/README new file mode 100644 index 0000000..7a3820c --- /dev/null +++ b/README @@ -0,0 +1,6 @@ +Open Media Library OS X Launcher and Installer + +place "Open Media Library.app" into /Applications + +On first launch it will install Open Media Library for each user. +Later you can use it to start or open Open Media Library. diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..5701907 --- /dev/null +++ b/build.sh @@ -0,0 +1,6 @@ +#!/bin/sh +tmpdir=`mktemp -d -t oml` +cp -r "Open Media Library.app" $tmpdir/ +hdiutil create -srcfolder "$tmpdir" -volname "Open Media Library" -format UDZO "Open Media Library.tmp.dmg" +hdiutil convert -format UDZO -imagekey zlib-level=9 -o "Open Media Library.dmg" "Open Media Library.tmp.dmg" +rm -rf $tmpdir "Open Media Library.tmp.dmg"