1 #!/bin/bash
2 #############################################################
3 # @file run_gateway.sh
4 #
5 # @brief TIMAC 2.0 run_gateway.sh, used by run_demo.sh to launch gateway
6 #
7 # Group: WCS LPC
8 # $Target Devices: Linux: AM335x, Embedded Devices: CC1310, CC1350$
9 #
10 #############################################################
11 # $License: BSD3 2016 $
12 #
13 # Copyright (c) 2015, Texas Instruments Incorporated
14 # All rights reserved.
15 #
16 # Redistribution and use in source and binary forms, with or without
17 # modification, are permitted provided that the following conditions
18 # are met:
19 #
20 # * Redistributions of source code must retain the above copyright
21 # notice, this list of conditions and the following disclaimer.
22 #
23 # * Redistributions in binary form must reproduce the above copyright
24 # notice, this list of conditions and the following disclaimer in the
25 # documentation and/or other materials provided with the distribution.
26 #
27 # * Neither the name of Texas Instruments Incorporated nor the names of
28 # its contributors may be used to endorse or promote products derived
29 # from this software without specific prior written permission.
30 #
31 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
32 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
33 # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
34 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
35 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
36 # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
37 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
38 # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
39 # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
40 # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
41 # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 #############################################################
43 # $Release Name: TI-15.4Stack Linux x64 SDK$
44 # $Release Date: July 14, 2016 (2.00.00.30)$
45 #############################################################
47 nodejs=`which nodejs`
48 arch=`uname -m`
50 if [ x"$nodejs"x != "xx" ]
51 then
52 # great, we have this
53 :
54 else
55 if [ x"${arch}"x == x"armv7l"x ]
56 then
57 # This name should be changed...
58 # however it has not been done yet
59 # SEE:
60 # https://lists.debian.org/debian-devel-announce/2012/07/msg00002.html
61 nodejs=`which node`
62 fi
63 fi
65 if [ x"$nodejs"x == xx ]
66 then
67 echo "Cannot find node-js appplication, is it installed?"
68 exit 6
69 fi
71 if [ ! -f $nodejs ]
72 then
73 echo "Cannot find node-js application, is it installed?"
74 exit 6
75 fi
77 if [ ! -x $nodejs ]
78 then
79 echo "Cannot find node-js application, is it installed?"
80 exit 6
81 fi
83 PID=`pgrep node |awk 'NR >= 2'`
85 if [ "x${PID}x" != "xx" ]
86 then
87 kill -9 ${PID}
88 fi
90 # Check for node_modules
91 if [ ! -d "node_modules" ]
92 then
93 echo "node_modules not found. Please run npm install to download and install the required dependencies for iot-gateway."
94 exit 9
95 fi
98 $nodejs ./iot-gateway.js $1&
99 PID=$!
100 # Wait a couple seconds for it to get started
101 # or ... for it to exit
102 sleep 2
104 if ps -p $PID > /dev/null
105 then
106 echo "Gateway is running as Process id: ${PID}"
107 exit 0
108 else
109 echo "Cannot start gateway application"
110 exit 8
111 fi