-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathportshare-serial-client
executable file
·202 lines (185 loc) · 3.75 KB
/
portshare-serial-client
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
#!/bin/sh
# chkconfig: 235 55 45
# description: portshare-serial-client script controls the interfaces of \
# the physical ports of Remote serial ports
BASE=/etc
DEVS=${BASE}/portshare-devices
BACKVARS=${BASE}/backvars$$
FOUND=0
BACKEXIT=0
DEV=all
GLOBALOPTS=""
# Make sure $PREFIX/sbin is in the path
PATH=`dirname $0`:$PATH
export DEV DEVS FOUND BACKEXIT BACKVARS PATH
clean()
{
if [ -f ${BACKVARS} ]
then
rm -f ${BACKVARS}
fi
}
if [ $# -lt 1 -o $# -gt 2 ]
then
echo "Usage : portshare-serial-client (start|stop|restart|status) [device]"
exit 2
fi
OPTION=$1
if [ $# -eq 2 ]
then
DEV=$2
fi
case $OPTION in
start_msg)
echo "Starting Portshare serial client"
exit 0
;;
stop_msg)
echo "Stopping Portshare serial client"
exit 0
;;
esac
if [ ! -f ${DEVS} ]
then
echo "portshare-serial-client : device table not found"
exit 1
fi
clean
trap 'clean' 1 2 3 15
cat ${DEVS} | grep -v "#" | while read line
do
if [ -z "${line}" ]
then
continue
fi
devc=`echo ${line} | cut -f1 -d:`
serv=`echo ${line} | cut -f2 -d:`
host=`echo ${line} | cut -f3 -d:`
port=`echo ${line} | cut -f4 -d:`
type=`echo ${line} | cut -f5 -d:`
opts=`echo ${line} | cut -f6 -d:`
opts="$GLOBALOPTS $opts"
if [ -z "${devc}" -o -z "${serv}" -o -z "${host}" -o -z "${port}" ]
then
echo "portshare-serial-client : Bad device table line"
BACKEXIT=3
echo "BACKEXIT=${BACKEXIT}" >> ${BACKVARS}
exit ${BACKEXIT}
fi
if [ "${DEV}" != "all" ]
then
if [ "${DEV}" != "${devc}" ]
then
continue
else
FOUND=1
echo "FOUND=${FOUND}" >> ${BACKVARS}
fi
fi
case ${type} in
rtelnet)
devst="${devc} (rtelnet at ${host}:${port})"
if [ "${serv}" = "path" ]
then
opts="-p 28672 $opts"
fi
;;
socket)
devst="${devc} ( socket at ${host}:${port})"
if [ "${serv}" = "path" ]
then
opts="-p 32768 $opts"
fi
opts="-s $opts"
;;
rfc2217)
devst="${devc} (rfc2217 at ${host}:${port})"
case ${serv} in
opengear|cm400?|cm41??|sd400?|im42??|img4004|acm500?)
opts="-p 5000 $opts"
;;
esac
;;
*)
case ${serv} in
opengear|cm400?|cm41??|sd400?|im42??|img4004|acm500?)
opts="-p 5000 $opts"
;;
*) echo "tsrport : Bad device table line"
BACKEXIT=2
echo "BACKEXIT=${BACKEXIT}" >> ${BACKVARS}
exit ${BACKEXIT}
;;
esac
;;
esac
if [ `uname` = "Linux" ]; then
ppid=`ps ax | grep portshare-ser-cli | grep "${devc} " | awk '{print $1}'`
else
ppid=`ps -ef | grep portshare-ser-cli | grep "${devc} " | awk '{print $2}'`
fi
case ${OPTION} in
"start")
if [ -n "${ppid}" ]
then
echo "portshare-serial-client : ${devc} already active"
continue
fi
echo "Starting ${devc} <<==>> ${host}:${port} interface"
portshare-ser-cli ${opts} ${devc} ${host} ${port}
sleep 1
;;
"stop")
if [ -z "${ppid}" ]
then
echo "portshare-serial-client : ${devc} already inactive"
continue
fi
echo "Stopping ${devc} <<==>> ${host}:${port} interface"
kill ${ppid}
;;
"restart")
if [ -z "${ppid}" ]
then
echo "portshare-serial-client : ${devc} is inactive"
echo "Starting ${devc} <<==>> ${host}:${port} interface"
portshare-ser-cli ${opts} ${devc} ${host} ${port}
sleep 1
else
echo \
"Restarting ${devc} <<==>> ${host}:${port} interface"
kill -s USR1 ${ppid}
fi
;;
"status")
if [ -n "${ppid}" ]
then
devst="${devst} active, pid ${ppid}"
else
devst="${devst} inactive"
fi
echo ${devst}
;;
*)
echo "Usage : portshare-serial-client (start|stop|restart|status) [device]"
BACKEXIT=2
echo "BACKEXIT=${BACKEXIT}" >> ${BACKVARS}
exit ${BACKEXIT}
;;
esac
done
if [ -s ${BACKVARS} ]
then
. ${BACKVARS}
fi
clean
if [ ${BACKEXIT} -ne 0 ]
then
exit ${BACKEXIT}
fi
if [ "${DEV}" != "all" -a $FOUND -eq 0 ]
then
echo "portshare-serial-client : device ${DEV} does not exist"
exit 3
fi
exit 0