Mercurial > codedump
comparison updatechromium.py @ 36:8e49e6662429
Add updatechromium.py
committer: GitHub <noreply@github.com>
author | Paper <37962225+mrpapersonic@users.noreply.github.com> |
---|---|
date | Mon, 21 Jun 2021 10:24:19 -0400 |
parents | |
children | 310a73329fa4 |
comparison
equal
deleted
inserted
replaced
35:7ea4b01a2e5c | 36:8e49e6662429 |
---|---|
1 # https://github.com/ungoogled-software/ungoogled-chromium-archlinux/ | |
2 import urllib.request | |
3 import os | |
4 import json | |
5 import sys | |
6 import subprocess | |
7 from tqdm import tqdm | |
8 | |
9 # Returns 0 if running, 1 if not running, and 2 if it doesn't exist | |
10 def check_for_file(file): | |
11 process = subprocess.Popen(["which", file], stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT) | |
12 process.wait() | |
13 | |
14 if process.returncode == 0: | |
15 try: | |
16 subprocess.check_output(["pidof", file]) | |
17 return 0 | |
18 except: | |
19 return 1 | |
20 else: | |
21 return 2 | |
22 | |
23 class DownloadProgressBar(tqdm): | |
24 def update_to(self, b=1, bsize=1, tsize=None): | |
25 if tsize is not None: | |
26 self.total = tsize | |
27 self.update(b * bsize - self.n) | |
28 | |
29 | |
30 def download_url(url, output_path): | |
31 with DownloadProgressBar(unit='B', unit_scale=True, | |
32 miniters=1, desc=url.split('/')[-1]) as t: | |
33 urllib.request.urlretrieve(url, filename=output_path, reporthook=t.update_to) | |
34 | |
35 if check_for_file("chromium") == 0: | |
36 print("Chromium is still running! Exiting...") | |
37 sys.exit(1) | |
38 if check_for_file("zstd") == 2: | |
39 print("zstd not found! Exiting...") | |
40 sys.exit(1) | |
41 if check_for_file("tar") == 2: | |
42 print("tar not found! Exiting...") | |
43 sys.exit(1) | |
44 OWNER = "ungoogled-software" | |
45 REPO = "ungoogled-chromium-archlinux" | |
46 r = urllib.request.urlopen(f"https://api.github.com/repos/{OWNER}/{REPO}/releases") | |
47 json = json.loads(r.read()) | |
48 for i in json[0]["assets"]: | |
49 if i["content_type"] == "application/octet-stream": | |
50 download_url(f"{i['browser_download_url']}", "/tmp/chromium.tar.zst") | |
51 os.system("sudo pacman -U /tmp/chromium.tar.zst") | |
52 os.remove("/tmp/chromium.tar.zst") | |
53 |