style: convert remaining tabs to spaces in root_bl9000.sh

This commit is contained in:
Krzysztof kuhy Rudnicki 2025-11-16 20:59:56 +01:00
parent 53bd0fd60a
commit 4256df1d15

View File

@ -40,7 +40,7 @@ log() {
local msg="$1"
echo -e "${GREEN}[$(timestamp)]${NC} $msg"
if [[ -w "$(dirname "$LOG_FILE")" ]] || [[ ! -e $LOG_FILE && -w /var/log ]]; then
echo "[$(timestamp)] $msg" >>"$LOG_FILE" 2>&1 || true
echo "[$(timestamp)] $msg" >> "$LOG_FILE" 2>&1 || true
fi
}
@ -48,7 +48,7 @@ warn() {
local msg="$1"
echo -e "${YELLOW}[WARN]${NC} $msg" >&2
if [[ -w "$(dirname "$LOG_FILE")" ]] || [[ ! -e $LOG_FILE && -w /var/log ]]; then
echo "[$(timestamp)] [WARN] $msg" >>"$LOG_FILE" 2>&1 || true
echo "[$(timestamp)] [WARN] $msg" >> "$LOG_FILE" 2>&1 || true
fi
}
@ -56,7 +56,7 @@ error() {
local msg="$1"
echo -e "${RED}[ERROR]${NC} $msg" >&2
if [[ -w "$(dirname "$LOG_FILE")" ]] || [[ ! -e $LOG_FILE && -w /var/log ]]; then
echo "[$(timestamp)] [ERROR] $msg" >>"$LOG_FILE" 2>&1 || true
echo "[$(timestamp)] [ERROR] $msg" >> "$LOG_FILE" 2>&1 || true
fi
}
@ -90,7 +90,7 @@ require_non_root() {
}
usage() {
cat <<EOF
cat << EOF
Usage: $SCRIPT_NAME [OPTIONS] [COMMAND]
Root BL9000 phone from Arch Linux using Magisk.
@ -130,33 +130,33 @@ install_dependencies() {
local missing=()
# Check for required commands
if ! command -v adb >/dev/null 2>&1; then
if ! command -v adb > /dev/null 2>&1; then
packages+=("android-tools")
missing+=("adb")
fi
if ! command -v fastboot >/dev/null 2>&1 && ! pacman -Q android-tools >/dev/null 2>&1; then
if ! command -v fastboot > /dev/null 2>&1 && ! pacman -Q android-tools > /dev/null 2>&1; then
packages+=("android-tools")
missing+=("fastboot")
fi
if ! command -v unzip >/dev/null 2>&1; then
if ! command -v unzip > /dev/null 2>&1; then
packages+=("unzip")
missing+=("unzip")
fi
if ! command -v curl >/dev/null 2>&1; then
if ! command -v curl > /dev/null 2>&1; then
packages+=("curl")
missing+=("curl")
fi
if ! command -v python3 >/dev/null 2>&1; then
if ! command -v python3 > /dev/null 2>&1; then
packages+=("python")
missing+=("python3")
fi
# Check for python-protobuf (needed for boot image tools)
if ! python3 -c "import google.protobuf" 2>/dev/null; then
if ! python3 -c "import google.protobuf" 2> /dev/null; then
packages+=("python-protobuf")
missing+=("python-protobuf")
fi
@ -179,11 +179,11 @@ install_dependencies() {
sudo pacman -S --needed --noconfirm "${packages[@]}" || die "Failed to install dependencies"
# Install payload-dumper-go from AUR if not present (for extracting boot.img from payload.bin)
if ! command -v payload-dumper-go >/dev/null 2>&1; then
if ! command -v payload-dumper-go > /dev/null 2>&1; then
if confirm "Install payload-dumper-go from AUR for extracting boot images?"; then
if command -v yay >/dev/null 2>&1; then
if command -v yay > /dev/null 2>&1; then
yay -S --needed --noconfirm payload-dumper-go || warn "Failed to install payload-dumper-go (optional)"
elif command -v paru >/dev/null 2>&1; then
elif command -v paru > /dev/null 2>&1; then
paru -S --needed --noconfirm payload-dumper-go || warn "Failed to install payload-dumper-go (optional)"
else
warn "No AUR helper found. Install payload-dumper-go manually if needed."
@ -212,7 +212,7 @@ setup_udev_rules() {
log "Creating Android udev rules..."
# Create comprehensive udev rules for Android devices
sudo tee "$udev_file" >/dev/null <<'EOF'
sudo tee "$udev_file" > /dev/null << 'EOF'
# Android Debug Bridge (ADB) devices
# Add your device's vendor ID if not listed
@ -225,7 +225,7 @@ SUBSYSTEM=="usb", ATTR{idVendor}=="*", ATTR{idProduct}=="*", MODE="0666", GROUP=
EOF
# Create adbusers group if it doesn't exist
if ! getent group adbusers >/dev/null; then
if ! getent group adbusers > /dev/null; then
sudo groupadd -r adbusers
log "Created adbusers group"
fi
@ -253,7 +253,7 @@ backup_device_data() {
mkdir -p "$backup_dir"
log "Backup directory: $backup_dir" # Check device connection first
if ! adb get-state >/dev/null 2>&1; then
if ! adb get-state > /dev/null 2>&1; then
error "Device not connected. Please connect your device first."
return 1
fi
@ -265,7 +265,7 @@ backup_device_data() {
local storage_dirs=("DCIM" "Pictures" "Documents" "Download" "Music" "Movies" "WhatsApp" "Telegram")
for dir in "${storage_dirs[@]}"; do
if adb shell "[ -d /sdcard/$dir ]" 2>/dev/null; then
if adb shell "[ -d /sdcard/$dir ]" 2> /dev/null; then
log " → Backing up /sdcard/$dir..."
if adb pull "/sdcard/$dir" "$backup_dir/$dir" 2>&1 | grep -v "^$"; then
log "$dir backed up successfully"
@ -277,34 +277,34 @@ backup_device_data() {
# 2. Backup SMS/MMS (if possible)
log "Backing up SMS/MMS database..."
if adb shell "su -c 'cp /data/data/com.android.providers.telephony/databases/mmssms.db /sdcard/mmssms.db'" 2>/dev/null; then
adb pull /sdcard/mmssms.db "$backup_dir/mmssms.db" 2>/dev/null && log " ✓ SMS/MMS backed up"
adb shell "rm /sdcard/mmssms.db" 2>/dev/null || true
if adb shell "su -c 'cp /data/data/com.android.providers.telephony/databases/mmssms.db /sdcard/mmssms.db'" 2> /dev/null; then
adb pull /sdcard/mmssms.db "$backup_dir/mmssms.db" 2> /dev/null && log " ✓ SMS/MMS backed up"
adb shell "rm /sdcard/mmssms.db" 2> /dev/null || true
else
warn " ⚠ SMS/MMS backup requires root (skipping)"
fi
# 3. Backup contacts
log "Backing up contacts..."
if adb shell "su -c 'cp /data/data/com.android.providers.contacts/databases/contacts2.db /sdcard/contacts2.db'" 2>/dev/null; then
adb pull /sdcard/contacts2.db "$backup_dir/contacts2.db" 2>/dev/null && log " ✓ Contacts backed up"
adb shell "rm /sdcard/contacts2.db" 2>/dev/null || true
if adb shell "su -c 'cp /data/data/com.android.providers.contacts/databases/contacts2.db /sdcard/contacts2.db'" 2> /dev/null; then
adb pull /sdcard/contacts2.db "$backup_dir/contacts2.db" 2> /dev/null && log " ✓ Contacts backed up"
adb shell "rm /sdcard/contacts2.db" 2> /dev/null || true
else
warn " ⚠ Contacts backup requires root (skipping)"
fi
# 4. Backup call logs
log "Backing up call logs..."
if adb shell "su -c 'cp /data/data/com.android.providers.contacts/databases/calllog.db /sdcard/calllog.db'" 2>/dev/null; then
adb pull /sdcard/calllog.db "$backup_dir/calllog.db" 2>/dev/null && log " ✓ Call logs backed up"
adb shell "rm /sdcard/calllog.db" 2>/dev/null || true
if adb shell "su -c 'cp /data/data/com.android.providers.contacts/databases/calllog.db /sdcard/calllog.db'" 2> /dev/null; then
adb pull /sdcard/calllog.db "$backup_dir/calllog.db" 2> /dev/null && log " ✓ Call logs backed up"
adb shell "rm /sdcard/calllog.db" 2> /dev/null || true
else
warn " ⚠ Call logs backup requires root (skipping)"
fi
# 5. Backup app list
log "Backing up installed apps list..."
adb shell "pm list packages -f" >"$backup_dir/installed_apps.txt"
adb shell "pm list packages -f" > "$backup_dir/installed_apps.txt"
log " ✓ App list saved to installed_apps.txt"
# 6. Backup APKs for user-installed apps (optional, can be large)
@ -324,10 +324,10 @@ backup_device_data() {
local apk_path
apk_path=$(adb shell "pm path $pkg" | head -n1 | sed 's/package://')
if [[ -n $apk_path ]]; then
adb pull "$apk_path" "$apk_dir/${pkg}.apk" >/dev/null 2>&1 && count=$((count + 1))
adb pull "$apk_path" "$apk_dir/${pkg}.apk" > /dev/null 2>&1 && count=$((count + 1))
fi
fi
done <<<"$user_apps"
done <<< "$user_apps"
log " ✓ Backed up $count APK files"
fi
@ -365,13 +365,13 @@ backup_device_data() {
echo
echo "Installed Apps:"
adb shell "pm list packages -3" | sed 's/package:/ - /'
} >"$backup_dir/device_info.txt"
} > "$backup_dir/device_info.txt"
log " ✓ Device info saved"
# Summary
local backup_size
backup_size=$(du -sh "$backup_dir" 2>/dev/null | cut -f1 || echo "unknown")
backup_size=$(du -sh "$backup_dir" 2> /dev/null | cut -f1 || echo "unknown")
echo
echo -e "${GREEN}╔═══════════════════════════════════════════════════════╗${NC}"
@ -408,7 +408,7 @@ check_device() {
print_header "Checking Device Connection"
log "Starting ADB server..."
adb start-server >/dev/null 2>&1 || true
adb start-server > /dev/null 2>&1 || true
log "Waiting for device..."
if ! adb wait-for-device; then
@ -437,11 +437,11 @@ check_device() {
# Check device properties
local model
model=$(adb shell getprop ro.product.model 2>/dev/null | tr -d '\r\n' || echo "Unknown")
model=$(adb shell getprop ro.product.model 2> /dev/null | tr -d '\r\n' || echo "Unknown")
log "Model: $model"
local android_version
android_version=$(adb shell getprop ro.build.version.release 2>/dev/null | tr -d '\r\n' || echo "Unknown")
android_version=$(adb shell getprop ro.build.version.release 2> /dev/null | tr -d '\r\n' || echo "Unknown")
log "Android version: $android_version"
local battery_level
@ -457,7 +457,7 @@ check_device() {
# Check if bootloader is unlocked
local unlock_status
unlock_status=$(adb shell getprop ro.boot.verifiedbootstate 2>/dev/null | tr -d '\r\n' || echo "unknown")
unlock_status=$(adb shell getprop ro.boot.verifiedbootstate 2> /dev/null | tr -d '\r\n' || echo "unknown")
if [[ $unlock_status == "orange" || $unlock_status == "red" ]]; then
log "Bootloader unlock status: ${GREEN}UNLOCKED${NC}"
else
@ -466,7 +466,7 @@ check_device() {
# Check if OEM unlocking is enabled
local oem_unlock
oem_unlock=$(adb shell getprop sys.oem_unlock_allowed 2>/dev/null | tr -d '\r\n' || echo "unknown")
oem_unlock=$(adb shell getprop sys.oem_unlock_allowed 2> /dev/null | tr -d '\r\n' || echo "unknown")
if [[ $oem_unlock == "1" ]]; then
log "OEM unlocking: ${GREEN}ENABLED${NC}"
else
@ -608,11 +608,11 @@ extract_boot_image() {
# Method 1: Try to pull boot partition directly
local boot_partition
boot_partition=$(adb shell "find /dev/block -name boot | head -n1" 2>/dev/null | tr -d '\r\n' || echo "")
boot_partition=$(adb shell "find /dev/block -name boot | head -n1" 2> /dev/null | tr -d '\r\n' || echo "")
if [[ -n $boot_partition ]]; then
log "Found boot partition: $boot_partition"
if adb pull "$boot_partition" "$boot_img" 2>/dev/null; then
if adb pull "$boot_partition" "$boot_img" 2> /dev/null; then
log "Boot image extracted successfully"
BOOT_IMG="$boot_img"
return 0
@ -620,13 +620,13 @@ extract_boot_image() {
fi
# Method 2: Try to get boot partition via by-name
boot_partition=$(adb shell "ls /dev/block/by-name/boot*" 2>/dev/null | head -n1 | tr -d '\r\n' || echo "")
boot_partition=$(adb shell "ls /dev/block/by-name/boot*" 2> /dev/null | head -n1 | tr -d '\r\n' || echo "")
if [[ -n $boot_partition ]]; then
log "Found boot partition: $boot_partition"
if adb shell "su -c 'dd if=$boot_partition of=/sdcard/boot.img'" 2>/dev/null &&
adb pull /sdcard/boot.img "$boot_img" 2>/dev/null; then
adb shell rm /sdcard/boot.img 2>/dev/null || true
if adb shell "su -c 'dd if=$boot_partition of=/sdcard/boot.img'" 2> /dev/null &&
adb pull /sdcard/boot.img "$boot_img" 2> /dev/null; then
adb shell rm /sdcard/boot.img 2> /dev/null || true
log "Boot image extracted successfully"
BOOT_IMG="$boot_img"
return 0
@ -659,7 +659,7 @@ patch_boot_with_magisk() {
fi
log "Installing Magisk APK on device..."
if ! adb install -r "$magisk_apk" 2>/dev/null; then
if ! adb install -r "$magisk_apk" 2> /dev/null; then
error "Failed to install Magisk APK"
return 1
fi