-
Notifications
You must be signed in to change notification settings - Fork 15
/
kodi_init
executable file
·139 lines (127 loc) · 5.09 KB
/
kodi_init
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
#!/bin/bash
set -e
trap 'kill $(jobs -p) 2>/dev/null' EXIT
KODI_STARTUP_DELAY=30
KODI_FUZZY_INTERVAL=30
KODI_DEFAULT_UPDATE_INTERVAL=900
KODI_DEFAULT_CLEAN_INTERVAL=0
KODI_DEFAULT_UPDATE_INTERVAL_ADDONS=21600
echo "======================================================="
if [ ! -e /config/userdata/advancedsettings.xml ]; then
cp /usr/local/share/kodi/advancedsettings.xml.default /config/userdata/advancedsettings.xml
chown kodi. /config/userdata/advancedsettings.xml
if [ ! -z $KODI_DBHOST ] && [ ! -z $KODI_DBUSER ] && [ ! -z $KODI_DBPASS ]; then
echo "Configuring shared MySQL database ($KODI_DBHOST)"
xmlstarlet ed -L -u "advancedsettings/videodatabase/host" -v "$KODI_DBHOST" /config/userdata/advancedsettings.xml
xmlstarlet ed -L -u "advancedsettings/videodatabase/user" -v "$KODI_DBUSER" /config/userdata/advancedsettings.xml
xmlstarlet ed -L -u "advancedsettings/videodatabase/pass" -v "$KODI_DBPASS" /config/userdata/advancedsettings.xml
if [ ! -z $KODI_DBPORT ]; then
xmlstarlet ed -L -u "advancedsettings/videodatabase/port" -v "$KODI_DBPORT" /config/userdata/advancedsettings.xml
fi
if [ ! -z $KODI_DBPREFIX_VIDEOS ]; then
xmlstarlet ed -L -u "advancedsettings/videodatabase/name" -v "$KODI_DBPREFIX_VIDEOS" /config/userdata/advancedsettings.xml
fi
xmlstarlet ed -L -u "advancedsettings/musicdatabase/host" -v "$KODI_DBHOST" /config/userdata/advancedsettings.xml
xmlstarlet ed -L -u "advancedsettings/musicdatabase/user" -v "$KODI_DBUSER" /config/userdata/advancedsettings.xml
xmlstarlet ed -L -u "advancedsettings/musicdatabase/pass" -v "$KODI_DBPASS" /config/userdata/advancedsettings.xml
if [ ! -z $KODI_DBPORT ]; then
xmlstarlet ed -L -u "advancedsettings/musicdatabase/port" -v "$KODI_DBPORT" /config/userdata/advancedsettings.xml
fi
if [ ! -z $KODI_DBPREFIX_MUSIC ]; then
xmlstarlet ed -L -u "advancedsettings/musicdatabase/name" -v "$KODI_DBPREFIX_MUSIC" /config/userdata/advancedsettings.xml
fi
else
echo "Not configuring shared MySQL database"
fi
else
echo "Using existing configuration"
fi
if [ -z $KODI_UPDATE_INTERVAL ]; then
KODI_UPDATE_INTERVAL=$KODI_DEFAULT_UPDATE_INTERVAL
fi
if [ -z $KODI_UPDATE_INTERVAL_VIDEOS ]; then
KODI_UPDATE_INTERVAL_VIDEOS=$KODI_UPDATE_INTERVAL
fi
if [ -z $KODI_UPDATE_INTERVAL_MUSIC ]; then
KODI_UPDATE_INTERVAL_MUSIC=$KODI_UPDATE_INTERVAL
fi
if [ -z $KODI_CLEAN_INTERVAL ]; then
# support legacy clean setting for now
if [[ $KODI_CLEAN == "yes" ]] || [[ $KODI_CLEAN == "true" ]]; then
KODI_CLEAN_INTERVAL=86400
else
KODI_CLEAN_INTERVAL=$KODI_DEFAULT_CLEAN_INTERVAL
fi
fi
if [ -z $KODI_CLEAN_INTERVAL_VIDEOS ]; then
KODI_CLEAN_INTERVAL_VIDEOS=$KODI_CLEAN_INTERVAL
fi
if [ -z $KODI_CLEAN_INTERVAL_MUSIC ]; then
KODI_CLEAN_INTERVAL_MUSIC=$KODI_CLEAN_INTERVAL
fi
if [ -z $KODI_UPDATE_INTERVAL_ADDONS ]; then
KODI_UPDATE_INTERVAL_ADDONS=$KODI_DEFAULT_UPDATE_INTERVAL_ADDONS
fi
function update_library_job {
while true; do
sleep $2
sleep $((RANDOM % $KODI_FUZZY_INTERVAL))
echo "Triggering $1 library update"
su kodi -c "kodi-send --action='UpdateLibrary($1)'" > /dev/null
done
}
function clean_library_job {
while true; do
sleep $2
sleep $((RANDOM % $KODI_FUZZY_INTERVAL))
echo "Triggering $1 library cleanup"
su kodi -c "kodi-send --action='CleanLibrary($1)'" > /dev/null
done
}
function update_addons_job {
sleep $KODI_STARTUP_DELAY
echo "Triggering initial addon updates"
su kodi -c "kodi-send --action='UpdateAddonRepos'" > /dev/null
while true; do
sleep $1
sleep $((RANDOM % $KODI_FUZZY_INTERVAL))
echo "Triggering addon updates"
su kodi -c "kodi-send --action='UpdateAddonRepos'" > /dev/null
done
}
if [[ $KODI_UPDATE_INTERVAL_VIDEOS -gt 0 ]]; then
echo "Automatic video library update: Yes (${KODI_UPDATE_INTERVAL_VIDEOS}s)"
update_library_job video $KODI_UPDATE_INTERVAL_VIDEOS &
else
echo "Automatic video library update: No"
fi
if [[ $KODI_UPDATE_INTERVAL_MUSIC -gt 0 ]]; then
echo "Automatic music library update: Yes (${KODI_UPDATE_INTERVAL_MUSIC}s)"
update_library_job music $KODI_UPDATE_INTERVAL_MUSIC &
else
echo "Automatic music library update: No"
fi
if [ -e /config/userdata/sources.xml ] && [ -e /config/userdata/passwords.xml ]; then
if [[ $KODI_CLEAN_INTERVAL_VIDEOS -gt 0 ]]; then
echo "Automatic video library cleaning: Yes (${KODI_CLEAN_INTERVAL_VIDEOS}s)"
clean_library_job video $KODI_CLEAN_INTERVAL_VIDEOS &
else
echo "Automatic video library cleaning: No"
fi
if [[ $KODI_CLEAN_INTERVAL_MUSIC -gt 0 ]]; then
echo "Automatic video library cleaning: Yes (${KODI_CLEAN_INTERVAL_MUSIC}s)"
clean_library_job music $KODI_CLEAN_INTERVAL_MUSIC &
else
echo "Automatic music library cleaning: No"
fi
else
echo "Automatic library cleaning: No (sources.xml/passwords.xml not found)"
fi
update_addons_job $KODI_UPDATE_INTERVAL_ADDONS &
echo "======================================================="
echo "Starting Kodi..."
if [ -f /config/temp/kodi.log ]; then
rm /config/temp/kodi.log
fi
tail -F -q /config/temp/kodi.log 2>/dev/null &
exec su kodi -c "kodi -p --standalone --headless"