public
Last active

Chromium Daily Installer for Linux

  • Download Gist
chromium_daily.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
#!/usr/bin/env python
# coding: utf-8
 
import errno
import os
import platform
import shutil
import stat
import subprocess
import sys
import tempfile
import zipfile
try:
import requests
except ImportError:
raise ImportError("Install requests with `pip install --user requests`")
 
 
# Adjust this:
INSTALL_PATH = "/home/pascal/Applications/chromium-daily"
 
GREEN_URL = "https://chromium-status.appspot.com/lkgr"
DOWNLOAD_URL = "http://commondatastorage.googleapis.com/chromium-browser-continuous/Linux_{arch}/{revision}/chrome-linux.zip"
REVISION_FILE = INSTALL_PATH + "/REVISION.txt"
 
 
def get_download_url(revision):
machine = platform.machine()
if machine == 'x86_64':
arch = 'x64'
else:
# Obviously, this is a fairly risky assumption.
arch = 'x86'
 
return DOWNLOAD_URL.format(arch=arch, revision=revision)
 
 
def get_revision():
request = requests.get(GREEN_URL)
return request.text.strip()
 
 
def get_local_revision():
try:
return open(REVISION_FILE, 'r').read().strip()
except IOError:
return 0
 
 
def backup_old():
# Remote previous
old_path = INSTALL_PATH + "/chromium.old"
shutil.rmtree(old_path, ignore_errors=True)
try:
os.rename(INSTALL_PATH + "/chrome-linux", old_path)
except OSError:
# Fails without prior install, obviously.
pass
 
 
def unpack(file):
zip = zipfile.ZipFile(file)
zip.extractall(INSTALL_PATH)
 
 
def upgrade(revision):
download_url = get_download_url(revision)
dlfile = tempfile.NamedTemporaryFile()
 
print("Starting download …")
if subprocess.call(["wget", download_url, "-O", dlfile.name]) != 0:
print("Download failed. New release probably hasn't been pushed yet.")
sys.exit(1)
 
print("Download finished.")
 
backup_old()
unpack(dlfile.name)
 
# Make the chrome file executable.
for executable in ('nacl_helper_bootstrap', 'nacl_helper', 'xdg-mime',
'xdg-settings', 'chrome', 'chrome-wrapper'):
bin_path = os.path.join(INSTALL_PATH, "chrome-linux", executable)
os.chmod(bin_path, 0o755)
 
with open(REVISION_FILE, 'w') as revision_file:
revision_file.write(unicode(revision))
 
print("Done. Execute {} to start Chromium.".format(bin_path))
 
 
def main():
try:
os.makedirs(INSTALL_PATH)
except OSError as e:
if e.errno != errno.EEXIST:
raise
 
local_revision = get_local_revision()
remote_revision = get_revision()
print("Local: {}, Remote: {}".format(local_revision, remote_revision))
 
if int(remote_revision) > int(local_revision):
print("Upgrading …")
upgrade(remote_revision)
 
 
if __name__ == "__main__":
main()

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.