blob: 2d83cdd7936ab963a44a240108e5c62fc8394b4f [file] [log] [blame]
developer15a43312022-04-12 11:23:23 +08001#!/bin/sh
2##########################################################################
3# If not stated otherwise in this file or this component's Licenses.txt
4# file the following copyright and licenses apply:
5#
6# Copyright 2016 RDK Management
7#
8# Licensed under the Apache License, Version 2.0 (the "License");
9# you may not use this file except in compliance with the License.
10# You may obtain a copy of the License at
11#
12# http://www.apache.org/licenses/LICENSE-2.0
13#
14# Unless required by applicable law or agreed to in writing, software
15# distributed under the License is distributed on an "AS IS" BASIS,
16# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17# See the License for the specific language governing permissions and
18# limitations under the License.
19##########################################################################
20# Scripts having common utility functions
21
22if [ -f /etc/utopia/service.d/log_env_var.sh ];then
23 source /etc/utopia/service.d/log_env_var.sh
24fi
25
26CMINTERFACE="wan0"
27WANINTERFACE="erouter0"
28
29#checkProcess()
30#{
31# ps -ef | grep $1 | grep -v grep
32#}
33
34Timestamp()
35{
36 date +"%Y-%m-%d %T"
37}
38
39# Set the name of the log file using SHA1
40#setLogFile()
41#{
42# fileName=`basename $6`
43# echo $1"_mac"$2"_dat"$3"_box"$4"_mod"$5"_"$fileName
44#}
45
46# Get the MAC address of the machine
47getMacAddressOnly()
48{
49 mac=`ifconfig $WANINTERFACE | grep HWaddr | cut -d " " -f7 | sed 's/://g'`
50 echo $mac
51}
52
53# Get the SHA1 checksum
54getSHA1()
55{
56 sha1sum $1 | cut -f1 -d" "
57
58}
59
60# IP address of the machine
61getIPAddress()
62{
63 wanIP=`ifconfig $WANINTERFACE | grep "inet addr" | grep -v inet6 | cut -f2 -d: | cut -f1 -d" "`
64 echo $wanIP
65}
66
67getCMIPAddress()
68{
69 if [ "$BOX_TYPE" = "XB6" ] || [ "$BOX_TYPE" = "TCCBR" ]; then
70 address=`dmcli eRT getv Device.X_CISCO_COM_CableModem.IPv6Address | grep string | awk '{print $5}'`
71 if [ ! "$address" ]; then
72 address=`dmcli eRT getv Device.X_CISCO_COM_CableModem.IPAddress | grep string | awk '{print $5}'`
73 fi
74 elif [ $BOX_TYPE = "XF3" ] || [ "$BOX_TYPE" = "HUB4" ]; then
75 # in PON/DSL you cant get the CM IP address, so use eRouter IP address
76 address=`ifconfig $WANINTERFACE | grep "inet addr" | grep -v inet6 | cut -f2 -d: | cut -f1 -d" "`
77 else
78 address=`ifconfig -a $CMINTERFACE | grep inet6 | tr -s " " | grep -v Link | cut -d " " -f4 | cut -d "/" -f1`
79 if [ ! "$address" ]; then
80 address=`ifconfig -a $CMINTERFACE | grep inet | grep -v inet6 | tr -s " " | cut -d ":" -f2 | cut -d " " -f1`
81 fi
82 fi
83 echo $address
84
85}
86
87getErouterIPAddress()
88{
89 if [ "$BOX_TYPE" = "XB6" ] || [ "$BOX_TYPE" = "TCCBR" ]; then
90 address=`dmcli eRT getv Device.DeviceInfo.X_COMCAST-COM_WAN_IPv6 | grep string | awk '{print $5}'`
91 if [ ! "$address" ]; then
92 address=`dmcli eRT getv Device.DeviceInfo.X_COMCAST-COM_WAN_IP | grep string | awk '{print $5}'`
93 fi
94 elif [ $BOX_TYPE = "XF3" ] || [ "$BOX_TYPE" = "HUB4" ]; then
95 # in PON/DSL you cant get the CM IP address, so use eRouter IP address
96 address=`ifconfig $WANINTERFACE | grep "inet addr" | grep -v inet6 | cut -f2 -d: | cut -f1 -d" "`
97 else
98 address=`ifconfig -a $WANINTERFACE | grep inet6 | tr -s " " | grep -v Link | cut -d " " -f4 | cut -d "/" -f1`
99 if [ ! "$address" ]; then
100 address=`ifconfig -a $WANINTERFACE | grep inet | grep -v inet6 | tr -s " " | cut -d ":" -f2 | cut -d " " -f1`
101 fi
102 fi
103 echo $address
104}
105
106processCheck()
107{
108 ps -ef | grep $1 | grep -v grep > /dev/null 2>/dev/null
109 if [ $? -ne 0 ]; then
110 echo "1"
111 else
112 echo "0"
113 fi
114}
115
116getMacAddress()
117{
118 if [ $BOX_TYPE = "XF3" ]; then
119 mac=`dmcli eRT getv Device.DPoE.Mac_address | grep value | awk '{print $5}'`
120 elif [ "$BOX_TYPE" = "XB6" ] || [ "$BOX_TYPE" = "TCCBR" ];then
121 mac=`dmcli eRT getv Device.X_CISCO_COM_CableModem.MACAddress | grep value | awk '{print $5}'`
122 elif [ "$BOX_TYPE" = "XF3" ]; then
123 mac=`ifconfig $WANINTERFACE | grep HWaddr | cut -d " " -f7`
124 else
125 mac=`ifconfig $WANINTERFACE | grep HWaddr | cut -d " " -f7`
126 fi
127 echo $mac
128}
129
130## Get eSTB mac address
131getErouterMacAddress()
132{
133 erouterMac=`ifconfig $WANINTERFACE | grep HWaddr | cut -d " " -f7`
134 echo $erouterMac
135}
136
137rebootFunc()
138{
139 #sync
140 reboot
141}
142
143# Return system uptime in seconds
144Uptime()
145{
146 cat /proc/uptime | awk '{ split($1,a,"."); print a[1]; }'
147}
148
149## Get Model No of the box
150getModel()
151{
152 if [ $BOX_TYPE = "XF3" ]; then
153 modelName=`grep ^imagename: /fss/gw/version.txt | cut -d ":" -f 2 | cut -d "_" -f 1`
154 else
155 modelName=`dmcli eRT getv Device.DeviceInfo.ModelName | grep value | awk '{print $5}'`
156 if [ "$modelName" = "" ]
157 then
158 modelName=`echo $MODEL_NUM`
159 fi
160 fi
161 echo "$modelName"
162}
163
164getFWVersion()
165{
166 # Handle imagename separator being colon or equals
167 grep imagename /version.txt | sed 's/.*[:=]//'
168}
169
170getBuildType()
171{
172 str=$(getFWVersion)
173
174 echo $str | grep -q 'VBN'
175 if [[ $? -eq 0 ]] ; then
176 echo 'vbn'
177 else
178 echo $str | grep -q 'PROD'
179 if [[ $? -eq 0 ]] ; then
180 echo 'prod'
181 else
182 echo $str | grep -q 'QA'
183 if [[ $? -eq 0 ]] ; then
184 echo 'qa'
185 else
186 echo 'dev'
187 fi
188 fi
189 fi
190}
191
192