diff --git a/README.md b/README.md index 7d658fa..6371e6b 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ This is a guide on utilizing ADB tools to uninstall packages on your bloated Xiaomi Phone, just so it reduces the spooky tracking from Big Tech, and not hog your system resources for a more minimalistic user experience. There's no root required to uninstall these packages. -***NOTE:*** Running all commands listed in ["command.txt"](/command.txt) will safely remove the applications,yet it is recommended to find a replacement of some +***NOTE:*** Running all commands listed in ["command.yaml"](/command.yaml) will safely remove the applications,yet it is recommended to find a replacement of some applications you require. These commands cannot harm your device or put your phone into a loop. However, you may lose functionality of some services like, *_Xiaomi Cloud Services_*, so make sure you don't take out something you need. @@ -64,5 +64,24 @@ For example, to list all installed packages with Google in their name, you'd typ pm list package | grep google - + ## Uninstalling and restoring packages using the script + + In order to uninstall the packages listed in the [provided file](./command.yaml),run: + ```bash + python main.py -u + ``` + In case you want to restore any of the packages ununstalled by the above command,run: + ```bash + python main.py -r + ``` + + you can also reference your own file like this: + ```bash + python main.py file= + ``` + + if you just run the script with no flags or options,it will default to + ```bash + python main.py -u file=command.yaml + ``` diff --git a/command.txt b/command.yaml similarity index 100% rename from command.txt rename to command.yaml diff --git a/main.py b/main.py index e28199a..e93dcb0 100644 --- a/main.py +++ b/main.py @@ -1,16 +1,51 @@ import subprocess +import sys + +class CommandLineOptions: + command = None + file = None + + def __init__(self,command ="-u",file="command.yaml"): + self.command = command + self.file = file # Uninstalls packages def uninstall_apk(package_name): subprocess.run(["adb", "shell", "pm", "uninstall", "--user", "0", package_name]) -# Reads from file and uninstalls -with open("commands.txt", "r") as file: - lines = file.readlines() - for line in lines: - if line.strip(): - package_name = line.split("|")[0].strip() - print(f"Uninstalling: {package_name}") - uninstall_apk(package_name) +#restores packages +def restore_apk(package_name): + subprocess.run(["adb", "shell", "cmd","package", "install-existing", package_name]) + +# Reads from file and execute an install or unuinstall +def read_and_execute(file_name,command,command_str = ""): + with open(file_name, "r") as file: + lines = file.readlines() + for line in lines: + if line.strip(): + package_name = line.split("|")[0].strip() + if not package_name.startswith("#"): + print(f"{command_str} {package_name}") + command(package_name) + +def read_cmd_line(): + options = CommandLineOptions() + for flag in sys.argv: + if flag == "-i" or flag == "-r": + options.command = flag + elif not (flag.find("=") == -1): + print(flag.find("=")) + if flag.split("=")[0] == "file": + options.file = flag.split("=")[1] + return options + +def main(): + options = read_cmd_line() + if options.command == "-u": + read_and_execute(options.file,uninstall_apk,"Uninstalling : ") + print("\nAPK uninstallation completed.") + elif options.command == "-r": + read_and_execute(options.file,restore_apk,"Restoring : ") + print("\nAPK restoration completed.") -print("APK uninstallation completed.") +main() \ No newline at end of file