waydroid_script/main.py

344 lines
11 KiB
Python
Raw Normal View History

2023-01-22 18:20:20 -08:00
#!/usr/bin/env python3
2023-04-29 10:36:05 -07:00
from InquirerPy import inquirer
from InquirerPy.base.control import Choice
from InquirerPy.separator import Separator
import argparse
2023-04-29 08:00:42 -07:00
import os
from typing import List
2023-05-04 07:51:32 -07:00
from stuff.android_id import AndroidId
from stuff.gapps import Gapps
from stuff.general import General
from stuff.hidestatusbar import HideStatusBar
from stuff.houdini import Houdini
from stuff.magisk import Magisk
from stuff.microg import MicroG
from stuff.ndk import Ndk
from stuff.nodataperm import Nodataperm
from stuff.smartdock import Smartdock
from stuff.widevine import Widevine
import tools.helper as helper
2023-04-29 08:00:42 -07:00
from tools import container
from tools import images
2023-04-29 04:10:24 -07:00
import argparse
2023-04-29 08:00:42 -07:00
from tools.logger import Logger
2023-04-29 11:46:11 -07:00
def get_certified(args):
AndroidId().get_id()
2023-04-29 08:00:42 -07:00
def mount(partition, copy_dir):
img = os.path.join(images.get_image_dir(), partition+".img")
mount_point = ""
if partition == "system":
mount_point = os.path.join(copy_dir)
else:
mount_point = os.path.join(copy_dir, partition)
Logger.info("Mounting {} to {}".format(img, mount_point))
images.mount(img, mount_point)
def resize(partition):
img = os.path.join(images.get_image_dir(), partition+".img")
img_size = int(os.path.getsize(img)/(1024*1024))
new_size = "{}M".format(img_size+500)
Logger.info("Resizing {} to {}".format(img, new_size))
images.resize(img, new_size)
def umount(partition, copy_dir):
mount_point = ""
if partition == "system":
mount_point = os.path.join(copy_dir)
else:
mount_point = os.path.join(copy_dir, partition)
Logger.info("Umounting {}".format(mount_point))
images.umount(mount_point)
2023-01-21 10:50:03 -08:00
2023-04-29 10:36:05 -07:00
def install_app(args):
install_list: List[General] = []
app = args.app
if "gapps" in app:
install_list.append(Gapps(args.android_version))
if "libndk" in app and "houdini" not in app:
arch = helper.host()[0]
if arch == "x86_64":
2023-05-25 06:34:20 -07:00
install_list.append(Ndk(args.android_version))
2023-04-29 10:36:05 -07:00
else:
Logger.warn("libndk is not supported on your CPU")
if "libhoudini" in app and "ndk" not in app:
arch = helper.host()[0]
if arch == "x86_64":
install_list.append(Houdini(args.android_version))
else:
Logger.warn("libhoudini is not supported on your CPU")
if "magisk" in app:
install_list.append(Magisk())
if "widevine" in app:
install_list.append(Widevine(args.android_version))
if "smartdock" in app:
install_list.append(Smartdock())
if "microg" in app:
install_list.append(MicroG(args.android_version, args.microg_variant))
2023-04-29 10:36:05 -07:00
if not container.use_overlayfs():
copy_dir = "/tmp/waydroid"
container.stop()
resize_system, resize_vendor = False, False
2023-04-29 08:00:42 -07:00
for item in install_list:
2023-04-29 10:36:05 -07:00
if item.partition == "system":
resize_system = True
elif item.partition == "vendor":
resize_vendor = True
if resize_system:
resize("system")
if resize_vendor:
resize("vendor")
mount("system", copy_dir)
mount("vendor", copy_dir)
for item in install_list:
item.install()
if not container.use_overlayfs():
umount("vendor", copy_dir)
umount("system", copy_dir)
container.upgrade()
def remove_app(args):
remove_list: List[General] = []
app = args.app
if "gapps" in app:
remove_list.append(Gapps(args.android_version))
if "libndk" in app and "houdini" not in app:
remove_list.append(Ndk(args.android_version))
2023-04-29 10:36:05 -07:00
if "libhoudini" in app and "ndk" not in app:
remove_list.append(Houdini(args.android_version))
if "magisk" in app:
remove_list.append(Magisk())
if "widevine" in app:
remove_list.append(Widevine(args.android_version))
if "smartdock" in app:
remove_list.append(Smartdock())
if "microg" in app:
remove_list.append(MicroG(args.android_version, args.microg_variant))
if "nodataperm" in app:
remove_list.append(Nodataperm(args.android_version))
if "hidestatusbar" in app:
remove_list.append(HideStatusBar())
if not container.use_overlayfs():
copy_dir = "/tmp/waydroid"
container.stop()
for item in remove_list:
item.uninstall()
if not container.use_overlayfs():
umount("vendor", copy_dir)
umount("system", copy_dir)
container.upgrade()
def hack_option(args):
Logger.warning(
"If these hacks cause any problems, run `sudo python main.py remove <hack_option>` to remove")
hack_list: List[General] = []
options = args.option_name
if "nodataperm" in options:
hack_list.append(Nodataperm())
if "hidestatusbar" in options:
hack_list.append(HideStatusBar())
if not container.use_overlayfs():
copy_dir = "/tmp/waydroid"
container.stop()
resize_system, resize_vendor = False, False
2023-04-29 08:00:42 -07:00
for item in hack_list:
2023-04-29 10:36:05 -07:00
if item.partition == "system":
resize_system = True
elif item.partition == "vendor":
resize_vendor = True
if resize_system:
resize("system")
if resize_vendor:
resize("vendor")
mount("system", copy_dir)
mount("vendor", copy_dir)
for item in hack_list:
item.install()
if not container.use_overlayfs():
umount("vendor", copy_dir)
umount("system", copy_dir)
container.upgrade()
def interact():
os.system("clear")
args = argparse.Namespace()
android_version = inquirer.select(
message="Select Android version",
instruction="(\u2191\u2193 Select Item)",
choices=[
Choice(name="Android 11", value="11"),
Choice(name="Android 13", value="13"),
Choice(name="Exit", value=None)
],
default="11",
).execute()
if not android_version:
exit()
args.android_version = android_version
action = inquirer.select(
message="Please select an action",
choices=[
"Install",
"Remove",
"Hack",
2023-05-04 07:51:32 -07:00
"Get Google Device ID to Get Certified"
2023-04-29 10:36:05 -07:00
],
2023-05-04 07:51:32 -07:00
instruction="([↑↓]: Select Item)",
2023-04-29 10:36:05 -07:00
default=None,
).execute()
if not action:
exit()
2023-05-25 03:21:01 -07:00
install_choices = ["gapps", "microg", "libndk", "magisk", "smartdock",]
hack_choices = []
if android_version=="11":
install_choices.extend(["libhoudini", "widevine"])
hack_choices.extend(["nodataperm", "hidestatusbar"])
2023-04-29 10:36:05 -07:00
if action == "Install":
apps = inquirer.checkbox(
message="Select apps",
2023-05-04 07:51:32 -07:00
instruction="([\u2191\u2193]: Select Item. [Space]: Toggle Choice), [Enter]: Confirm",
2023-04-29 10:36:05 -07:00
validate=lambda result: len(result) >= 1,
invalid_message="should be at least 1 selection",
choices=install_choices
).execute()
microg_variants = ["Standard", "NoGoolag",
"UNLP", "Minimal", "MinimalIAP"]
2023-06-01 00:39:14 -07:00
if "microg" in apps:
2023-04-29 10:36:05 -07:00
microg_variant = inquirer.select(
message="Select MicroG variant",
choices=microg_variants,
default="Standard",
).execute()
args.microg_variant = microg_variant
args.app = apps
install_app(args)
elif action == "Remove":
apps = inquirer.checkbox(
message="Select apps",
2023-05-04 07:51:32 -07:00
instruction="([\u2191\u2193]: Select Item. [Space]: Toggle Choice), [Enter]: Confirm",
2023-04-29 10:36:05 -07:00
validate=lambda result: len(result) >= 1,
invalid_message="should be at least 1 selection",
choices=[*install_choices, *hack_choices]
).execute()
args.app = apps
args.microg_variant="Standard"
remove_app(args)
2023-04-29 11:46:11 -07:00
elif action == "Hack":
2023-04-29 10:36:05 -07:00
apps = inquirer.checkbox(
message="Select hack options",
2023-05-04 07:51:32 -07:00
instruction="([\u2191\u2193]: Select Item. [Space]: Toggle Choice), [Enter]: Confirm",
2023-04-29 10:36:05 -07:00
validate=lambda result: len(result) >= 1,
invalid_message="should be at least 1 selection",
choices=hack_choices
).execute()
args.option_name = apps
2023-04-29 11:46:11 -07:00
hack_option(args)
2023-05-04 07:51:32 -07:00
elif action == "Get Google Device ID to Get Certified":
AndroidId().get_id()
2023-04-29 08:00:42 -07:00
2023-04-29 10:36:05 -07:00
def main():
2023-04-29 08:00:42 -07:00
parser = argparse.ArgumentParser(description='''
2023-01-21 10:50:03 -08:00
Does stuff like installing Gapps, installing Magisk, installing NDK Translation and getting Android ID for device registration.
2023-04-29 08:00:42 -07:00
Use -h flag for help!''')
2023-01-21 10:50:03 -08:00
2023-04-29 08:00:42 -07:00
subparsers = parser.add_subparsers(title="coomand", dest='command')
2023-04-27 12:54:19 -07:00
parser.add_argument('-a', '--android-version',
dest='android_version',
help='Specify the Android version',
default="11",
2023-04-29 08:00:42 -07:00
choices=["11", "13"])
# android command
certified = subparsers.add_parser(
'certified', help='Get device ID to obtain Play Store certification')
certified.set_defaults(func=get_certified)
2023-01-21 10:50:03 -08:00
2023-04-29 08:00:42 -07:00
install_choices = ["gapps", "microg", "libndk",
"libhoudini", "magisk", "smartdock", "widevine"]
hack_choices = ["nodataperm", "hidestatusbar"]
micrg_variants = ["Standard", "NoGoolag", "UNLP", "Minimal", "MinimalIAP"]
remove_choices = install_choices
2023-01-21 10:50:03 -08:00
arg_template = {
"dest": "app",
"type": str,
"nargs": '+',
2023-04-29 08:00:42 -07:00
# "metavar":"",
2023-01-21 10:50:03 -08:00
}
2023-01-24 09:52:41 -08:00
install_help = """
2023-04-29 04:10:24 -07:00
gapps: Install Open GApps (Android 11) or MindTheGapps (Android 13)
2023-01-24 09:52:41 -08:00
microg: Add microG, Aurora Store and Aurora Droid to WayDriod
libndk: Add libndk arm translation, better for AMD CPUs
libhoudini: Add libhoudini arm translation, better for Intel CPUs
magisk: Install Magisk Delta to WayDroid
smartdock: A desktop mode launcher for Android
2023-04-29 04:10:24 -07:00
widevine: Add support for widevine DRM L3
2023-01-24 09:52:41 -08:00
"""
2023-04-29 08:00:42 -07:00
# install and its aliases
install_parser = subparsers.add_parser(
'install', formatter_class=argparse.RawTextHelpFormatter, help='Install an app')
install_parser.add_argument(
**arg_template, choices=install_choices, help=install_help)
install_parser.set_defaults(func=install_app)
# remove and its aliases
2023-04-29 10:36:05 -07:00
remove_parser = subparsers.add_parser(
'remove', aliases=["uninstall"], help='Remove an app')
2023-04-29 08:00:42 -07:00
remove_parser.add_argument(
2023-04-29 10:36:05 -07:00
**arg_template, choices=[*remove_choices, * hack_choices], help='Name of app to remove')
2023-04-29 08:00:42 -07:00
remove_parser.set_defaults(func=remove_app)
# hack and its aliases
hack_parser = subparsers.add_parser('hack', help='Hack the system')
hack_parser.add_argument(
2023-04-29 10:36:05 -07:00
'option_name', nargs="+", choices=hack_choices, help='Name of hack option')
2023-04-29 08:00:42 -07:00
hack_parser.set_defaults(func=hack_option)
2023-01-21 10:50:03 -08:00
args = parser.parse_args()
2023-04-29 10:36:05 -07:00
args.microg_variant = "Standard"
2023-04-29 08:00:42 -07:00
if hasattr(args, 'func'):
args_dict = vars(args)
helper.check_root()
2023-04-27 12:54:19 -07:00
args.func(args)
2023-01-21 10:50:03 -08:00
else:
2023-04-29 10:36:05 -07:00
helper.check_root()
interact()
2023-01-21 10:50:03 -08:00
if __name__ == "__main__":
2023-04-25 18:16:59 -07:00
main()