Skip to content

Commit 4269469

Browse files
committed
Create basic workflow to package binaries for linux
1 parent acf4db4 commit 4269469

6 files changed

Lines changed: 147 additions & 8 deletions

File tree

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ app:
66
poetry run python openandroidinstaller/openandroidinstaller.py
77

88
build-app:
9-
poetry run pyinstaller openandroidinstaller/openandroidinstaller.py --noconsole --noconfirm --onefile --icon "/assets/favicon.ico" --add-data "openandroidinstaller/assets:assets"
9+
poetry run pyinstaller openandroidinstaller/openandroidinstaller.py --noconsole --noconfirm --onefile --icon "/assets/favicon.ico" --add-data "openandroidinstaller/assets:assets" --add-binary "openandroidinstaller/bin/adb:bin/adb" --add-binary "openandroidinstaller/bin/fastboot:bin/fastboot" --add-binary "openandroidinstaller/bin/heimdall:bin/heimdall"
10+
1011

1112
clean-build:
1213
rm -rf build/ dist/

openandroidinstaller/openandroidinstaller.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,16 @@
5252
from widgets import call_button, confirm_button, get_title
5353

5454
# Toggle to True for development purposes
55-
DEVELOPMENT = False
56-
DEVELOPMENT_CONFIG = "Xperia Z" # "Pixel 3a"
55+
DEVELOPMENT = True
56+
DEVELOPMENT_CONFIG = "Samsung Galaxy A3 2017" # "Pixel 3a"
5757

5858

5959
PLATFORM = sys.platform
6060
logger.info(f"Running OpenAndroidInstaller on {PLATFORM}")
6161
# Define asset paths
6262
CONFIG_PATH = Path(__file__).parent.joinpath(Path("assets/configs")).resolve()
6363
IMAGE_PATH = Path(__file__).parent.joinpath(Path("assets/imgs")).resolve()
64+
BIN_PATH = Path(__file__).parent.joinpath(Path("bin")).resolve()
6465

6566

6667
class BaseView(UserControl):
@@ -183,7 +184,7 @@ def search_devices(self, e):
183184
if PLATFORM in ("linux", "MacOS"):
184185
output = check_output(
185186
[
186-
"adb",
187+
BIN_PATH.joinpath(Path("adb")).name,
187188
"shell",
188189
"dumpsys",
189190
"bluetooth_manager",
@@ -199,7 +200,7 @@ def search_devices(self, e):
199200
elif PLATFORM == "windows":
200201
output = check_output(
201202
[
202-
"adb",
203+
BIN_PATH.joinpath(Path("adb")).name,
203204
"shell",
204205
"dumpsys",
205206
"bluetooth_manager",
@@ -501,6 +502,10 @@ def build(self):
501502
return self.view
502503

503504
def call_to_phone(self, e, command: str):
505+
# TODO: use proper windows paths
506+
command = command.replace("adb", BIN_PATH.joinpath(Path("adb")).name)
507+
command = command.replace("fastboot", BIN_PATH.joinpath(Path("fastboot")).name)
508+
504509
command = command.replace("<recovery>", self.recovery_path)
505510
command = command.replace("<image>", self.image_path)
506511
command = command.replace("<inputtext>", self.inputtext.value)

openandroidinstaller/widgets.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@
1414
# Author: Tobias Sterbak
1515

1616
from functools import partial
17-
from os import path
1817
from typing import Callable
1918

20-
from flet import Column, Container, ElevatedButton, Image, Row, Text, alignment, icons
19+
from flet import Column, Container, ElevatedButton, Row, Text, alignment, icons
2120

2221

2322
def get_title(title: str):

poetry.lock

Lines changed: 64 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Pillow = "^9.2.0"
1616
PyYAML = "^6.0"
1717
isort = "^5.10.1"
1818
loguru = "^0.6.0"
19+
requests = "^2.28.1"
1920

2021
[tool.poetry.dev-dependencies]
2122

scripts/download-tools.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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

Comments
 (0)