#68392
Naurandir
Guest

Little change to prevent problems with tmp Files, sorry ^^

#!/bin/sh
#First Show USB Devices and Inputs inside dev that user knows what pi recognizes.
echo Initialising Joystick Configuration...
echo Showing all USB-Devices:
sudo lsusb
sleep 6
echo " "
echo " "
echo Showing Devices in dev:
sudo ls /dev/input
echo Joysticks should be shown as js0, js1, js2 and so on.
sleep 6s
echo " "
echo " "
echo Remember your shown Devices for further configuration...
sleep 3s
echo Script will start in 5 Seconds...
sleep 5s

#Create Temp Data
#Tempdata for Platform
platformtemp="/home/pi/platformtjs.tmp"
#Make Sure file is empty
>$platformtemp

#Tempdata for Joystick
joysticktemp="/home/pi/joyconfig.tmp"
#Make Sure file is empty
>$joysticktemp

#Tempdata for player
playertemp="/home/pi/playerconfig.tmp"
#Make Sure file is empty
>$playertemp

dialog --backtitle "Joystick-Configuration" \
--title "Joystick-Configuration" \
--msgbox 'Welcome to Joystick-Configuration' 6 60

dialog --backtitle "Joystick-Configuration" \
--title "Joystick-Configuration" \
--yesno 'Would you like to Configure your Joystick?' 6 60
response=$?
case $response in
   0) starting=1;;
   1) dialog --backtitle "Joystick-Configuration" --title "Configuration Finished" --msgbox 'Joystick-Configuration will now end.' 6 60;;
   255) dialog --backtitle "Joystick-Configuration" --title "Configuration Finished" --msgbox 'Joystick-Configuration will now end.' 6 60;;
esac

#While Loop to configure more than one Player.
while [ "$starting" = "1" ]
do
	#---------Platform-Index------------
	dialog --backtitle "Joystick-Configuration: Platform Selection" \
	--radiolist "Select a Platform to configure (Use SPACEBAR to select and ENTER to confirm):" 18 45 9 \
	all "All" on \
	gb "Game Boy" off \
	gbc "Game Boy Advanced" off \
	nes "Nintendo" off \
	snes "Super Nintendo" off \
	mastersystem "Sega Master System" off \
	megadrive "Sega Mega Drive" off \
	mame "M.A.M.E" off \
	psx "Playstation 1" off 2> $platformtemp
	
	#Platform Type
	platform=$(cat $platformtemp)
	dialog --backtitle "Joystick-Configuration for -${platform}- Platforms: Platform Selection" \
	--title "Selected Platform" \
	--msgbox "Platform -${platform}- was selected." 6 60
	
	#---------Joystick-Index------------
	dialog --backtitle "Joystick-Configuration for -${platform}- Platforms: Joystick-Index Selection" \
	--radiolist "Select Joystick-Number (Use SPACEBAR to select and ENTER to confirm):" 18 45 9 \
	0 "Joystick #0" on \
	1 "Joystick #1" off \
	2 "Joystick #2" off \
	3 "Joystick #3" off \
	4 "Joystick #4" off \
	5 "Joystick #5" off \
	6 "Joystick #6" off \
	7 "Joystick #7" off \
	8 "Joystick #8" off 2> $joysticktemp
	
	#Joystick-Index
	joystickindex=$(cat $joysticktemp)
	dialog --backtitle "Joystick-Configuration for -${platform}- Platforms: Joystick-Index Selection" \
	--title "Selected Joystick" \
	--msgbox "Joystick-Index Number ${joystickindex} was selected." 6 60
	
	#--------Player-Index-------------
	dialog --backtitle "Player-Configuration for -${platform}- Platforms: Player-Number Selection" \
	--radiolist "Select Player-Number (Use SPACEBAR to select and ENTER to confirm):" 18 45 9 \
	1 "Player #1" on \
	2 "Player #2" off \
	3 "Player #3" off \
	4 "Player #4" off \
	5 "Player #5" off \
	6 "Player #6" off \
	7 "Player #7" off \
	8 "Player #8" off 2> $playertemp
	
	#Player-Index
	playerindex=$(cat $playertemp)
	dialog --backtitle "Player-Configuration for -${platform}- Platforms: Player-Number Selection" \
	--title "Selected Player" \
	--msgbox "Player-Number ${playerindex} was selected." 6 60
	
	#---------Start Joypad Configuration Script
	dialog --backtitle "Joystick-Configuration for -${platform}- Platforms: Starting Input" \
	--title "Starting Input Configuration" \
	--msgbox "Configuration of Joystick ${joystickindex} for Player ${playerindex} will start on Platform -${platform}- shortly. Before the Configuration starts it is recommended that all Buttons are used now to calibrate them." 8 60
	
	#Start known Joystick Script with correct Parameters.
	sudo /opt/retropie/emulators/RetroArch/installdir/bin/retroarch-joyconfig -p $playerindex -j $joystickindex > /opt/retropie/configs/${platform}/p${playerindex}.cfg
	#Finished
	dialog --backtitle "Joystick-Configuration for -${platform}- Platforms: Finished Config" \
	--title "Configuration Finished" \
	--msgbox "Configuration of Joystick ${joystickindex} for Player ${playerindex} is finished." 6 60
	
	#Ask if another Player should be configured.
	dialog --backtitle "Joystick-Configuration for -${platform}- Platforms." \
	--title "Joystick-Configuration" \
	--yesno 'Would you like to Configure another Joystick?' 6 60
	response=$?
	case $response in
		0) 	starting=1;;
		1) 	starting=0
			dialog --backtitle "Joystick-Configuration for -${platform}- Platforms." --title "Configuration Finished" --msgbox 'Joystick-Configuration will now end.' 6 60;;
		255) starting=0
			 dialog --backtitle "Joystick-Configuration for -${platform}- Platforms." --title "Configuration Finished" --msgbox 'Joystick-Configuration will now end.' 6 60;;
	esac
	>$platformtemp
	>$joysticktemp
	>$playertemp
done #Ende der While Schleife

#After Configuration is finished all files have to be copied into retroarch.cfg
sudo cp -f /opt/retropie/configs/${platform}/retroarch_original.cfg /opt/retropie/configs/${platform}/retroarch.cfg
sudo cat /opt/retropie/configs/${platform}/p*.cfg >> /opt/retropie/configs/${platform}/retroarch.cfg

#Remove all Temp Files
rm $platformtemp
rm $joysticktemp
rm $playertemp