forked from Wintermute0110/kodi-install
-
Notifications
You must be signed in to change notification settings - Fork 0
/
start_kodi.sh
executable file
·202 lines (151 loc) · 7.79 KB
/
start_kodi.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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#!/bin/bash
################################################################################
# Inputs
################################################################################
# Setup arrays that will store what we need
KODI_LOCATIONS="OFFICE" # "LIVING", "BOTH"
if [ $KODI_LOCATIONS == "BOTH" ]; then
KODI_DOCKER_NAMES=("kodi_living_room" "kodi_office")
USB_PASSTHROUGH=("js1" "js0")
DISPLAYS=(":0.2" ":0.1")
elif [ $KODI_LOCATIONS == "LIVING" ]; then
KODI_DOCKER_NAMES=("kodi_living_room")
USB_PASSTHROUGH=("js1")
DISPLAYS=(":0.2")
elif [ $KODI_LOCATIONS == "OFFICE" ]; then
KODI_DOCKER_NAMES=("kodi_office")
USB_PASSTHROUGH=("js0")
DISPLAYS=(":0.1")
fi
# Kodi resources
KODI_RESOURCES="kodi_resources"
MARIADB_PASS="kodimaria"
################################################################################
# Functions
################################################################################
# Copy emulator bioses
copy_bioses () {
KODI_PROCESS_NAME=$1
for i in "${KODI_PROCESS_NAME[@]}"
do
# Copy PSX bxos
mkdir -p ~/${KODI_RESOURCES}/$i/.kodi/userdata/addon_data/game.libretro.pcsx-rearmed/resources/system/
cp -u ./bios/scph*.bin ~/${KODI_RESOURCES}/$i/.kodi/userdata/addon_data/game.libretro.pcsx-rearmed/resources/system/
cp -u ./bios/scph*.bin ~/${KODI_RESOURCES}/$i/.kodi/userdata/addon_data/game.libretro.beetle-psx/resources/system
# Copy Sega CD Bios
mkdir -p ~/${KODI_RESOURCES}/$i/.kodi/userdata/addon_data/game.libretro.genplus/resources/system/
cp -u ./bios/bios_CD_E.bin ~/${KODI_RESOURCES}/$i/.kodi/userdata/addon_data/game.libretro.genplus/resources/system/
cp -u ./bios/bios_CD_U.bin ~/${KODI_RESOURCES}/$i/.kodi/userdata/addon_data/game.libretro.genplus/resources/system/
cp -u ./bios/bios_CD_J.bin ~/${KODI_RESOURCES}/$i/.kodi/userdata/addon_data/game.libretro.genplus/resources/system/
# Master System
mkdir -p ~/${KODI_RESOURCES}/$i/.kodi/userdata/addon_data/game.libretro.genplus/resources/system/
cp -u ./bios/bios_E.sms ~/${KODI_RESOURCES}/$i/.kodi/userdata/addon_data/game.libretro.genplus/resources/system/
cp -u ./bios/bios_U.sms ~/${KODI_RESOURCES}/$i/.kodi/userdata/addon_data/game.libretro.genplus/resources/system/
cp -u ./bios/bios_J.sms ~/${KODI_RESOURCES}/$i/.kodi/userdata/addon_data/game.libretro.genplus/resources/system/
# Game Gear
mkdir -p ~/${KODI_RESOURCES}/$i/.kodi/userdata/addon_data/game.libretro.genplus/resources/system/
cp -u ./bios/bios.gg ~/${KODI_RESOURCES}/$i/.kodi/userdata/addon_data/game.libretro.genplus/resources/system/
# Dreamcast
mkdir -p ~/${KODI_RESOURCES}/$i/.kodi/userdata/addon_data/game.libretro.reicast/resources/system/dc/
cp -u ./bios/dc_boot.bin ~/${KODI_RESOURCES}/$i/.kodi/userdata/addon_data/game.libretro.reicast/resources/system/dc/
cp -u ./bios/dc_flash.bin ~/${KODI_RESOURCES}/$i/.kodi/userdata/addon_data/game.libretro.reicast/resources/system/dc/
# Naomi
cp -u ./bios/hod2bios.zip ~/${KODI_RESOURCES}/$i/.kodi/userdata/addon_data/game.libretro.reicast/resources/system/dc/
cp -u ./bios/f355dlx.zip ~/${KODI_RESOURCES}/$i/.kodi/userdata/addon_data/game.libretro.reicast/resources/system/dc/
cp -u ./bios/f355bios.zip ~/${KODI_RESOURCES}/$i/.kodi/userdata/addon_data/game.libretro.reicast/resources/system/dc/
cp -u ./bios/airlbios.zip ~/${KODI_RESOURCES}/$i/.kodi/userdata/addon_data/game.libretro.reicast/resources/system/dc/
cp -u ./bios/awbios.zip ~/${KODI_RESOURCES}/$i/.kodi/userdata/addon_data/game.libretro.reicast/resources/system/dc/
# Playstaiton 2
mkdir -p ~/${KODI_RESOURCES}/$i/.config/PCSX2/bios/
cp -u ./bios/PS2/* ~/${KODI_RESOURCES}/$i/.config/PCSX2/bios/
done
}
# Mount all the samba shares you want
# To be able to mount cifs shares you must have cifs-utils installed
# sudo apt install -y cifs-utils
mount_cifs () {
local HOST=$1
local SHARE=$2
local CIFS_USER=$3
local CIFS_PASS=$4
echo "Mounting share: $HOST/$SHARE"
mkdir -p ~/${KODI_RESOURCES}/shares/$HOST/$SHARE
sudo mount -t cifs //$HOST/$SHARE/ ~/${KODI_RESOURCES}/shares/$HOST/$SHARE -o user=$CIFS_USER,pass=$CIFS_PASS,vers=1.0,ro
}
# Start mariadb (common db for the kodi instances)
mkdir -p ~/${KODI_RESOURCES}/mariadb
sudo docker run --name kodi-mariadb \
-v ~/${KODI_RESOURCES}/mariadb:/var/lib/mysql \
-v /etc/localtime:/etc/localtime:ro \
-e MYSQL_ROOT_PASSWORD=${MARIADB_PASS} -d mariadb:latest
MARIA_DOCKER=`sudo docker ps | grep kodi-mariadb | cut -f1 -d ' '`
sleep 5
sudo docker exec -it kodi-mariadb mysql -p${MARIADB_PASS} -e "CREATE USER IF NOT EXISTS 'kodi' IDENTIFIED BY 'kodi';"
sudo docker exec -it kodi-mariadb mysql -p${MARIADB_PASS} -e "SET PASSWORD FOR 'kodi'@'%' = PASSWORD('${MARIADB_PASS}');"
sudo docker exec -it kodi-mariadb mysql -p${MARIADB_PASS} -e "GRANT ALL ON *.* TO 'kodi';"
sudo docker exec -it kodi-mariadb mysql -p${MARIADB_PASS} -e "flush privileges;"
MARIA_DB_IP=`sudo docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' kodi-mariadb`
# replace with the correct IP in the settings
sed 's/'"<pass>kodi<\/pass>"'/'"<pass>${MARIADB_PASS}<\/pass>"'/g' < advancedsettings_template.xml > advancedsettings.xml
sed -i 's/'"\*\*\*.\*\*\*.\*\*\*.\*\*\*"'/'"${MARIA_DB_IP}"'/g' advancedsettings.xml
# Copy this file over to each kodi
for i in "${KODI_DOCKER_NAMES[@]}"
do
mkdir -p ~/${KODI_RESOURCES}/$i/.kodi/userdata
cp ./advancedsettings.xml ~/${KODI_RESOURCES}/$i/.kodi/userdata/
done
# Copy bios' over
copy_bioses ${KODI_DOCKER_NAMES[@]}
# Open Media Vault Shares
mount_cifs "openmediavault.local" "Anime_Disk18" "xbmc" "xbmc"
# Minime Shares
mount_cifs "minime.local" "snapdisk_8tb_03_shows" "xbmc" "xbmc"
# Start up the different kodi instances
for (( i = 0 ; i < ${#KODI_DOCKER_NAMES[@]} ; i=$i+1 ));
do
CURR_DOCKER=${KODI_DOCKER_NAMES[${i}]}
CURR_USB_PASSTHROUGH=${USB_PASSTHROUGH[${i}]}
CURR_DISPLAY=${DISPLAYS[${i}]}
# Get the event for the usb pass-through
CURR_USB_DEVICE_NAME=`ls -lah /dev/input/by-id/ | grep ${CURR_USB_PASSTHROUGH} | awk '{print $9}'`
CURR_USB_DEVICE_NAME=${CURR_USB_DEVICE_NAME/-joystick/}
CURR_USB_EVENT=`ls -lah /dev/input/by-id/ | grep $CURR_USB_DEVICE_NAME | grep event | awk '{print $11}'`
CURR_USB_EVENT=${CURR_USB_EVENT/..\//}
echo
echo "#####################################################################"
echo "Setting up $CURR_DOCKER ON ${CURR_DISPLAY}"
echo "USB device: ${CURR_USB_PASSTHROUGH}, ${CURR_USB_EVENT}"
echo "#####################################################################"
echo
export DISPLAY="${CURR_DISPLAY}"
sleep 1
sudo x11docker --homedir ~/${KODI_RESOURCES}/${CURR_DOCKER} \
--hostdisplay --desktop --gpu --alsa --pulseaudio --wm=gnome -- \
--device=/dev/input/${CURR_USB_PASSTHROUGH} \
--device=/dev/input/${CURR_USB_EVENT} \
--privileged \
-v /etc/localtime:/etc/localtime:ro \
-v /dev/bus/usb:/dev/bus/usb \
-v /dev/input:/dev/input \
-v $HOME/${KODI_RESOURCES}/shares:$HOME/shares \
--link kodi-mariadb:mysql \
-- kodi &
sleep 5
#export DISPLAY=":0.0"
done
export DISPLAY=":0.0"
test () {
sudo docker run -t -i --device=/dev/input/event17 \
--device=/dev/input/js1 \
--device=/dev/bus/usb/001/007 \
-v /dev/input:/dev/input ubuntu bash
sudo docker run -t -i \
--device=/dev/input \
-v /dev/input:/dev/input ubuntu bash
# Useful to figure out which joystick to send to a kodi
apt-get update
apt-get install joystick -y
jstest /dev/input/js0
pulseaudio -k
pacmd set-card-profile 0 output:analog-stereo+output:hdmi-stereo+output:hdmi-stereo+output:hdmi-stereo
}