Created
June 17, 2023 01:25
-
-
Save Jimbolino/c78b42d392d41107f0b08cf5fff8bc77 to your computer and use it in GitHub Desktop.
Copy my DualShock PlayStation 4 controller Bluetooth key from Linux to Windows, so it keeps paired when i dual boot :)
This file contains 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 | |
set -e | |
input_pattern="/var/lib/bluetooth/*/*/info" | |
output_folder="/mnt/data/ubuntu/" | |
for file in ${input_pattern}; do | |
content=$(cat "${file}") | |
name=$(grep -oP '(?<=Name=).*' <<< "${content}") | |
name="${name// /_}" | |
key=$(grep -oP '(?<=Key=).*' <<< "${content}") | |
key=$(echo -n "${key}" | sed 's/\([0-9A-F]\{2\}\)/\L\1,/g' | sed 's/,$//' || true) | |
device=$(basename "$(dirname "${file}")") | |
device=$(tr -d ':' <<< "${device,,}") | |
controller=$(basename "$(dirname "$(dirname "${file}")")") | |
controller=$(tr -d ':' <<< "${controller,,}") | |
filename="${output_folder}${name}_${controller}_${device}.reg" | |
cat > "${filename}" <<EOL | |
Windows Registry Editor Version 5.00 | |
[HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\BTHPORT\\Parameters\\Keys\\${controller}] | |
"${device}"=hex:${key} | |
EOL | |
echo "---" | |
echo "--- File: ${filename}" | |
echo "---" | |
cat "${filename}" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment