|
|
@ -1,3 +1,4 @@
|
|
|
|
|
|
|
|
from pathlib import Path
|
|
|
|
import requests
|
|
|
|
import requests
|
|
|
|
import hashlib
|
|
|
|
import hashlib
|
|
|
|
import sys
|
|
|
|
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")
|
|
|
|
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():
|
|
|
|
def isMagiskInstalled():
|
|
|
|
cmdlist = ['adb', 'shell', 'command', '-v', 'su']
|
|
|
|
cmdlist = ['adb', 'shell', 'command', '-v', 'su']
|
|
|
|
sp = subprocess.run(cmdlist, stdout=subprocess.DEVNULL,
|
|
|
|
sp = subprocess.run(cmdlist, stdout=subprocess.DEVNULL,
|
|
|
@ -59,10 +69,16 @@ def checkInstalledVersion():
|
|
|
|
|
|
|
|
|
|
|
|
def downloadUpdate(device, version):
|
|
|
|
def downloadUpdate(device, version):
|
|
|
|
filename = f"lineage-{version}.zip"
|
|
|
|
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}'
|
|
|
|
url = f'https://download.lineage.microg.org/{device}/{filename}'
|
|
|
|
r = requests.get(url, stream=True)
|
|
|
|
r = requests.get(url, stream=True)
|
|
|
|
with tqdm.wrapattr(open(filename, "wb"), "write",
|
|
|
|
with tqdm.wrapattr(open(filename, "wb"),
|
|
|
|
miniters=1, desc=filename,
|
|
|
|
"write",
|
|
|
|
|
|
|
|
miniters=1,
|
|
|
|
|
|
|
|
desc=filename,
|
|
|
|
total=int(r.headers.get('Content-Length'))) as fout:
|
|
|
|
total=int(r.headers.get('Content-Length'))) as fout:
|
|
|
|
for chunk in r.iter_content(chunk_size=4096):
|
|
|
|
for chunk in r.iter_content(chunk_size=4096):
|
|
|
|
fout.write(chunk)
|
|
|
|
fout.write(chunk)
|
|
|
@ -150,6 +166,13 @@ def cleanUp(filename):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
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)
|
|
|
|
print("Checking if Magisk already installed...", end='', flush=True)
|
|
|
|
if isMagiskInstalled():
|
|
|
|
if isMagiskInstalled():
|
|
|
|
print("\nIt seems Magisk is already installed (su in PATH).")
|
|
|
|
print("\nIt seems Magisk is already installed (su in PATH).")
|
|
|
|