Last active
August 3, 2018 19:30
-
-
Save PierrickKoch/8f64d64b9d3212d62754 to your computer and use it in GitHub Desktop.
update atom -- https://github.com/atom/atom/issues/2956
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function check(resolved) { | |
console.log(resolved); | |
var tag = resolved.split('/').pop(-1); | |
var latest = tag.slice(1); | |
var current = atom.getVersion(); | |
if (latest != current) { | |
atom.notifications.addInfo('new version available: ' + resolved); | |
// TODO detect platform | |
// var filename = 'atom-amd64.deb'; // or 'atom.x86_64.rpm' | |
// var url = 'https://github.com/atom/atom/releases/download/' + tag + '/' + filename; | |
// TODO download and install | |
var status = atom.document.getElementsByClassName('status-bar-right')[0]; | |
var link = atom.document.createElement('a'); | |
link.href = resolved; | |
link.innerHTML = '<span class="icon icon-arrow-up"> update</span>'; | |
link.classList.add('inline-block'); | |
status.appendChild(link); | |
} | |
} | |
var request = new XMLHttpRequest(); | |
request.onreadystatechange = function () { | |
var DONE = this.DONE || 4; | |
if (this.readyState === DONE) { | |
check(this.responseURL); | |
} | |
}; | |
request.open('HEAD', 'https://github.com/atom/atom/releases/latest', true); | |
request.send(null); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python | |
import sys | |
import platform | |
try: # python3 | |
from urllib.request import urlopen, urlretrieve | |
except ImportError: # python2 | |
from urllib import urlopen, urlretrieve | |
import subprocess | |
def reporthook(count, block_size, total_size): | |
sys.stdout.write("\r%6.2f %% [%i/%i]"%((count * block_size * 100.0 / | |
total_size), count * block_size, total_size)) | |
sys.stdout.flush() | |
filename = "atom-amd64.deb" | |
base_url = "https://github.com/atom/atom/releases" | |
url_info = urlopen("%s/latest"%base_url) | |
resolved = url_info.geturl() | |
version = lambda s: list(map(int, s.split('.'))) | |
tag = resolved.split('/')[-1] | |
latest = version(tag[1:]) # remove 'v' in v0.1.2 | |
try: | |
cmd = subprocess.check_output(['atom', '--version']).decode() | |
if cmd.startswith('Atom'): cmd = cmd.split()[2] # since 1.7 | |
current = version(cmd) | |
except: | |
current = [0, 0, 0] | |
if latest > current: | |
if platform.dist()[0] in ['fedora', 'redhat', 'SuSE']: | |
filename = "atom.x86_64.rpm" | |
url = "%s/download/%s/%s"%(base_url, tag, filename) | |
print("downloading %s current is %s"%(url, current)) | |
filepath, _ = urlretrieve(url, filename, reporthook) | |
print("\ninstall %s"%filepath) | |
subprocess.check_output(['xdg-open', filepath]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment