forked from adangert/JoustMania
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
executable file
·182 lines (148 loc) · 7.93 KB
/
setup.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#!/bin/bash
setup() {
# Prevent apt from prompting us about restarting services.
export DEBIAN_FRONTEND=noninteractive
HOMENAME=`logname`
HOMEDIR=/home/$HOMENAME
cd $HOMEDIR
#removing espeak, most installs/updates are done manually, and there
#is a ton of extra terminal output
#sudo apt-get install -y espeak
#This is needed to hear espeak with sudo (adjusting asound.conf)
#adds asound.conf to /etc/ This is important for audio to play
#out of the headphone jack, sudo aplay <wav file> does weird things
#and setting it to the correct device(headphones) (hw:<HEADPHONE NUMBER>,0)
#Allows multiple streams to play at the same time
#The pi 4 headphones do not like the dmixer and give a
#ALSA: Couldn't open audio device: Invalid argument
#However the USB input needs a dmixer for multiple streams to work
#This is why we are splitting up the below logic for both
#the pi4 and pi5 (which requires a usb audio jack).
echo "Now trying to get the audio card"
#Get the sudo aplay -l line corresponding to the headphones
headphones_info=$(sudo aplay -l | grep -Ei 'Headphones')
if [ ! -z "$headphones_info" ]; then
echo "Headphones found, likely a pi 4, updating asound.conf"
#Get the card number from the headphones_info(tested 0 on bullseye, 2 on bookworm)
card_number=$(echo "$headphones_info" | sed -n 's/^card \([0-9]*\):.*$/\1/p' | head -n 1) || exit -1
#update the asound.conf to have the correct card to play from, copy to /etc
sed -i "s/pcm \"hw:[0-9]*,/pcm \"hw:$card_number,/g" $HOMEDIR/JoustMania/conf/asound_pi_4.conf || exit -1
sed -i "s/card [0-9]*/card $card_number/g" $HOMEDIR/JoustMania/conf/asound_pi_4.conf || exit -1
sudo cp $HOMEDIR/JoustMania/conf/asound_pi_4.conf /etc/asound.conf || exit -1
else
echo "Headphones not found, likely a pi 5"
fi
USB_info=$(sudo aplay -l | grep -Ei 'USB')
if [ ! -z "$USB_info" ]; then
echo "USB audio jack found, likely a pi 5, updating asound.conf"
#Get the card number from the headphones_info(tested 0 on bullseye, 2 on bookworm)
card_number=$(echo "$USB_info" | sed -n 's/^card \([0-9]*\):.*$/\1/p' | head -n 1) || exit -1
#update the asound.conf to have the correct card to play from, copy to /etc
sed -i "s/pcm \"hw:[0-9]*,/pcm \"hw:$card_number,/g" $HOMEDIR/JoustMania/conf/asound.conf || exit -1
sed -i "s/card [0-9]*/card $card_number/g" $HOMEDIR/JoustMania/conf/asound.conf || exit -1
sudo cp $HOMEDIR/JoustMania/conf/asound.conf /etc/ || exit -1
else
echo "No USB audio jack found, likely a pi 4"
fi
echo "starting software upgrade"
sudo apt-get update -y || exit -1
sudo apt-get upgrade -y || exit -1
echo "Installing required software dependencies"
#TODO: remove pyaudio and dependencies
#install components
sudo apt-get install -y \
python3 python3-dev python3-pip \
python3-pkg-resources python3-setuptools libdpkg-perl \
libsdl1.2-dev libsdl-mixer1.2-dev libsdl-sound1.2-dev \
libportmidi-dev portaudio19-dev \
libsdl-image1.2-dev libsdl-ttf2.0-dev \
libblas-dev liblapack-dev \
bluez bluez-tools iptables rfkill supervisor cmake ffmpeg \
libudev-dev swig libbluetooth-dev \
alsa-utils alsa-tools libasound2-dev libsdl2-mixer-2.0-0 \
python-dbus-dev python3-dbus libdbus-glib-1-dev usbutils libatlas-base-dev \
python3-pyaudio python3-psutil || exit -1
echo "Installing PS move A.P.I. software updates"
#install components for psmoveapi
sudo apt-get install -y \
build-essential \
libv4l-dev libopencv-dev \
libudev-dev libbluetooth-dev \
libusb-dev || exit -1
echo "Installing software libraries"
VENV=$HOMEDIR/JoustMania/venv
# We install nearly all python deps in the virtualenv to avoid concflicts with system, except
# numpy and scipy because they take forever to build.
sudo apt-get install -y libasound2-dev libasound2 python3-scipy cmake || exit -1
#install the python3 dev environment
echo "about to install python3-dev and virtualenv"
sudo apt-get install -y python3-dev || exit -1
sudo apt-get install -y python3-virtualenv || exit -1
echo "installing virtual environment"
/usr/bin/python3 -m virtualenv --system-site-packages $VENV || exit -1
PYTHON=$VENV/bin/python3
echo "installing virtual environment dependencies"
$PYTHON -m pip install --ignore-installed flask Flask-WTF pyalsaaudio pydub pyyaml dbus-python python-dotenv || exit -1
#Sometimes pygame tries to install without a whl, and fails (like 2.4.0) this
#checks that only correct versions will install
$PYTHON -m pip install --ignore-installed --only-binary ":all:" pygame || exit -1
echo "downloading PS move API"
#install psmoveapi (currently adangert's for opencv 3 support)
rm -rf psmoveapi
git clone --recursive https://github.com/thp/psmoveapi.git || exit -1
cd psmoveapi || exit -1
git checkout 8a1f8d035e9c82c5c134d848d9fbb4dd37a34b58 || exit -1
echo "compiling PS move API components"
mkdir build
cd build
cmake .. \
-DPSMOVE_BUILD_CSHARP_BINDINGS:BOOL=OFF \
-DPSMOVE_BUILD_EXAMPLES:BOOL=OFF \
-DPSMOVE_BUILD_JAVA_BINDINGS:BOOL=OFF \
-DPSMOVE_BUILD_OPENGL_EXAMPLES:BOOL=OFF \
-DPSMOVE_BUILD_PROCESSING_BINDINGS:BOOL=OFF \
-DPSMOVE_BUILD_TESTS:BOOL=OFF \
-DPSMOVE_BUILD_TRACKER:BOOL=OFF \
-DPSMOVE_USE_PSEYE:BOOL=OFF || exit -1
make -j4 || exit -1
#change the supervisord directory to our own homename
#this replaces pi default username in joust.conf,
sed -i -e "s/pi/$HOMENAME/g" $HOMEDIR/JoustMania/conf/supervisor/conf.d/joust.conf || exit -1
#installs custom supervisor script for running joustmania on startup
sudo cp -r $HOMEDIR/JoustMania/conf/supervisor/ /etc/ || exit -1
#Use amixer to set sound output to 100% (This looks somewhat broken, potentially remove it)
#unable to find simple control 'PCM',0
amixer sset PCM,0 100%
sudo alsactl store
DIST_REL=$(cut -f2 <<< $(lsb_release -r))
if [ "$DIST_REL" -ge 12 ]; then
echo "the distribution $DIST_REL is larger than 12"
config_loc=/boot/firmware/config.txt || exit -1
else
echo "the distribution is smaller than 12"
config_loc=/boot/config.txt || exit -1
fi
#This will disable on-board bluetooth with the --disable_internal_bt command line option
#This will allow only class one long range btdongles to connect to psmove controllers
if [ "$1" = "--disable_internal_bt" ]; then
echo "disabling internal bt"
sudo grep -qxF 'dtoverlay=disable-bt' $config_loc || { echo "dtoverlay=disable-bt" | sudo tee -a $config_loc; sudo rm -rf /var/lib/bluetooth/*; } || exit -1
sudo systemctl disable hciuart || exit -1
fi
uname2="$(stat --format '%U' $HOMEDIR'/JoustMania/setup.sh')"
uname3="$(stat --format '%U' $HOMEDIR'/JoustMania/piparty.py')"
if [ "${uname2}" = "root" ] || [ "${uname3}" = "root" ] ; then
sudo chown -R $HOMENAME:$HOMENAME $HOMEDIR/JoustMania/ || exit -1
echo "permisions updated, please wait after reboot for Joustmania to start"
else
echo "no permissions to update"
fi
#This will change ClassiBondedOnly to false in /etc/bluetooth/input.conf
#needed for pairing the PS3 controllers: https://github.com/thp/psmoveapi/issues/489
sudo sed -i '/^#\?ClassicBondedOnly=\(true\|false\)$/s/.*/ClassicBondedOnly=false/' '/etc/bluetooth/input.conf'
echo "joustmania successfully updated, now rebooting"
#es[eak "Joustmania successfully updated, now rebooting"
# Pause a second before rebooting so we can see all the output from this script.
(sleep 2; sudo reboot) &
}
setup $1 2>&1 | tee setup.log