Advertisement
Guest User

Untitled

a guest
Mar 10th, 2024
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.89 KB | None | 0 0
  1. #!/bin/bash
  2. #Steam Deck Auto Disable Steam Controller by scawp
  3. #License: DBAD: https://github.com/scawp/Steam-Deck.Auto-Disable-Steam-Controller/blob/main/LICENSE.md
  4. #Source: https://github.com/scawp/Steam-Deck.Auto-Disable-Steam-Controller
  5. # Use at own Risk!
  6.  
  7. set -e
  8.  
  9. script_install_dir="/home/deck/.local/share/scawp/SDADSC"
  10. conf_dir="$script_install_dir/conf"
  11. tmp_dir="/tmp/scawp/SDADSC"
  12.  
  13. mkdir -p "$tmp_dir" "$conf_dir"
  14.  
  15. debug=0
  16. action="$1"
  17. device_name=$(sed 's/[.[\*^$]/_/g' <<<"$2")
  18.  
  19. if [ "$3" = "3/28de/11ff/1" ] || [ "$3" = "3/28de/1205/111" ]; then
  20.   #Steam converts all inputs to virtual 360 pads with id 3/28de/11ff/1 (I hope!) and its own inputs have id 3/28de/1205/111, ignore.
  21.   [ "$debug" = 1 ] && echo "$(date +'%F %T') - $1 - $2 ($device_name) - $3 --- IGNORING" >> "$script_install_dir/debug.log"
  22.   exit 0
  23. else
  24.   [ "$debug" = 1 ] && echo "$(date +'%F %T') - $1 - $2 ($device_name) - $3" >> "$script_install_dir/debug.log"
  25. fi
  26.  
  27. if [ ! -f "$conf_dir/disabled" ]; then
  28.   if [ "$action" = "disable" ] && grep -q "^$device_name$" "$conf_dir/simple_device_list.txt"; then
  29.     if [ ! -f "$tmp_dir/controller_id.txt" ]; then
  30.       echo "$(date +'%F %T') - Disabling internal controller because '$device_name' was connected." >> "$script_install_dir/action.log"
  31.       echo "3-3:1.0" > /sys/bus/usb/drivers/usbhid/unbind
  32.       echo "3-3:1.1" > /sys/bus/usb/drivers/usbhid/unbind
  33.       echo "3-3:1.2" > /sys/bus/usb/drivers/usbhid/unbind
  34.     else
  35.       echo "$(date +'%F %T') - '$device_name' was connected but internal controller is already disabled. Adding to wait list." >> "$script_install_dir/action.log"
  36.     fi
  37.     echo "$device_name" >> "$tmp_dir/controller_id.txt"
  38.  
  39.   elif [ "$action" = "enable" ] && [ -f "$tmp_dir/controller_id.txt" ] && grep -qi "^$device_name$" "$tmp_dir/controller_id.txt"; then
  40.     sed -i "0,/^$device_name$/{//d}" "$tmp_dir/controller_id.txt"
  41.  
  42.     if [ ! -s "$tmp_dir/controller_id.txt" ]; then
  43.       echo "$(date +'%F %T') - Enabling internal controller because '$device_name' was disconnected." >> "$script_install_dir/action.log"
  44.       rm "$tmp_dir/controller_id.txt"
  45.       echo "3-3:1.0" > /sys/bus/usb/drivers/usbhid/bind
  46.       echo "3-3:1.1" > /sys/bus/usb/drivers/usbhid/bind
  47.       echo "3-3:1.2" > /sys/bus/usb/drivers/usbhid/bind
  48.     else
  49.       echo "$(date +'%F %T') - '$device_name' was disconnected but internal controller is kept disabled because other controllers are still connected. Removing from wait list." >> "$script_install_dir/action.log"
  50.     fi
  51.   elif [ "$action" = "enable" ] && ! grep -q "^#\\?$device_name$" "$conf_dir/simple_device_list.txt"; then
  52.     echo "#$device_name" >> "$conf_dir/simple_device_list.txt"
  53.     echo "$(date +'%F %T') - '$device_name' was connected for the first time and added to '$conf_dir/simple_device_list.txt'. Remove the prefixed '#' to enable the script for it." >> "$script_install_dir/action.log"
  54.   fi
  55. fi
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement