Created
June 9, 2023 15:28
-
-
Save althafvly/be22422aeb5d04b898ed51469451b818 to your computer and use it in GitHub Desktop.
Script to enable USB 2.0 compatibility mode for POCO F1 and other xiaomi phones in fastboot mode
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 | |
# | |
# Script to install or uninstall USB 2.0 compatibility mode for Xiaomi devices | |
# | |
# Usage: ./script.sh [install|uninstall] | |
# | |
# Function to install the USB 2.0 compatibility mode | |
install_usb_compatibility() { | |
# Read USB details from lsusb | |
usb_details=$(lsusb | grep "Xiaomi") | |
# Check if lsusb output contains Xiaomi device information | |
if [[ -n "$usb_details" ]]; then | |
# Extract vendor ID and product ID | |
vendor_id=$(echo "$usb_details" | awk '{print $6}' | cut -d ':' -f 1) | |
product_id=$(echo "$usb_details" | awk '{print $6}' | cut -d ':' -f 2) | |
# Define the content with a comment | |
content="# USB 2.0 compatibility mode for Xiaomi device" | |
content+="\noptions usbcore quirks=0x$vendor_id:0x$product_id:0x20000000" | |
# Define the file path | |
conf_file="/etc/modprobe.d/usb-quirks.conf" | |
# Check if the conf file exists and has the same content | |
if [[ -f "$conf_file" ]] && grep -Fxqf <(echo -e "$content") "$conf_file"; then | |
echo "USB 2.0 compatibility mode is already enabled for Xiaomi device." | |
exit 0 | |
fi | |
# Append the USB device configuration line to the file | |
echo -e "$content" | sudo tee -a "$conf_file" >/dev/null | |
sudo update-initramfs -u | |
echo "USB 2.0 compatibility mode enabled for Xiaomi device." | |
echo "Please reboot your computer for the changes to take effect." | |
else | |
echo "No Xiaomi device found in lsusb output. Exiting." | |
echo "Install the latest Android Platform Tools if not already installed." | |
fi | |
} | |
# Function to uninstall the USB 2.0 compatibility mode | |
uninstall_usb_compatibility() { | |
# Define the file path | |
conf_file="/etc/modprobe.d/usb-quirks.conf" | |
# Check if the conf file exists and remove the comment and the line below it | |
if [[ -f "$conf_file" ]]; then | |
sudo sed -i '/^# USB 2.0 compatibility mode for Xiaomi device$/,/^options usbcore quirks=.*$/d' "$conf_file" | |
sudo update-initramfs -u | |
echo "USB 2.0 compatibility mode disabled for Xiaomi device." | |
echo "Please reboot your computer for the changes to take effect." | |
else | |
echo "USB 2.0 compatibility mode is not enabled for Xiaomi device." | |
fi | |
} | |
# Check if any arguments were passed | |
if [[ $# -eq 0 ]]; then | |
echo "Usage: $0 [install|uninstall]" | |
exit 1 | |
fi | |
# Process the arguments | |
case $1 in | |
install) | |
install_usb_compatibility | |
;; | |
uninstall) | |
uninstall_usb_compatibility | |
;; | |
*) | |
echo "Invalid argument. Usage: $0 [install|uninstall]" | |
exit 1 | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment