forked from kovidgoyal/kitty
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-on-ubuntu
executable file
·55 lines (44 loc) · 1.55 KB
/
update-on-ubuntu
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
#!/usr/bin/env python3
# vim:fileencoding=utf-8
# License: GPL v3 Copyright: 2017, Kovid Goyal <kovid at kovidgoyal.net>
import os
import shlex
import shutil
import subprocess
import sys
import tempfile
from contextlib import suppress
if False:
tarball = sys.argv[-1]
dest = os.path.expanduser('~/.local/kitty.app')
shutil.rmtree(dest, ignore_errors=True)
os.makedirs(dest)
os.chdir(dest)
dest = os.path.expanduser('~/.local/bin/kitty')
with suppress(OSError):
os.remove(dest)
with suppress(OSError):
os.makedirs(os.path.dirname(dest))
subprocess.check_call(['tar', 'xJf', tarball])
os.symlink(os.path.abspath('bin/kitty'), dest)
print('kitty installed to ~/.local/kitty.app')
# EOF_REMOTE
HOST = 'ubuntu'
base = os.path.dirname(os.path.abspath(__file__))
if True:
sys.path.insert(0, base)
from kitty.constants import str_version
tarball = f'kitty-{str_version}-x86_64.txz'
def run(what):
ret = subprocess.run(shlex.split(what))
if ret.returncode != 0:
raise SystemExit(ret.returncode)
with open(__file__, 'rb') as f:
script = f.read().decode('utf-8')
script = script[:script.find('# EOF_REMOTE')].replace('if False:', 'if True:', 1)
with tempfile.NamedTemporaryFile(prefix='install-tarball-', suffix='.py') as f:
run('python ../bypy linux program --dont-strip --compression-level=1')
f.write(script.encode('utf-8'))
f.flush()
run(f'scp bypy/b/linux/64/sw/dist/{tarball} {f.name} {HOST}:/tmp')
run(f'ssh {HOST} python /tmp/{os.path.basename(f.name)} /tmp/{tarball}')