Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- NC='\033[31;0m'
- RED='\033[0;31;1m'
- PUR='\033[0;35;1m'
- YEL='\033[0;33;1m'
- GRA='\033[0;37;1m'
- if [ "$(id -u)" != "0" ]; then
- printf "\n\n${RED}== /!\ DO NOT USE ROOT! /!\ ==\n\n\${NC}" 2>&1
- exit 1
- fi
- ## DS4 Check Script
- ## Sony DualShock 4 controller script for Linux
- ##
- ## /!\ THIS SCRIPT IS EXPERIMENTAL AND MAY REQUIRE TWEAKING TO GET THE RESULT YOU WANT /!\
- ##
- ## make sure you have ds4drv and xboxdrv installed on your system in order to use this.
- ## this script is to attempt to detect DualShock 4 controller when plugged into the system
- ## and automatically apply a config in ds4drv.conf, you can change LED bar color to any defined in the conf
- ## there are RGB color limitations to the LightBar on the DS4.
- ##
- ## List of tested valid LED colors for DualShock 4 written by me:
- ## - https://github.com/chrippa/ds4drv/wiki/Light-Bar-Colors
- ##
- ## first it'll attempt to lock the ds4drv to its own PID so there is only 1 instance running at all times.
- ## if a PID file already exists it will exit, otherwise it'll create and lock to one. Check your $HOME/.cache
- ## directory for the log file labeled ds4drv.log. A secondary log may be contained within systems own Syslog
- ## detailing hidraw and udev events.
- ##
- ## if controller gets disconnected, it should hopefully unlock the PID file and remove it.
- ## if you do not have a ds4drv.conf you can get a template from here:
- ## https://github.com/chrippa/ds4drv/blob/master/ds4drv.conf
- pidfile=/tmp/ds4drv.pid
- # check if process is already running
- for pid in $(pidof -x $HOME/scripts/ds4check.sh $pidfile); do
- if [ $pid != $$ ]; then
- echo "[$(date "+%Y-%m-%d - %I:%M:%S %p")] : ds4check.sh : Process is already running with PID $pid\n" >> $HOME/.cache/ds4drv.log
- printf "\n${PUR}[$(date "+%Y-%m-%d - %I:%M:%S %p")]${NC} : ds4check.sh : ${RED}Process is already running with PID $pid\n\n${NC}" 2>&1
- exit 1
- # if not running then run and apply config
- else ( ds4drv --hidraw --config $HOME/.config/ds4drv.conf & disown );
- exit 0
- fi
- done
- ## === /!\/!\ DO NOT RUN AS ROOT /!\/!\ ===
- ## if you are having permission issues running this, you will need to create a udev rule for normal users.
- ## read here on how to create udev rule: https://github.com/chrippa/ds4drv
- ## just ignore this stuff below, it wasn't working out so well, but I may fix it eventually.
- ##
- # remove PID file on exit... hopefully
- #if ( set -o noclobber; echo "locked" > "$pidfile") 2> /dev/null; then
- # trap 'rm -f "$pidfile"; exit $?' INT TERM EXIT
- # echo "Locking succeeded" 2> $HOME/.cache/ds4drv.log;
- # rm -f "$pidfile"
- #else
- # echo "Lock failed - exit" 2> $HOME/.cache/ds4drv.log;
- # exit 1
- #fi
- #trap "srm -rv -- '$pidfile'" EXIT >> $HOME/.cache/ds4drv.log
- echo " "
- echo "DualShock 4 Check Script"
- echo " "
Add Comment
Please, Sign In to add comment