Last active
December 14, 2025 17:49
-
-
Save watson0x90/3f3b3ea8b40b8f6fa8e5c07cc087615e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # ---------------------------------------------------- | |
| # SNIPER ELITE: HARDENED LOOP (State Aware) | |
| # ---------------------------------------------------- | |
| # TARGET CONFIGURATION | |
| TARGET_VID="0634" | |
| TARGET_PID="5603" | |
| # RECOVERY FILES | |
| IMG_FILE="/mnt/recovery_drive/sniper.img" | |
| MAP_FILE="/mnt/recovery_drive/sniper.map" | |
| # 1. GLOBAL SETTINGS | |
| echo -1 | sudo tee /sys/module/usbcore/parameters/autosuspend >/dev/null | |
| echo "----------------------------------------------------" | |
| echo "[*] PASSIVE LISTENER ACTIVE (HARDENED)" | |
| echo "[*] Waiting for Kasa Plug to cycle power..." | |
| echo "----------------------------------------------------" | |
| # 2. PERSISTENT MONITORING | |
| inotifywait -m -e create --format '%f' /dev | while read NEW_DRIVE; do | |
| # Filter for sd* devices (sdc, sdd, sde...) | |
| if [[ "$NEW_DRIVE" =~ ^sd[c-z]$ ]]; then | |
| echo "[?] Event detected: $NEW_DRIVE. Verifying stability..." | |
| # SAFETY 1: THE SETTLE PAUSE | |
| # Give the kernel/udev 3 seconds to fully register the device attributes. | |
| # This prevents "race conditions" where we check the ID too fast. | |
| sleep 3 | |
| # SAFETY 2: THE STALE CHECK | |
| # If this event was buffered while we were busy, the drive might already be gone. | |
| # If the file /dev/sdX doesn't exist, skip it immediately. | |
| if [ ! -b "/dev/$NEW_DRIVE" ]; then | |
| echo "[!] Skipping Stale/Ghost Event: /dev/$NEW_DRIVE is effectively gone." | |
| continue | |
| fi | |
| # Verify it is the Crucial Drive | |
| IS_TARGET=$(udevadm info -a -n /dev/$NEW_DRIVE 2>/dev/null | grep "$TARGET_VID") | |
| if [ ! -z "$IS_TARGET" ]; then | |
| echo "------------------------------------------------" | |
| echo "[!] HARDWARE EVENT: Drive $NEW_DRIVE Confirmed & Stable" | |
| # A. APPLY PERFORMANCE PATCHES | |
| echo 180 | sudo tee /sys/block/$NEW_DRIVE/device/timeout >/dev/null 2>&1 | |
| echo 256 | sudo tee /sys/block/$NEW_DRIVE/queue/max_sectors_kb >/dev/null 2>&1 | |
| # Force Power On | |
| find /sys/block/$NEW_DRIVE/device/../../ -name "control" | grep "power/control" | while read config; do | |
| echo "on" | sudo tee $config >/dev/null 2>&1 | |
| done | |
| # B. RUN RESCUE | |
| # Using standard Forward mode with the mapfile (No Input Position needed) | |
| echo "[!] Starting Recovery Run..." | |
| sudo timeout -s INT 100s ddrescue -n -d -r 0 -c 64 /dev/$NEW_DRIVE "$IMG_FILE" "$MAP_FILE" | |
| EXIT_STATUS=$? | |
| if [ $EXIT_STATUS -eq 0 ]; then | |
| echo "------------------------------------------------" | |
| echo "🎉 VICTORY: Recovery Complete! (Exit Code 0)" | |
| echo "------------------------------------------------" | |
| exit 0 | |
| fi | |
| echo "[!] Run finished. Mapfile updated." | |
| echo "[*] Loop active. Waiting for next hardware event..." | |
| else | |
| echo "[X] Ignored: $NEW_DRIVE is not the target (Vendor Mismatch)." | |
| fi | |
| fi | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment