1+ """Basic script to get adb and fastboot.
2+
3+ Inspired by: https://gitlab.com/ubports/installer/android-tools-bin/-/blob/master/build.js
4+ """
5+ import requests
6+ from pathlib import Path
7+ import zipfile
8+ from io import BytesIO
9+
10+
11+ def download_adb_fastboot (platform : str ):
12+ url = f"https://dl.google.com/android/repository/platform-tools-latest-{ platform } .zip"
13+ # Downloading the file by sending the request to the URL
14+ response = requests .get (url , allow_redirects = True )
15+ # Split URL to get the file name
16+ filename = url .split ('/' )[- 1 ]
17+
18+ # Writing the file to the local file system
19+ download_path = Path (__file__ ).parent .joinpath (Path ("tools" )).resolve ()
20+ file = zipfile .ZipFile (BytesIO (response .content ))
21+ file .extractall (download_path .name )
22+ return filename
23+
24+
25+ def download_heimdall (platform : str ):
26+ url = f"https://people.ubuntu.com/~neothethird/heimdall-{ platform } .zip"
27+ # Downloading the file by sending the request to the URL
28+ response = requests .get (url , allow_redirects = True )
29+ # Split URL to get the file name
30+ filename = url .split ('/' )[- 1 ]
31+
32+ # Writing the file to the local file system
33+ download_path = Path (__file__ ).parent .joinpath (Path ("heimdall" )).resolve ()
34+ file = zipfile .ZipFile (BytesIO (response .content ))
35+ file .extractall (download_path .name )
36+ return filename
37+
38+
39+
40+ def move_files_to_lib ():
41+ target_path = Path ("openandroidinstaller/bin" , exist_ok = True )
42+ target_path .mkdir ()
43+ # move adb
44+ adb_path = Path (__file__ ).parent .joinpath (Path ("../tools/platform-tools/adb" )).resolve ()
45+ adb_target_path = Path (__file__ ).parent .joinpath (Path ("../openandroidinstaller/bin/adb" )).resolve ()
46+ adb_path .rename (adb_target_path )
47+ # move fastboot
48+ fb_path = Path (__file__ ).parent .joinpath (Path ("../tools/platform-tools/fastboot" )).resolve ()
49+ fb_target_path = Path (__file__ ).parent .joinpath (Path ("../openandroidinstaller/bin/fastboot" )).resolve ()
50+ fb_path .rename (fb_target_path )
51+ # move heimdall
52+ hd_path = Path (__file__ ).parent .joinpath (Path ("../heimdall/heimdall" )).resolve ()
53+ hd_target_path = Path (__file__ ).parent .joinpath (Path ("../openandroidinstaller/bin/heimdall" )).resolve ()
54+ hd_path .rename (hd_target_path )
55+ # make executable
56+ adb_target_path .chmod (0o755 )
57+ fb_target_path .chmod (0o755 )
58+ hd_target_path .chmod (0o755 )
59+ print ("Done" )
60+
61+
62+ def main ():
63+ filename = download_adb_fastboot (platform = "linux" )
64+ print (filename )
65+ filename = download_heimdall (platform = "linux" )
66+ move_files_to_lib ()
67+
68+
69+ if __name__ == "__main__" :
70+ main ()
0 commit comments