From f44f3dcd23817d189776e718e2a525cae4d7cc18 Mon Sep 17 00:00:00 2001 From: Jeremiah K <17190268+jeremiah-k@users.noreply.github.com> Date: Fri, 18 Oct 2024 09:19:52 -0500 Subject: [PATCH] Check if storage has been set up --- README.md | 10 ++++++++++ app/setup_config.py | 32 +++++++++++++------------------- setup.cfg | 2 +- 3 files changed, 24 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 6a55d19..3eb2832 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,16 @@ Fetchtastic is a tool to download the latest Meshtastic Android app and Firmware 3. **Install Termux API**: Download and install [Termux API](https://f-droid.org/en/packages/com.termux.api/) from F-Droid. 4. *(Optional)* **Install ntfy**: Download and install [ntfy](https://f-droid.org/en/packages/io.heckel.ntfy/) from F-Droid. +### Setup Termux Storage Access + +Open Termux and run the following command to grant storage access: + +```bash +termux-setup-storage +``` + +"Allow" when prompted, then restart Termux to apply the changes. + ## Installation ### Step 1: Install Dependencies diff --git a/app/setup_config.py b/app/setup_config.py index ce52239..d96476d 100644 --- a/app/setup_config.py +++ b/app/setup_config.py @@ -35,33 +35,27 @@ def config_exists(): return os.path.exists(CONFIG_FILE) def check_storage_setup(): - # Check if storage has been set up in Termux by verifying ~/storage directory + # Check if the Termux storage directory and Downloads are set up and writable storage_dir = os.path.expanduser("~/storage") - if not os.path.exists(storage_dir): + storage_downloads = os.path.expanduser("~/storage/downloads") + + # If ~/storage or ~/storage/downloads doesn't exist or isn't writable, exit + if not os.path.exists(storage_dir) or not os.path.exists(storage_downloads) or not os.access(storage_downloads, os.W_OK): print("Storage access is required to continue.") - print("We will now run a command to enable storage access.") - print("Please allow storage permissions in the upcoming popup.") - confirm = input("Proceed with setting up storage? [y/n] (default: yes): ").strip().lower() or 'y' - if confirm == 'y': - try: - # Run the termux-setup-storage command - subprocess.run(['termux-setup-storage'], check=True) - print("Storage access has been successfully configured. Please restart Termux if needed.") - except Exception as e: - print(f"An error occurred while setting up storage: {e}") - return False - else: - print("Storage setup is required to proceed. Exiting setup.") - return False + print("Please run 'termux-setup-storage' and restart Termux before running this setup again.") + exit() # Exit the script as storage is not set up + print("Storage access has been successfully verified.") return True def run_setup(): - print("Running Fetchtastic Setup...") - # First, check if Termux storage has been set up if is_termux() and not check_storage_setup(): + print("Setup cannot continue without proper storage access.") return - + + # The rest of your setup process continues here + print("Running Fetchtastic Setup...") + if not os.path.exists(DEFAULT_CONFIG_DIR): os.makedirs(DEFAULT_CONFIG_DIR) diff --git a/setup.cfg b/setup.cfg index 178be6c..533a159 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = fetchtastic -version = 0.1.4 +version = 0.1.5 author = Jeremiah K author_email = jeremiahk@gmx.com description = Meshtastic Firmware and APK Downloader