chore: rooting bl9000 with etc hosts

This commit is contained in:
Krzysztof kuhy Rudnicki 2025-11-17 11:14:38 +01:00
parent dfe079c219
commit bd0d87b276
3 changed files with 1274 additions and 644 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,217 @@
#!/bin/bash
set -euo pipefail
# Re-run with sudo if needed for reading /etc/hosts
if [[ $EUID -ne 0 ]] && [[ ! -r /etc/hosts ]]; then
exec sudo -E bash "$0" "$@"
fi
WORK_DIR="${HOME}/.cache/android-adblock"
mkdir -p "$WORK_DIR"
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m'
log() {
echo -e "${GREEN}[$(date '+%Y-%m-%d %H:%M:%S%z')]${NC} $*"
}
error() {
echo -e "${RED}[ERROR]${NC} $*" >&2
}
warn() {
echo -e "${YELLOW}[WARN]${NC} $*"
}
die() {
error "$@"
exit 1
}
print_header() {
echo
echo "========================================"
echo " $1"
echo "========================================"
echo
}
check_device() {
log "Checking device connection..."
if ! adb devices | grep -q "device$"; then
die "No device connected. Enable USB debugging and connect your phone."
fi
log "Device connected"
}
check_root() {
log "Checking root access..."
if ! adb shell "su -c 'echo test'" 2>/dev/null | grep -q "test"; then
die "Root access not available. Make sure Magisk is installed and grant root to Shell."
fi
log "Root access confirmed"
}
install_adaway() {
print_header "Installing AdAway"
local adaway_apk="$WORK_DIR/adaway.apk"
local adaway_url="https://github.com/AdAway/AdAway/releases/latest/download/AdAway.apk"
if [[ ! -f $adaway_apk ]]; then
log "Downloading AdAway APK..."
curl -L -o "$adaway_apk" "$adaway_url" || die "Failed to download AdAway"
else
log "AdAway APK already downloaded"
fi
log "Installing AdAway..."
if adb install -r "$adaway_apk" 2>&1 | grep -q "Success"; then
log "AdAway installed successfully"
else
warn "AdAway installation may have failed or already installed"
fi
}
setup_systemless_hosts() {
print_header "Setting up Systemless Hosts"
log "Installing Systemless Hosts module..."
# Create systemless hosts module directory
adb shell "su -c 'mkdir -p /data/adb/modules/systemless_hosts/system/etc'" || die "Failed to create module directory"
# Create module.prop
cat >"$WORK_DIR/module.prop" <<'EOF'
id=systemless_hosts
name=Systemless Hosts
version=1.0
versionCode=1
author=Custom
description=Custom hosts file from StevenBlack with extensions
EOF
adb push "$WORK_DIR/module.prop" /sdcard/module.prop
adb shell "su -c 'cp /sdcard/module.prop /data/adb/modules/systemless_hosts/'" || die "Failed to create module.prop"
adb shell "su -c 'rm /sdcard/module.prop'"
log "Module structure created"
}
push_hosts_file() {
print_header "Pushing Custom Hosts File"
local hosts_file="$WORK_DIR/hosts"
# Use the StevenBlack cache or generate from /etc/hosts
if [[ -f /etc/hosts.stevenblack ]]; then
log "Using StevenBlack hosts cache..."
cp /etc/hosts.stevenblack "$hosts_file"
elif [[ -f /etc/hosts ]]; then
log "Using current /etc/hosts..."
cp /etc/hosts "$hosts_file"
else
die "No hosts file found"
fi
# Show stats
local total_entries
total_entries=$(grep -c "^0\.0\.0\.0 " "$hosts_file" || echo 0)
log "Hosts file contains $total_entries blocked domains"
log "Pushing hosts file to device..."
adb push "$hosts_file" /sdcard/hosts || die "Failed to push hosts file"
log "Installing hosts file systemlessly..."
adb shell "su -c 'cp /sdcard/hosts /data/adb/modules/systemless_hosts/system/etc/hosts'" || die "Failed to install hosts file"
adb shell "su -c 'chmod 644 /data/adb/modules/systemless_hosts/system/etc/hosts'" || die "Failed to set permissions"
adb shell "su -c 'rm /sdcard/hosts'"
log "Hosts file installed successfully"
log "Total blocked domains: $total_entries"
}
enable_module() {
print_header "Enabling Systemless Hosts Module"
log "Removing disable flag if present..."
adb shell "su -c 'rm -f /data/adb/modules/systemless_hosts/disable'" 2>/dev/null || true
adb shell "su -c 'rm -f /data/adb/modules/systemless_hosts/remove'" 2>/dev/null || true
log "Module enabled"
echo
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo " REBOOT REQUIRED"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo
echo "The systemless hosts module requires a reboot to take effect."
echo
read -p "Reboot device now? [y/N]: " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
log "Rebooting device..."
adb reboot
log "Device rebooting. Wait for boot to complete."
else
warn "Remember to reboot manually for changes to take effect!"
fi
}
verify_hosts() {
print_header "Verifying Hosts Installation"
log "Waiting for device to boot..."
sleep 5
adb wait-for-device
sleep 10
log "Checking if hosts file is active..."
local test_domain="doubleclick.net"
local result
result=$(adb shell "su -c 'cat /system/etc/hosts | grep -c $test_domain'" 2>/dev/null || echo "0")
if [[ $result -gt 0 ]]; then
log "✓ Hosts file is active and blocking domains"
else
warn "Could not verify hosts file, but module should be installed"
fi
}
main() {
print_header "Android Ad Blocking Setup"
check_device
check_root
echo "This will:"
echo " 1. Install AdAway app (optional GUI management)"
echo " 2. Create systemless hosts module"
echo " 3. Push your custom hosts file (StevenBlack with extensions)"
echo " 4. Enable the module and reboot"
echo
read -p "Continue? [y/N]: " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
log "Cancelled by user"
exit 0
fi
install_adaway
setup_systemless_hosts
push_hosts_file
enable_module
log "Setup complete!"
log "After reboot, ads should be blocked system-wide"
log "You can manage hosts in the AdAway app or by updating the module"
}
main "$@"

View File

@ -0,0 +1,208 @@
#!/bin/bash
set -euo pipefail
# Re-run with sudo if needed for reading /etc/hosts
if [[ $EUID -ne 0 ]] && [[ ! -r /etc/hosts ]]; then
exec sudo -E bash "$0" "$@"
fi
WORK_DIR="${HOME}/.cache/android-adblock"
mkdir -p "$WORK_DIR"
# Color codes for output
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color
log() {
echo -e "${GREEN}[$(date '+%Y-%m-%d %H:%M:%S%z')]${NC} $*"
}
error() {
echo -e "${RED}[ERROR]${NC} $*" >&2
}
die() {
error "$@"
exit 1
}
log "Updating Android hosts file from Linux configuration..."
# Check device connection
if ! adb devices | grep -q "device$"; then
die "No device connected. Enable USB debugging and connect your phone."
fi
# Check root access
if ! adb shell "su -c 'echo test'" 2>/dev/null | grep -q "test"; then
die "Root access not available. Make sure Magisk is installed and grant root to Shell."
fi
# Use the StevenBlack cache or /etc/hosts
HOSTS_FILE="$WORK_DIR/hosts"
if [[ -f /etc/hosts.stevenblack ]]; then
log "Using StevenBlack hosts cache..."
cp /etc/hosts.stevenblack "$HOSTS_FILE"
elif [[ -f /etc/hosts ]]; then
log "Using /etc/hosts..."
cp /etc/hosts "$HOSTS_FILE"
else
die "No hosts file found"
fi
# Show stats
TOTAL_ENTRIES=$(grep -c "^0\.0\.0\.0 " "$HOSTS_FILE" || echo 0)
log "Hosts file contains $TOTAL_ENTRIES blocked domains"
# Push to device
log "Pushing hosts file to device..."
adb push "$HOSTS_FILE" /sdcard/hosts || die "Failed to push hosts file"
# Install systemlessly
log "Updating systemless hosts..."
adb shell "su -c 'mkdir -p /data/adb/modules/systemless_hosts/system/etc'" || die "Failed to create module directory"
adb shell "su -c 'cp /sdcard/hosts /data/adb/modules/systemless_hosts/system/etc/hosts'" || die "Failed to install hosts file"
adb shell "su -c 'chmod 644 /data/adb/modules/systemless_hosts/system/etc/hosts'" || die "Failed to set permissions"
adb shell "su -c 'rm /sdcard/hosts'"
echo "[$(date +'%Y-%m-%d %H:%M:%S%z')] ✓ Hosts file updated successfully"
# Append custom blocking entries
echo "[$(date +'%Y-%m-%d %H:%M:%S%z')] Adding custom blocking entries..."
adb shell "su -c 'cat >> /data/adb/modules/systemless_hosts/system/etc/hosts << \"CUSTOM_EOF\"
# Custom blocking entries
# YouTube
0.0.0.0 youtube.com
0.0.0.0 www.youtube.com
0.0.0.0 m.youtube.com
0.0.0.0 youtu.be
0.0.0.0 youtube-nocookie.com
0.0.0.0 www.youtube-nocookie.com
0.0.0.0 youtubei.googleapis.com
0.0.0.0 youtube.googleapis.com
0.0.0.0 yt3.ggpht.com
0.0.0.0 ytimg.com
0.0.0.0 i.ytimg.com
0.0.0.0 s.ytimg.com
0.0.0.0 i9.ytimg.com
0.0.0.0 googlevideo.com
0.0.0.0 r1---sn-4g5e6nls.googlevideo.com
0.0.0.0 r1---sn-4g5lne7s.googlevideo.com
# Steam Store
# Discord (selective blocking - media only, voice chat allowed)
0.0.0.0 cdn.discordapp.com
0.0.0.0 media.discordapp.net
0.0.0.0 images-ext-1.discordapp.net
0.0.0.0 images-ext-2.discordapp.net
0.0.0.0 attachments-1.discordapp.net
0.0.0.0 attachments-2.discordapp.net
0.0.0.0 tenor.com
0.0.0.0 giphy.com
# Food Delivery Services
# Polish services
0.0.0.0 pyszne.pl
0.0.0.0 www.pyszne.pl
0.0.0.0 m.pyszne.pl
0.0.0.0 glovo.com
0.0.0.0 www.glovo.com
0.0.0.0 m.glovo.com
0.0.0.0 bolt.eu
0.0.0.0 food.bolt.eu
0.0.0.0 woltwojta.pl
0.0.0.0 www.woltwojta.pl
0.0.0.0 wolt.com
0.0.0.0 www.wolt.com
0.0.0.0 m.wolt.com
# International services
0.0.0.0 ubereats.com
0.0.0.0 www.ubereats.com
0.0.0.0 m.ubereats.com
0.0.0.0 uber.com
0.0.0.0 www.uber.com
0.0.0.0 m.uber.com
0.0.0.0 deliveroo.com
0.0.0.0 www.deliveroo.com
0.0.0.0 m.deliveroo.com
0.0.0.0 deliveroo.co.uk
0.0.0.0 www.deliveroo.co.uk
0.0.0.0 foodpanda.com
0.0.0.0 www.foodpanda.com
0.0.0.0 m.foodpanda.com
0.0.0.0 grubhub.com
0.0.0.0 www.grubhub.com
0.0.0.0 m.grubhub.com
0.0.0.0 doordash.com
0.0.0.0 www.doordash.com
0.0.0.0 m.doordash.com
0.0.0.0 justeat.com
0.0.0.0 www.justeat.com
0.0.0.0 m.justeat.com
0.0.0.0 justeat.co.uk
0.0.0.0 www.justeat.co.uk
0.0.0.0 postmates.com
0.0.0.0 www.postmates.com
0.0.0.0 seamless.com
0.0.0.0 www.seamless.com
0.0.0.0 menulog.com.au
0.0.0.0 www.menulog.com.au
0.0.0.0 delivery.com
0.0.0.0 www.delivery.com
# Fast food chain apps and websites
0.0.0.0 mcdonalds.com
0.0.0.0 www.mcdonalds.com
0.0.0.0 m.mcdonalds.com
0.0.0.0 mcdonalds.pl
0.0.0.0 www.mcdonalds.pl
0.0.0.0 kfc.com
0.0.0.0 www.kfc.com
0.0.0.0 m.kfc.com
0.0.0.0 kfc.pl
0.0.0.0 www.kfc.pl
0.0.0.0 burgerking.com
0.0.0.0 www.burgerking.com
0.0.0.0 m.burgerking.com
0.0.0.0 burgerking.pl
0.0.0.0 www.burgerking.pl
0.0.0.0 pizzahut.com
0.0.0.0 www.pizzahut.com
0.0.0.0 m.pizzahut.com
0.0.0.0 pizzahut.pl
0.0.0.0 www.pizzahut.pl
0.0.0.0 dominos.com
0.0.0.0 www.dominos.com
0.0.0.0 m.dominos.com
0.0.0.0 dominos.pl
0.0.0.0 www.dominos.pl
0.0.0.0 subway.com
0.0.0.0 www.subway.com
0.0.0.0 m.subway.com
0.0.0.0 subway.pl
0.0.0.0 www.subway.pl
CUSTOM_EOF
'" || {
echo "[$(date +'%Y-%m-%d %H:%M:%S%z')] ✗ Failed to add custom entries"
exit 1
}
echo "[$(date +'%Y-%m-%d %H:%M:%S%z')] ✓ Custom entries added successfully"
# Count and display blocked domains
domain_count=$(adb shell "su -c 'cat /system/etc/hosts | grep -c \"^0.0.0.0\"'" 2>/dev/null | tr -d '\r')
if [[ -n $domain_count ]]; then
echo "[$(date +'%Y-%m-%d %H:%M:%S%z')] ✓ Total blocked domains: $domain_count"
fi
echo "[$(date +'%Y-%m-%d %H:%M:%S%z')] ✓ Changes will take effect immediately for new connections"
echo "[$(date +'%Y-%m-%d %H:%M:%S%z')] (Optional: Toggle airplane mode or reboot to force all apps to reconnect)"
log "✓ Total blocked domains: $TOTAL_ENTRIES"
log ""
log "Changes will take effect immediately for new connections."
log "To apply to all apps, reboot the device or toggle airplane mode."