-
Notifications
You must be signed in to change notification settings - Fork 67
/
hauppauge.sh
executable file
·226 lines (202 loc) · 5.6 KB
/
hauppauge.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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
#!/bin/sh
#-------------------------------------------
# hauppauge.sh
#
# by: Vincent Fortier
# email: th0ma7_AT_gmail.com
#
# Simplify the status, start, stop, reset
# of tvheadend service along with loading
# and unloading of all necessary modules
#-------------------------------------------
SERVICE="pkgctl-tvheadend"
MODULE_PATH=/usr/local/lib/modules/$(uname -r)
MODULES="em28xx_dvb em28xx lgdt3306a si2157 tveeprom v4l2_common dvb_usb rc_core dvb_core videobuf2_vmalloc videobuf2_memops videobuf2_v4l2 videobuf2_common videodev media"
RESET=em28xx_dvb
#
declare -a SYSCTL_VAR=('vm.dirty_expire_centisecs' 'vm.swappiness')
declare -a SYSCTL_VALUE=('300' '1')
#
NOAUTOSUSPEND=em28xx
declare -a AUTOSUSPEND_VAR=('autosuspend_delay_ms' 'autosuspend')
declare -a AUTOSUSPEND_VALUE=('-1000' '-1')
USBAutoSuspend() {
usbID=$(lsusb -i | grep $NOAUTOSUSPEND | awk '{print $1}' | cut -f1 -d:)
if [ ! "$usbID" ]; then
echo "kernel USB (none) autosuspend values N/A"
else
echo "kernel USB ($usbID) autosuspend values..."
for index in "${!AUTOSUSPEND_VAR[@]}"
do
declare sys=/sys/bus/usb/devices/$usbID/power/${AUTOSUSPEND_VAR[$index]}
declare -i current=$(cat $sys)
declare -i new=${AUTOSUSPEND_VALUE[$index]}
printf '\t(%s)%-25s' $usbID ${AUTOSUSPEND_VAR[$index]}
if [ $current -eq $new ]; then
printf '[%5s] -> OK\n' "$current"
else
[ "$1" = "check" ] || echo ${AUTOSUSPEND_VALUE[$index]} | sudo tee $sys 1>/dev/null
printf '[%5s] -> [%5s]\n' "$current" "$new"
fi
done
fi
}
Sysctl() {
echo "kernel sysctl values... "
for index in "${!SYSCTL_VAR[@]}"
do
declare -i current=$(sysctl -n ${SYSCTL_VAR[$index]})
declare -i new=${SYSCTL_VALUE[$index]}
printf '\t%-30s' ${SYSCTL_VAR[$index]}
if [ $current -eq $new ]; then
printf '[%5s] -> OK\n' "$current"
else
[ "$1" = "check" ] || sysctl -w ${SYSCTL_VAR[$index]}=$new 2>/dev/null 1>&2
printf '[%5s] -> [%5s]\n' "$current" "$new"
fi
done
}
ModuleLOAD() {
echo "Loading kernel modules... "
for item in $MODULES; do echo $item; done | tac | while read module
do
module_load=$(echo "${module}.ko" | sed 's/_/-/g')
printf '\t%-30s' $module_load
status=$(lsmod | grep "^$module ")
if [ $? -eq 0 -a "status" ]; then
echo "Loaded"
else
insmod $MODULE_PATH/$module_load
[ $? -eq 0 ] && echo "OK" || echo "ERROR"
fi
done
}
ModuleUNLOAD() {
# Unload Hauppauge updated drivers
echo "Unloading kernel modules... "
for module in $MODULES
do
printf '\t%-30s' $module
status=$(lsmod | grep "^$module ")
if [ $? -eq 0 -a "status" ]; then
rmmod $module
echo -ne "OK\n"
else
echo -ne "N/A\n"
fi
done
}
ModuleSTATUS() {
# Unload Hauppauge updated drivers
echo "kernel module status... "
for module in $MODULES
do
printf '\t%-30s' $module
status=$(lsmod | grep "^$module ")
if [ $? -eq 0 -a "status" ]; then
echo -ne "OK\n"
else
echo -ne "N/A\n"
fi
done
}
ModuleRESET() {
reset=$1
module=$(echo "${reset}.ko" | sed 's/_/-/g')
rmmod $reset
sleep 1
insmod $MODULE_PATH/$module
}
ServiceSTATUS() {
status=$(synoservice --status $SERVICE | grep "\[$SERVICE\] status" | awk -F"status=" '{print $2}' | sed -e 's/\[//g' -e 's/\]//g')
running=$(synoservice --status $SERVICE | grep "\[$SERVICE\] is" | awk -F"is " '{print $2}' | sed -e 's/\.//g' -e 's/ //g')
pid=$(pidof tvheadend)
[ ! "$pid" ] && pid="---"
case "$1" in
"full" ) printf '%-38s' "Status $SERVICE..."
echo $status,$running,$pid
;;
* ) echo $running;;
esac
}
ServiceSTART() {
status=$(ServiceSTATUS)
#echo $status 1>&2
printf '%-38s' "Starting $SERVICE..."
module=$(lsmod | grep "^$RESET ")
if [ $? -ne 0 -a ! "module" ]; then
echo "ERROR module $RESET not found!"
return
fi
if [ "$status" = "stop" ]; then
synoservice --start $SERVICE
echo "OK"
elif [ "$status" = "start" ]; then
# Check if sevice isn't already started!
if [ "$(pidof tvheadend)" ]; then
echo "Started"
else
synoservice --restart $SERVICE 2>/dev/null 1>&2
echo "Restart"
fi
else
echo "N/A"
fi
}
ServiceSTOP() {
status=$(ServiceSTATUS)
#echo $status 1>&2
printf '%-38s' "Stopping $SERVICE..."
if [ "$status" = "start" ]; then
#synoservice --disable $SERVICE
synoservice --stop $SERVICE 2>/dev/null 1>&2
echo "OK"
else
echo "N/A"
fi
# Is it really off?
if [ "`pidof tvheadend`" ]; then
printf '%-33s' "Killing $SERVICE..."
kill -9 $(pidof tvheadend)
echo "killed"
fi
}
Usage() {
echo "$0 - Usage: start, stop, status, reset, restart, load"
}
case $1 in
start ) ModuleLOAD
USBAutoSuspend
Sysctl
ServiceSTART
;;
stop ) ServiceSTOP
ModuleUNLOAD
;;
status ) ServiceSTATUS full
ModuleSTATUS
USBAutoSuspend check
Sysctl check
;;
restart ) ServiceSTOP
ModuleUNLOAD
sleep 1
ModuleLOAD
USBAutoSuspend
Sysctl
ServiceSTART
;;
reset ) ServiceSTOP
ModuleRESET $RESET
ServiceSTART
ServiceSTATUS full
ModuleSTATUS
;;
load ) ModuleLOAD
USBAutoSuspend
Sysctl
;;
* ) Usage
;;
esac
exit 0