Last optimizations
This commit is contained in:
parent
de96fad7f7
commit
f4fc03c26d
@ -1,3 +1,4 @@
|
||||
from pathlib import Path
|
||||
import requests
|
||||
import hashlib
|
||||
import sys
|
||||
@ -40,6 +41,15 @@ def yes_or_no(question, default=None):
|
||||
print("Please respond with 'yes' or 'no' " "(or 'y' or 'n').\n")
|
||||
|
||||
|
||||
def isAdbConnected():
|
||||
cmdlist = ['adb', 'devices']
|
||||
sp = subprocess.run(cmdlist, capture_output=True)
|
||||
if len(sp.stdout.split(b'\n')) < 4:
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
|
||||
def isMagiskInstalled():
|
||||
cmdlist = ['adb', 'shell', 'command', '-v', 'su']
|
||||
sp = subprocess.run(cmdlist, stdout=subprocess.DEVNULL,
|
||||
@ -59,10 +69,16 @@ def checkInstalledVersion():
|
||||
|
||||
def downloadUpdate(device, version):
|
||||
filename = f"lineage-{version}.zip"
|
||||
|
||||
if Path(filename).exists():
|
||||
print(f'{filename} already found locally.')
|
||||
else:
|
||||
url = f'https://download.lineage.microg.org/{device}/{filename}'
|
||||
r = requests.get(url, stream=True)
|
||||
with tqdm.wrapattr(open(filename, "wb"), "write",
|
||||
miniters=1, desc=filename,
|
||||
with tqdm.wrapattr(open(filename, "wb"),
|
||||
"write",
|
||||
miniters=1,
|
||||
desc=filename,
|
||||
total=int(r.headers.get('Content-Length'))) as fout:
|
||||
for chunk in r.iter_content(chunk_size=4096):
|
||||
fout.write(chunk)
|
||||
@ -150,6 +166,13 @@ def cleanUp(filename):
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("Checking if an adb device is connected...", end='', flush=True)
|
||||
if not isAdbConnected():
|
||||
print("\nNo adb device is connected.")
|
||||
print("Aborting.")
|
||||
sys.exit()
|
||||
print(' [OK]')
|
||||
|
||||
print("Checking if Magisk already installed...", end='', flush=True)
|
||||
if isMagiskInstalled():
|
||||
print("\nIt seems Magisk is already installed (su in PATH).")
|
||||
|
Reference in New Issue
Block a user