rc.frewe-client 3.06 KB
Newer Older
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
#!/bin/sh
# Install/uninstall, start/stop/restart, testrun frewe-client

if [ -x /usr/bin/dirname ] && [ -x /usr/bin/readlink ]
then

        if [ -L $0 ] 
        then
            DIR=$(dirname $(readlink -f $0)) ;
        else
            DIR=$(dirname $0) ;
        fi
else
	DIR="/var/media/ftp/frewe"
fi

if [ "$DIR" == "." ]
then
	DIR="`pwd`"
fi

PRONAME="frewe-client"
BINFILE="$DIR/$PRONAME"
CFGFILE="$DIR/$PRONAME.cfg"
LOGFILE="/dev/null"

# Uncomment to enable local data logging
#LOGFILE="$DIR/$PRONAME.csv"

if [ ! -f "$BINFILE" ]
then
	echo "File $BINFILE not found. "
	echo "Please upload this file. Aborted"
	exit 1
fi

if [ ! -f "$CFGFILE" ] 
then
	echo "File $CFGFILE not found."
	echo "Please upload this file. Aborted"
	exit 1
fi

chmod 755 $BINFILE

# Print version info of currently installed frewe-client
$BINFILE -H

case "$1" in

install)

if [ -e /var/flash/debug.cfg ] && [ "`cat /var/flash/debug.cfg | grep $PRONAME`" != "" ]
then
	echo "$PRONAME is already installed. Here is the content of debug.cfg:"
	cat /var/flash/debug.cfg
	echo "Nothing to install"
	exit 1
fi

echo "(max=12; i=0; while [ \$i -lt \$max ]; do if [ -x "$BINFILE" ]; then $BINFILE -c $CFGFILE >> $LOGFILE & break; fi; let i=\$i+1; echo Waiting for $PRONAME... \$i; sleep 5; done) &" > /var/tmp/debug.cfg

if [ -e /var/flash/debug.cfg ]
then
	cat /var/flash/debug.cfg >> /var/tmp/debug.cfg
fi

cat /var/tmp/debug.cfg > /var/flash/debug.cfg
echo "$PRONAME installed. Here is the content of the new debug.cfg:"
cat /var/flash/debug.cfg

;;

uninstall)

if [ -e /var/flash/debug.cfg ]
then
	cat /var/flash/debug.cfg | grep -v $PRONAME > /var/tmp/debug.cfg
	cat /var/tmp/debug.cfg > /var/flash/debug.cfg
	echo "$PRONAME uninstalled. Here is the content of the new debug.cfg:"
	cat /var/flash/debug.cfg
else
	echo "debug.cfg not found, nothing was installed..."
fi

;;

start)

if [ "`pidof $PRONAME`" != "" ]
then
	echo "$PRONAME is already running with PID `pidof $PRONAME`"
	exit 1
fi
$BINFILE -c $CFGFILE >> $LOGFILE &
echo "$PRONAME started with PID `pidof $PRONAME`"

;;

stop)

if [ "`pidof $PRONAME`" == "" ]
then
	echo "$PRONAME is not running. Nothing to stop"
	exit 1
fi
kill `pidof $PRONAME`
echo "$PRONAME stopped"

;;

restart)

if [ "`pidof $PRONAME`" == "" ]
then
	echo "$PRONAME is not running. Nothing to stop"
else
	kill `pidof $PRONAME`
	echo "$PRONAME stopped"
fi

if [ "`pidof $PRONAME`" != "" ]
then
	echo "$PRONAME is already running with PID `pidof $PRONAME`"
	exit 1
fi
$BINFILE -c $CFGFILE >> $LOGFILE &
echo "$PRONAME started with PID `pidof $PRONAME`"

;;

stat)

if [ "`cat /var/flash/debug.cfg | grep $PRONAME`" != "" ]
then
	echo "$PRONAME is installed. Here is content of debug.cfg:"
	cat /var/flash/debug.cfg
else
	echo "$PRONAME is not installed"
fi

echo

if [ "`pidof $PRONAME`" != "" ]
then
	echo "$PRONAME is running with PID `pidof $PRONAME`"
	ps | grep "`pidof $PRONAME`"
else
	echo "$PRONAME is not running"
fi

;;


testrun)

$BINFILE -v

;;

testruncfg)

$BINFILE -v -c $CFGFILE -r 0

;;

*)

echo "Usage: $0 {install|uninstall|start|stop|restart|stat|testrun|testruncfg}"
exit 1

;;

esac

exit 0