Skip to content

Commit

Permalink
Sleep boot script so wifi has time to connect
Browse files Browse the repository at this point in the history
Bump version

Add exclude patterns to setup
  • Loading branch information
jeremiah-k committed Oct 21, 2024
1 parent b203b08 commit 53e0df0
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 18 deletions.
8 changes: 6 additions & 2 deletions app/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def main():
firmware_versions_to_keep = config.get("FIRMWARE_VERSIONS_TO_KEEP", 2)
auto_extract = config.get("AUTO_EXTRACT", False)
extract_patterns = config.get("EXTRACT_PATTERNS", [])
exclude_patterns = config.get("EXCLUDE_PATTERNS", [])
wifi_only = config.get("WIFI_ONLY", True)

selected_apk_patterns = config.get('SELECTED_APK_ASSETS', [])
Expand Down Expand Up @@ -118,13 +119,16 @@ def is_connected_to_wifi():
return False

# Function to extract files from zip archives
def extract_files(zip_path, extract_dir, patterns):
def extract_files(zip_path, extract_dir, patterns, exclude_patterns):
try:
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
matched_files = []
for file_info in zip_ref.infolist():
file_name = file_info.filename
base_name = os.path.basename(file_name)
# Check if file matches exclude patterns
if any(exclude in base_name for exclude in exclude_patterns):
continue
for pattern in patterns:
if pattern in base_name:
# Extract and flatten directory structure
Expand Down Expand Up @@ -201,7 +205,7 @@ def check_and_download(releases, latest_release_file, release_type, download_dir
download_path = os.path.join(release_dir, file_name)
download_file(asset['browser_download_url'], download_path)
if auto_extract and file_name.endswith('.zip') and release_type == "Firmware":
extract_files(download_path, release_dir, extract_patterns)
extract_files(download_path, release_dir, extract_patterns, exclude_patterns)
downloaded_versions.append(release_tag)

# Only update latest_release_file if downloads occurred
Expand Down
58 changes: 43 additions & 15 deletions app/setup_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,12 @@ def run_setup():
if config.get('EXTRACT_PATTERNS'):
current_patterns = ' '.join(config.get('EXTRACT_PATTERNS', []))
print(f"Current patterns: {current_patterns}")
extract_patterns = input("Extraction patterns (leave blank to keep current): ").strip()
if extract_patterns:
extract_patterns = input("Extraction patterns (leave blank to keep current, enter '!' to clear): ").strip()
if extract_patterns == '!':
config['AUTO_EXTRACT'] = False
config['EXTRACT_PATTERNS'] = []
print("Extraction patterns cleared. No files will be extracted.")
elif extract_patterns:
config['AUTO_EXTRACT'] = True
config['EXTRACT_PATTERNS'] = extract_patterns.split()
else:
Expand All @@ -150,10 +154,43 @@ def run_setup():
config['EXTRACT_PATTERNS'] = extract_patterns.split()
else:
config['AUTO_EXTRACT'] = False
print("No extraction patterns provided. Extraction will be skipped.")
print("You can run 'fetchtastic setup' again to set extraction patterns.")
print("No patterns selected, no files will be extracted. Run setup again if you wish to change this.")
# Skip exclude patterns prompt
config['EXCLUDE_PATTERNS'] = []
# Prompt for exclude patterns if extraction is enabled
if config.get('AUTO_EXTRACT', False) and config.get('EXTRACT_PATTERNS'):
exclude_prompt = "Would you like to exclude any patterns from extraction? [y/n] (default: no): "
exclude_choice = input(exclude_prompt).strip().lower() or 'n'
if exclude_choice == 'y':
print("Enter the keywords to exclude from extraction, separated by spaces.")
print("Example: .hex tcxo")
if config.get('EXCLUDE_PATTERNS'):
current_excludes = ' '.join(config.get('EXCLUDE_PATTERNS', []))
print(f"Current exclude patterns: {current_excludes}")
exclude_patterns = input("Exclude patterns (leave blank to keep current, enter '!' to clear): ").strip()
if exclude_patterns == '!':
config['EXCLUDE_PATTERNS'] = []
print("Exclude patterns cleared. No files will be excluded.")
elif exclude_patterns:
config['EXCLUDE_PATTERNS'] = exclude_patterns.split()
else:
# Keep existing patterns
pass
else:
exclude_patterns = input("Exclude patterns: ").strip()
if exclude_patterns:
config['EXCLUDE_PATTERNS'] = exclude_patterns.split()
else:
config['EXCLUDE_PATTERNS'] = []
else:
# User chose not to exclude patterns
config['EXCLUDE_PATTERNS'] = []
else:
config['EXCLUDE_PATTERNS'] = []
else:
config['AUTO_EXTRACT'] = False
config['EXTRACT_PATTERNS'] = []
config['EXCLUDE_PATTERNS'] = []

# Ask if the user wants to only download when connected to Wi-Fi
wifi_only_default = 'yes' if config.get('WIFI_ONLY', True) else 'no'
Expand Down Expand Up @@ -316,26 +353,17 @@ def remove_cron_job():
except Exception as e:
print(f"An error occurred while removing the cron job: {e}")

def is_cron_job_set():
try:
result = subprocess.run(['crontab', '-l'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
if result.returncode == 0 and 'fetchtastic download' in result.stdout:
return True
else:
return False
except Exception:
return False

def setup_boot_script():
boot_dir = os.path.expanduser("~/.termux/boot")
boot_script = os.path.join(boot_dir, "fetchtastic.sh")
if not os.path.exists(boot_dir):
os.makedirs(boot_dir)
print("Created the Termux:Boot directory.")
print("It seems that Termux:Boot is not installed or hasn't been run yet.")
print("Please install Termux:Boot from F-Droid and run it once to enable boot scripts.")
# Write the boot script
with open(boot_script, 'w') as f:
f.write("#!/data/data/com.termux/files/usr/bin/sh\n")
f.write("sleep 30\n")
f.write("fetchtastic download\n")
os.chmod(boot_script, 0o700)
print("Boot script created to run Fetchtastic on device boot.")
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = fetchtastic
version = 0.1.9
version = 0.1.10
author = Jeremiah K
author_email = [email protected]
description = Meshtastic Firmware and APK Downloader
Expand Down

0 comments on commit 53e0df0

Please sign in to comment.