Skip to content

Instantly share code, notes, and snippets.

@bunkbail
Last active February 1, 2024 17:55
Show Gist options
  • Select an option

  • Save bunkbail/d87268cc730c52eb1fb6a2a4dbe95a10 to your computer and use it in GitHub Desktop.

Select an option

Save bunkbail/d87268cc730c52eb1fb6a2a4dbe95a10 to your computer and use it in GitHub Desktop.
Pull everything from your android internal storage (default folder: /storage/emulated/0)
#!/bin/bash
cleanup() {
echo "Cleaning up..."
kill -TERM "$ADB_PULL_PID" # Send SIGTERM to adb pull
wait "$ADB_PULL_PID" # Wait for adb pull to exit
rm -rf "${OUTPUT_DIR}"
exit 1
}
trap cleanup SIGINT
OUTPUT_DIR=./output
mkdir -p "${OUTPUT_DIR}"
ROOT_DIR="/storage/emulated/0"
echo "### Pulling directory: ${ROOT_DIR}"
# Use 'adb pull' directly for binary files
adb pull "${ROOT_DIR}" "${OUTPUT_DIR}" &
ADB_PULL_PID=$! # Capture the PID of adb pull
# Monitor progress
while kill -0 "$ADB_PULL_PID" 2>/dev/null; do
DOWNLOADED_SIZE=$(du -s "${OUTPUT_DIR}" 2>/dev/null | awk '{print $1}')
TOTAL_SIZE=$(adb shell "du -s '${ROOT_DIR}' 2>/dev/null | awk '{print \$1}'" | tr -d ' ')
# Handle the case where TOTAL_SIZE is not yet known
if [ -z "$TOTAL_SIZE" ]; then
PROGRESS=0
else
PROGRESS=$((DOWNLOADED_SIZE * 100 / TOTAL_SIZE))
fi
# Print progress bar
printf "\rProgress: [%-50s] %d%%" $(printf '#%.0s' $(seq 1 $((PROGRESS / 2)))) "$PROGRESS"
sleep 1
done
# Move to the next line after the progress bar is complete
echo
echo "Download complete!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment