-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathCo-Op-On-Linux.sh
121 lines (95 loc) · 3.91 KB
/
Co-Op-On-Linux.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/bin/bash
DIR_CO_OP=$PWD
DIR_CO_OP_WEST=$DIR_CO_OP/weston_configs
DIR_CO_OP_CONT=$DIR_CO_OP/controller_blacklists
### Currently only 2 players is supported
if [ "$1" = --help ]; then
echo "
====C-O-O-L======================================================================X========
|| ||
|| --- how to use quickrun --- ||
|| ||
|| ~ ./Co-Op-On-linux.sh --quickrun resolution /path/to/the/game ||
|| ||
|| --- Example --- ||
|| ||
|| ~ ./Co-Op-On-linux.sh --quickrun 1280x720 /home/user/path/to/thegame ||
|| ||
|| ||
||--------------------------------------------------------------------------------------||
|| ! note ! : You need to run the script without --quickrun to regenerate configs. ||
||--------------------------------------------------------------------------------------||
|| ||
==========================================================================================
"
else
### Checking for --quickrun
if [ "$1" = --quickrun ] ; then
echo "Quickrun is used, The Controller and Resolution setup will be skipped for now
Run the script again without --quickrun or delete controller_blacklists folder if you want to reconfigure the controllers"
else
echo "Quickrun is not used, type --help for more information"
fi
### Manage game controllers
if [ "$1" = --quickrun ] && [ -d $DIR_CO_OP_CONT ] ; then
echo "Controllers already Configured."
else
rm -rf $DIR_CO_OP_CONT
mkdir $DIR_CO_OP_CONT
CONTROLLER_LIST=$(ls -l /dev/input/by-id/ | grep joystick | awk '{gsub("-joystick", ""); gsub("-event", ""); print $9}' | uniq)
CONTROLLER_1=$(zenity --list --title="Choose controller for player 1" --text="" --column=Controllers \ $CONTROLLER_LIST)
CONTROLLER_2=$(zenity --list --title="Choose controller for player 2" --text="" --column=Controllers \ $CONTROLLER_LIST)
echo $(ls -l /dev/input/by-id/ | grep joystick | grep -wv $CONTROLLER_1 | awk '{print "--blacklist=/dev/input/by-id/" $9;}' ) >> $DIR_CO_OP_CONT/Player1_Controller_Blacklist
echo $(ls -l /dev/input/by-id/ | grep joystick | grep -wv $CONTROLLER_2 | awk '{print "--blacklist=/dev/input/by-id/" $9;}' ) >> $DIR_CO_OP_CONT/Player2_Controller_Blacklist
fi
### Getting game path/command
if [ "$1" = --quickrun ]; then
GAMERUN="${@:3}"
else
GAMERUN=$(zenity --title="Select game executable/launch script" --file-selection)
fi
### Writing Config files for Weston
if [ -d $DIR_CO_OP_WEST ]; then
echo "Weston Configurations already exist."
else
mkdir $DIR_CO_OP_WEST
printf "[core]
xwayland=true
idle-time=0
[shell]
locking=false
[keyboard]
keymap_layout=gb
[launcher]
icon=/usr/share/weston/icon_terminal.png
path=/usr/bin/weston-terminal" >> $DIR_CO_OP_WEST/weston0.ini
cp $DIR_CO_OP_WEST/weston0.ini $DIR_CO_OP_WEST/weston1.ini
cp $DIR_CO_OP_WEST/weston0.ini $DIR_CO_OP_WEST/weston2.ini
fi
### Setup resolution for Weston sessions
if [ "$1" = --quickrun ]; then
RESOLUTION=($2)
else
RESOLUTION=$(zenity --title="Resolution" --entry --text="Enter Resolution for Weston sessions ( for example: 1280x720 ) " --entry-text="1280x720")
fi
WIDTH=$(printf $RESOLUTION | awk -F "x" '{print $1}')
HEIGHT=$(printf $RESOLUTION | awk -F "x" '{print $2}')
### Launching Weston sessions
weston --xwayland -c "$DIR_CO_OP_WEST/weston0.ini" --width=1024 --height=768 2> /dev/null &
sleep 2
weston --xwayland -c "$DIR_CO_OP_WEST/weston1.ini" --width=$WIDTH --height=$HEIGHT 2> /dev/null &
sleep 2
weston --xwayland -c "$DIR_CO_OP_WEST/weston2.ini" --width=$WIDTH --height=$HEIGHT 2> /dev/null &
sleep 2
notneeded=$(ps l | grep weston0.ini | awk 'length($0) > 120 {print $3}')
kill $notneeded
sleep 1
### Launching instances
#---Player 1---#
DISPLAY=:2 WAYLAND_DISPLAY=wayland-1 firejail --noprofile $(cat $DIR_CO_OP_CONT/Player1_Controller_Blacklist ) "$GAMERUN" &
sleep 1
#---Player 2---#
DISPLAY=:3 WAYLAND_DISPLAY=wayland-2 firejail --noprofile $(cat $DIR_CO_OP_CONT/Player2_Controller_Blacklist ) "$GAMERUN" &
sleep 1
echo "Done~!"
fi