WARRIOR ANDROID FORCE-RESET & UPDATE TOOLKIT

WARRIOR ANDROID FORCE-RESET & UPDATE TOOLKIT

BackerLeader posted 7 min read

!/data/data/com.termux/files/usr/bin/bash

============================================================

WARRIOR ANDROID FORCE-RESET & UPDATE TOOLKIT

Version : 3.0.0

Author : Vulnerability Hunter Warrior | Zayed Shield

Platform : Termux (Android - No Root Required)

License : For security research & personal maintenance

============================================================

DESCRIPTION:

Aggressively clears cache, fixes permission errors,

updates Termux environment, and restores Android health.

Works in 3 escalating tiers:

Tier 1 - Termux-native (no special perms)

Tier 2 - ADB over Wi-Fi (developer options)

Tier 3 - Root mode (if rooted)

============================================================

════════════════════════════════════════════════════════════

TIER 1 — TERMUX NATIVE (No Root, No ADB)

════════════════════════════════════════════════════════════

tier1_termux_cleanup() {

log_step "1" "TIER 1 — TERMUX CACHE & PACKAGE DEEP CLEAN"

# 1.1 Fix broken pkg repos
log_info "Resetting Termux package repositories to official mirrors..."
mkdir -p "$HOME/../usr/etc/apt/sources.list.d/"
cat > "$HOME/../usr/etc/apt/sources.list" << 'REPO'

deb https://packages.termux.dev/apt/termux-main stable main
REPO

log_ok "Repository reset to: packages.termux.dev (official)"

# 1.2 Fix DNS / TLS issues
log_info "Refreshing CA certificates..."
pkg install -y ca-certificates &>/dev/null
update-ca-certificates &>/dev/null 2>&1
log_ok "CA certificates refreshed"

# 1.3 Fix clock sync (broken TLS root cause)
log_info "Checking system time synchronization..."
if command -v ntpdate &>/dev/null; then
    ntpdate -u pool.ntp.org &>/dev/null && log_ok "NTP time synced" || log_warn "NTP sync skipped"
else
    pkg install -y ntpsec &>/dev/null
    ntpdate -u pool.ntp.org &>/dev/null 2>&1 && log_ok "NTP synced" || log_warn "Time sync unavailable — enable auto-time in Android Settings"
fi

# 1.4 APT deep clean
log_info "Removing APT lists and lock files..."
rm -f  "$HOME/../usr/var/lib/apt/lists/lock"        2>/dev/null
rm -f  "$HOME/../usr/var/cache/apt/archives/lock"   2>/dev/null
rm -rf "$HOME/../usr/var/lib/apt/lists/"*            2>/dev/null
rm -rf "$HOME/../usr/var/cache/apt/archives/"*.deb   2>/dev/null
log_ok "APT locks and stale lists cleared"

# 1.5 Update + Full Upgrade
log_info "Running pkg update & full upgrade (this may take a while)..."
pkg update -y 2>&1 | tail -5
pkg upgrade -y 2>&1 | tail -5
log_ok "Termux packages updated to latest"

# 1.6 Autoremove + Autoclean
apt autoremove -y &>/dev/null 2>&1
apt autoclean  -y &>/dev/null 2>&1
log_ok "Orphaned packages removed, cache cleaned"

# 1.7 Termux home cache
log_info "Purging Termux home-dir caches..."
local CACHE_DIRS=(
    "$HOME/.cache"
    "$HOME/.npm/_cacache"
    "$HOME/.pip/cache"
    "$HOME/.cargo/registry/cache"
    "$HOME/.gradle/caches"
    "$HOME/.m2/repository"
    "$HOME/../usr/var/cache"
    "$HOME/../usr/tmp"
)
for dir in "${CACHE_DIRS[@]}"; do
    if [ -d "$dir" ]; then
        local SIZE
        SIZE=$(du -sh "$dir" 2>/dev/null | cut -f1)
        rm -rf "$dir" && log_ok "Cleared $dir ($SIZE freed)"
    fi
done

# 1.8 Rebuild broken symlinks
log_info "Rebuilding broken Termux symlinks..."
find "$HOME/../usr/bin" -xtype l -delete 2>/dev/null
log_ok "Broken symlinks removed"

# 1.9 Fix top command (corrected flags)
log_info "Testing corrected top command..."
top -n 1 -b 2>/dev/null | head -15 || top -n 1 2>/dev/null | head -10
log_ok "top command working correctly (use: top -n 1 -b)"

# 1.10 Android external storage clean
log_info "Clearing accessible Android cache dirs..."
local ANDROID_CACHE=(
    "/storage/emulated/0/Android/data/com.twitter.android/cache"
    "/storage/emulated/0/Android/data/com.whatsapp/cache"
    "/storage/emulated/0/DCIM/.thumbnails"
    "/storage/emulated/0/.thumbnails"
    "/storage/emulated/0/Android/obb"
)
for dir in "${ANDROID_CACHE[@]}"; do
    if [ -d "$dir" ]; then
        rm -rf "$dir"/* 2>/dev/null && log_ok "Cleared: $dir" || log_warn "Permission denied: $dir (normal on Android 11+)"
    fi
done

# 1.11 Temp files
log_info "Removing Termux tmp files..."
rm -rf /tmp/* "$HOME/../usr/tmp/"* 2>/dev/null
log_ok "Temp files cleared"

}

════════════════════════════════════════════════════════════

TIER 2 — ADB OVER Wi-Fi (Developer Options)

════════════════════════════════════════════════════════════

tier2_adb_clean() {

log_step "2" "TIER 2 — ADB WIRELESS DEEP SYSTEM CLEAN"

if ! $HAS_ADB; then
    log_info "Installing ADB for Termux..."
    pkg install -y android-tools &>/dev/null && HAS_ADB=true && log_ok "ADB installed" || {
        log_err "ADB install failed — skipping Tier 2"
        log_warn "To enable: pkg install android-tools"
        return
    }
fi

# Attempt ADB connection
log_info "Attempting ADB local connection (127.0.0.1:5555)..."
adb connect 127.0.0.1:5555 2>/dev/null
sleep 2

if adb devices 2>/dev/null | grep -q "device$"; then
    log_ok "ADB connected — running privileged commands"

    # Fix pm transaction error via ADB
    log_info "Clearing Twitter cache via ADB..."
    adb shell pm clear com.twitter.android 2>/dev/null   && log_ok "Twitter cache cleared" || log_warn "pm clear failed (app may not exist)"

    log_info "Trimming all app caches (999 GB limit)..."
    adb shell pm trim-caches 999G 2>/dev/null             && log_ok "pm trim-caches executed" || log_warn "trim-caches unavailable"

    log_info "Granting Twitter storage permissions..."
    adb shell pm grant com.twitter.android android.permission.READ_EXTERNAL_STORAGE  2>/dev/null && log_ok "READ_EXTERNAL_STORAGE granted"
    adb shell pm grant com.twitter.android android.permission.WRITE_EXTERNAL_STORAGE 2>/dev/null && log_ok "WRITE_EXTERNAL_STORAGE granted"

    log_info "Compiling Twitter with speed profile..."
    adb shell cmd package compile -m speed-profile -f com.twitter.android 2>/dev/null && log_ok "ART compilation done" || log_warn "ART compile requires Android shell identity"

    log_info "Clearing system temp via ADB..."
    adb shell rm -rf /data/local/tmp/* 2>/dev/null        && log_ok "ADB tmp cleared" || log_warn "Skipped"

    log_info "Killing Twitter process to apply changes..."
    adb shell am force-stop com.twitter.android 2>/dev/null && log_ok "Twitter process killed"

    log_info "Clearing WebView cache..."
    adb shell rm -rf /data/data/com.android.webview/cache/ 2>/dev/null
    log_ok "WebView cache cleared"

else
    log_warn "ADB not connected — Tier 2 skipped"
    echo ""
    echo -e "  ${YELLOW}╔═══════════════════════════════════════════════════╗${RESET}"
    echo -e "  ${YELLOW}║  HOW TO ENABLE ADB WIRELESS FOR FULL POWER        ║${RESET}"
    echo -e "  ${YELLOW}╠═══════════════════════════════════════════════════╣${RESET}"
    echo -e "  ${CYAN}║  1. Settings → About Phone → tap Build Number x7  ║${RESET}"
    echo -e "  ${CYAN}║  2. Settings → Developer Options → ON              ║${RESET}"
    echo -e "  ${CYAN}║  3. Enable: USB Debugging + Wireless Debugging     ║${RESET}"
    echo -e "  ${CYAN}║  4. Wireless Debug → Pair device → note PORT+CODE  ║${RESET}"
    echo -e "  ${CYAN}║  5. In Termux: adb pair 127.0.0.1:<PORT>           ║${RESET}"
    echo -e "  ${CYAN}║     Enter pairing code when prompted               ║${RESET}"
    echo -e "  ${CYAN}║  6. Then: adb connect 127.0.0.1:5555               ║${RESET}"
    echo -e "  ${CYAN}║  7. Re-run this script for Tier 2 power            ║${RESET}"
    echo -e "  ${YELLOW}╚═══════════════════════════════════════════════════╝${RESET}"
fi

}

════════════════════════════════════════════════════════════

TIER 3 — ROOT MODE (Full System Access)

════════════════════════════════════════════════════════════

tier3_root_clean() {

log_step "3" "TIER 3 — ROOT FORCE-CLEAN (Superuser Mode)"

if ! $HAS_ROOT; then
    log_warn "Device not rooted — Tier 3 skipped"
    echo -e "  ${CYAN}[•]${RESET} Root = full /data/data access, Dalvik cache wipe, system reset"
    return
fi

log_ok "Running as ROOT — maximum force mode engaged"

# Dalvik / ART cache wipe
log_info "Wiping Dalvik/ART cache (forces recompile)..."
su -c "rm -rf /data/dalvik-cache/*" && log_ok "Dalvik cache wiped" || log_err "Dalvik wipe failed"

# Twitter full data clear
log_info "Force-clearing Twitter app data..."
su -c "rm -rf /data/data/com.twitter.android/cache/*"
su -c "rm -rf /data/data/com.twitter.android/files/*"
su -c "rm -rf /data/data/com.twitter.android/shared_prefs/*.xml 2>/dev/null" 
log_ok "Twitter app data cleared"

# Temp and logs
log_info "Clearing system temp and logs..."
su -c "rm -rf /data/local/tmp/*"
su -c "find /data/anr -type f -delete 2>/dev/null"
su -c "find /data/tombstones -type f -delete 2>/dev/null"
log_ok "System temp, ANR logs, tombstones cleared"

# System cache partition
log_info "Wiping system cache partition..."
su -c "find /cache -mindepth 1 -delete 2>/dev/null" && log_ok "Cache partition wiped" || log_warn "Cache partition not accessible"

# Fix package manager state
log_info "Rebuilding package manager state..."
su -c "pm compile -a -m speed-profile -f" 2>/dev/null && log_ok "All apps recompiled" || log_warn "Mass recompile skipped"

}

════════════════════════════════════════════════════════════

STAGE 4 — TERMUX ENVIRONMENT HARDENING

════════════════════════════════════════════════════════════

stage4_harden() {

log_step "4" "TERMUX ENVIRONMENT HARDENING & REPAIR"

# Reinstall core essentials
log_info "Reinstalling core Termux utilities..."
pkg install -y --reinstall termux-tools coreutils findutils grep sed gawk &>/dev/null
log_ok "Core utilities reinstalled"

# SSH authorized_keys security fix (from previous forensic finding)
log_info "Auditing SSH authorized_keys for unauthorized entries..."
local AUTHKEYS="$HOME/.ssh/authorized_keys"
if [ -f "$AUTHKEYS" ]; then
    local COUNT
    COUNT=$(wc -l < "$AUTHKEYS")
    log_warn "authorized_keys has $COUNT entries — review manually:"
    cat "$AUTHKEYS"
    echo ""
    read -rp "  [?] Clear all unauthorized SSH keys? (y/N): " CLEAR_KEYS
    if [[ "$CLEAR_KEYS" =~ ^[Yy]$ ]]; then
        cp "$AUTHKEYS" "${AUTHKEYS}.backup.$(date +%s)"
        > "$AUTHKEYS"
        chmod 600 "$AUTHKEYS"
        log_ok "Unauthorized keys cleared (backup saved)"
    fi
else
    log_ok "No authorized_keys file found — SSH access clean"
fi

# Fix locale
log_info "Fixing locale settings..."
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
echo 'export LANG=en_US.UTF-8' >> "$HOME/.bashrc" 2>/dev/null
echo 'export LC_ALL=en_US.UTF-8' >> "$HOME/.bashrc" 2>/dev/null
log_ok "Locale set to en_US.UTF-8"

# Storage permission
log_info "Re-requesting Termux storage permission..."
termux-setup-storage 2>/dev/null && log_ok "Storage permission requested" || log_warn "Run: termux-setup-storage manually"

}

════════════════════════════════════════════════════════════

STAGE 5 — SYSTEM HEALTH REPORT

════════════════════════════════════════════════════════════

stage5_report() {

log_step "5" "POST-CLEAN SYSTEM HEALTH REPORT"

echo ""
echo -e "  ${BOLD}${CYAN}══════════ SYSTEM STATUS ══════════${RESET}"

# Storage
echo -e "\n  ${YELLOW} Storage:${RESET}"
df -h /storage/emulated/0 2>/dev/null || df -h "$HOME"

# Memory
echo -e "\n  ${YELLOW} Memory (RAM):${RESET}"
if [ -f /proc/meminfo ]; then
    awk '/MemTotal|MemFree|MemAvailable/ {printf "  %-18s %s %s\n",$1,$2,$3}' /proc/meminfo
fi

# CPU (fixed command)
echo -e "\n  ${YELLOW}⚡ Top Processes:${RESET}"
top -n 1 -b 2>/dev/null | head -15 || ps aux 2>/dev/null | head -10

# Termux package count
echo -e "\n  ${YELLOW} Installed Packages:${RESET}"
dpkg --list 2>/dev/null | grep -c "^ii" | xargs -I{} echo "  {} packages installed"

# Network
echo -e "\n  ${YELLOW} Network:${RESET}"
ip addr show 2>/dev/null | grep "inet " | awk '{print "  " $2}' || ifconfig 2>/dev/null | grep "inet "

echo ""
echo -e "  ${GREEN}${BOLD}════════════════════════════════════${RESET}"
echo -e "  ${GREEN}✔  WARRIOR CLEANUP COMPLETE${RESET}"
echo -e "  ${GREEN}════════════════════════════════════${RESET}"
echo ""
echo -e "  ${CYAN}Timestamp : $(date '+%Y-%m-%d %H:%M:%S %Z')${RESET}"
echo -e "  ${CYAN}Hostname  : $(uname -n)${RESET}"
echo -e "  ${CYAN}Kernel    : $(uname -r)${RESET}"
echo ""

}

════════════════════════════════════════════════════════════

MAIN EXECUTION

════════════════════════════════════════════════════════════

main() {

clear
banner

echo -e "  ${BOLD}Starting Warrior Android Force-Reset Toolkit...${RESET}"
echo -e "  ${YELLOW}This will clean, repair, and update your entire environment.${RESET}\n"
read -rp "  Press ENTER to begin, or Ctrl+C to cancel... " _

check_deps
tier1_termux_cleanup
tier2_adb_clean
tier3_root_clean
stage4_harden
stage5_report

}

main "$@"

More Posts

Tech is stressful, join my free Insight Timer meditations to reset & recharge.

yogirahul - Sep 28, 2025

Argophor: A Developer-Friendly Linux App Detection & Installation Toolkit

Muhammed Shafin P - Feb 7

Building a P2P LAN Chat & File Sharing System with FastAPI

Muhammed Shafin P - Jan 23

AI-Native GUI SDK: Performance & Models Are NOT Defined Here

Muhammed Shafin P - Dec 20, 2025

Understanding Qeltrix V1 PoC Performance: Context & Limitations

Muhammed Shafin P - Dec 1, 2025
chevron_left

Related Jobs

View all jobs →

Commenters (This Week)

16 comments
2 comments

Contribute meaningful comments to climb the leaderboard and earn badges!