-
Notifications
You must be signed in to change notification settings - Fork 13
/
oscamrr
130 lines (99 loc) · 4.3 KB
/
oscamrr
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
#!/bin/bash
USER_NAME="a"
USER_PASS="b"
PORT="8888"
OSCAM_READER="reader_sci0"
OSCAM_WEBIF="http://${USER_NAME}:${USER_PASS}@127.0.0.1:${PORT}" # if the oscam password is not used: OSCAM_WEBIF="http://127.0.0.1:${PORT}"
###################################
####
#### OSCAM-Reader-Restarts
####
#### A simple endless shell-script that restarts the Oscam reader - in case if there are no "Tiers" / "Entitlements"
####
###################################
####
#### Shell script designed by s3n0 (2022-03-20):
#### https://github.com/s3n0
#### https://www.linuxsat-support.com/cms/user/347246-s3n0/
####
#### Example of use:
#### /etc/init.d/oscamrr <start|stop|restart>
####
#### Original shell script:
#### https://www.linuxsat-support.com/thread/115614-script-to-restart-1-of-2-readers-on-no-entitelments/
####
###################################
####
#### How to install:
#### wget -O /etc/init.d/oscamrr --no-check-certificate "https://github.com/s3n0/e2scripts/raw/master/oscamrr" # download and place the script into the "/etc/inid.d" folder
#### chmod a+x /etc/init.d/oscamrr # and set the file execution rights
#### ln -sf /etc/init.d/oscamrr /etc/rc3.d/S90oscamrr # link the script file under the Run-Level-3 (for auto-start during system boot)
#### /etc/init.d/oscamrr start # start it manually (only as first time)
####
#### How to uninstall:
#### /etc/init.d/oscamrr stop
#### rm -f /etc/rc3.d/S90oscamrr /etc/init.d/oscamrr
####
###################################
TMP_SCRIPT_NAME="oscam_entitlements_checking"
###################################
fStart() {
cat << NEWSCRIPT > /tmp/$TMP_SCRIPT_NAME
#!/bin/bash
trap 'exit' INT TERM ERR
trap 'kill 0' EXIT
while true; do
# [ \$(wget -qO- "${OSCAM_WEBIF}/entitlements.html?label=${OSCAM_READER}" | grep -c "tier") -gt 0 ] && wget -qO- "${OSCAM_WEBIF}/status.html?action=restart&label=${OSCAM_READER}" > /dev/null 2>&1
[ \$(wget -qO- "${OSCAM_WEBIF}/entitlements.html?label=${OSCAM_READER}" | grep -c "e_expired") -gt 2 ] && wget -qO- "${OSCAM_WEBIF}/status.html?action=restart&label=${OSCAM_READER}" > /dev/null 2>&1
sleep 65
done
exit
NEWSCRIPT
chmod a+x /tmp/$TMP_SCRIPT_NAME
nohup /tmp/$TMP_SCRIPT_NAME &>/dev/null &
}
###################################
fStop() {
if [ -e "/tmp/$TMP_SCRIPT_NAME" ]; then
if killall --help > /dev/null 2>&1; then # use the `killall` command
killall -9 $TMP_SCRIPT_NAME
else # use the `kill` command
if ps --version 2>&1 | grep -q -i "busybox"; then # ...then... use the feature-poor `ps` command from BusyBox (for example in OpenPLi image)
PID=$(ps | grep $TMP_SCRIPT_NAME | grep -v 'grep' | awk '{ printf $1 }')
else # ...else... use the full-featured `ps` command from Linux OS (for example in OpenATV image)
PID=$(ps -ef | grep $TMP_SCRIPT_NAME | grep -v 'grep' | awk '{ printf $2 }')
#PID=$(ps -aux | grep $TMP_SCRIPT_NAME | grep -v 'grep' | cut -d ' ' -f 6)
fi
kill -n 9 $PID
fi
sleep 1
rm -f /tmp/$TMP_SCRIPT_NAME
fi
}
###################################
case "$1" in
start)
fStart
;;
stop)
fStop
;;
restart)
fStop
fStart
;;
status)
[ -e "/tmp/$TMP_SCRIPT_NAME" ] && { echo "service is running"; exit 0; } || { echo "service is stopped"; exit 3; }
;;
*)
echo "ERROR ! Wrong argument ! The correct usage syntax is:"
echo " $0 <start|stop|restart|status>"
exit 2 # invalid or excess argument(s)
;;
esac
###################################
exit 0
#### ---- to restart the specific card reader :
#### [ $(wget -qO- "${OSCAM_WEBIF}/entitlements.html?label=${OSCAM_READER}" | grep -c "tier") -gt 0 ] && wget -qO- "${OSCAM_WEBIF}/status.html?action=restart&label=${OSCAM_READER}" > /dev/null 2>&1
#### ---- to re-read entitlements :
#### # # # # # # # # # # # # # # # # # # # # # # # # # /readers.html?action=reread&label=${OSCAM_READER}" > /dev/null 2>&1