This repository has been archived by the owner on Jan 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
DCMscript.sh
executable file
·747 lines (660 loc) · 25.4 KB
/
DCMscript.sh
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
#!/bin/sh
##########################################################################
# If not stated otherwise in this file or this component's Licenses.txt
# file the following copyright and licenses apply:
#
# Copyright 2016 RDK Management
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
##########################################################################
#
. /etc/include.properties
. /etc/device.properties
if [ -f /etc/telemetry2_0.properties ]; then
. /etc/telemetry2_0.properties
fi
if [ -f /etc/waninfo.sh ]; then
. /etc/waninfo.sh
EROUTER_INTERFACE=$(getWanInterfaceName)
fi
source /etc/log_timestamp.sh
source /lib/rdk/getpartnerid.sh
source /lib/rdk/getaccountid.sh
source /lib/rdk/t2Shared_api.sh
CERT=""
if [ -f $RDK_PATH/mtlsUtils.sh ]; then
. $RDK_PATH/mtlsUtils.sh
echo_t "DCMscript.sh calling getMtlsCreds"
CERT="`getMtlsCreds DCMscript.sh`"
fi
# Enable override only for non prod builds
if [ "$BUILD_TYPE" != "prod" ] && [ -f $PERSISTENT_PATH/dcm.properties ]; then
. $PERSISTENT_PATH/dcm.properties
else
. /etc/dcm.properties
fi
if [ -f /lib/rdk/utils.sh ]; then
. /lib/rdk/utils.sh
fi
if [ -f /etc/mount-utils/getConfigFile.sh ];then
. /etc/mount-utils/getConfigFile.sh
fi
SIGN_FILE="/tmp/.signedRequest_$$_`date +'%s'`"
CODEBIG_BLOCK_TIME=1800
CODEBIG_BLOCK_FILENAME="/tmp/.lastcodebigfail_dcm"
FORCE_DIRECT_ONCE="/tmp/.forcedirectonce_dcm"
export PATH=$PATH:/usr/bin:/bin:/usr/local/bin:/sbin:/usr/local/lighttpd/sbin:/usr/local/sbin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib:/lib
partnerId=$(getPartnerId)
DIRECT_MAX_ATTEMPTS=3
CODEBIG_MAX_ATTEMPTS=3
if [ -z $LOG_PATH ]; then
LOG_PATH="$PERSISTENT_PATH/logs"
fi
if [ -z $PERSISTENT_PATH ]; then
PERSISTENT_PATH="/tmp"
fi
TELEMETRY_PATH="$PERSISTENT_PATH/.telemetry"
T2_XCONF_PERSISTENT_PATH="$PERSISTENT_PATH/.t2persistentfolder"
T2_BULK_PERSISTENT_PATH="$PERSISTENT_PATH/.t2reportprofiles"
DCMFLAG="/tmp/.DCMSettingsFlag"
DCM_LOG_FILE="$LOG_PATH/dcmscript.log"
TELEMETRY_INOTIFY_FOLDER="/telemetry"
TELEMETRY_INOTIFY_EVENT="$TELEMETRY_INOTIFY_FOLDER/eventType.cmd"
DCMRESPONSE="$PERSISTENT_PATH/DCMresponse.txt"
T2_RESPONSE="$T2_XCONF_PERSISTENT_PATH/DCMresponse.txt"
TELEMETRY_TEMP_RESEND_FILE="$PERSISTENT_PATH/.temp_resend.txt"
FWDL_FLAG="/tmp/.fwdl_flag"
useStaticXpkiMtlsLogupload="false"
FORMATTED_TMP_DCM_RESPONSE='/tmp/DCMSettings.conf'
DEFAULT_REPORT_FILE="/etc/Default_T2_ReportProfile.json"
#to support ocsp
EnableOCSPStapling="/tmp/.EnableOCSPStapling"
EnableOCSP="/tmp/.EnableOCSPCA"
if [ -f $EnableOCSPStapling ] || [ -f $EnableOCSP ]; then
CERT_STATUS="--cert-status"
fi
PEER_COMM_ID="/tmp/elxrretyt-dcm.swr"
if [ ! -f /usr/bin/GetConfigFile ];then
echo "Error: GetConfigFile Not Found"
exit 127
fi
IDLE_TIMEOUT=30
# http header
HTTP_HEADERS='Content-Type: application/json'
## RETRY DELAY in secs
RETRY_DELAY=60
MAX_SSH_RETRY=3
if [ "x$BOX_TYPE" = "xSR300" ] ;then
while :
do
WAN_STATUS=$(sysevent get wan-status)
NTP_STATUS=$(timedatectl | grep "NTP service" | awk -F": " '{print $2}')
if [ "$WAN_STATUS" = "started" ] && [ "$NTP_STATUS" = "active" ]; then
echo_t "wan is up and ntp has been started" >> "$DCM_LOG_FILE"
break
fi
echo_t "Waiting for wan to be up and ntp sync..." >> "$DCM_LOG_FILE"
sleep 3
done
fi
echo_t "Starting execution of DCMscript.sh" >> $DCM_LOG_FILE
if [ $# -ne 5 ]; then
echo_t "Argument does not match" >> $DCM_LOG_FILE
echo 0 > $DCMFLAG
exit 1
fi
#---------------------------------
# Initialize Variables
#---------------------------------
URL=$2
tftp_server=$3
reboot_flag=$4
checkon_reboot=$5
echo_t "URL: $URL" >> $DCM_LOG_FILE
echo_t "DCM_TFTP_SERVER: $tftp_server" >> $DCM_LOG_FILE
echo_t "BOOT_FLAG: $reboot_flag" >> $DCM_LOG_FILE
echo_t "CHECK_ON_REBOOT: $checkon_reboot" >> $DCM_LOG_FILE
rm -f $TELEMETRY_TEMP_RESEND_FILE
conn_str="Direct"
CodebigAvailable=0
UseCodeBig=0
#Partner sky-uk should impose MTLS only connection
if [ "$DEVICE_TYPE" = "broadband" ] && [ "$partnerId" = "sky-uk" ]
then
echo_t "Check MTLS only for partner sky-uk"
if [ "$CERT" = "" ]
then
echo_t "DCMscript getMtlsCreds failed for sky-uk. Exiting"
exit
else
echo_t "DCMscript getMtlsCreds returned $CERT"
fi
else
echo_t "DCMscript getMtlsCreds returned $CERT"
fi
sshCmdOnAtom() {
command=$1
if [ ! -f $PEER_COMM_ID ]; then
GetConfigFile $PEER_COMM_ID
fi
count=0
isCmdExecFail="true"
while [ $count -lt $MAX_SSH_RETRY ]
do
ssh -I $IDLE_TIMEOUT -i $PEER_COMM_ID root@$ATOM_INTERFACE_IP "echo $command > $TELEMETRY_INOTIFY_EVENT" > /dev/null 2>&1
ret=$?
if [ $ret -ne 0 ]; then
echo_t "$count : SSH failure to ATOM for $command.Retrying..." >> $RTL_LOG_FILE
sleep 10
else
count=$MAX_SSH_RETRY
isCmdExecFail="false"
fi
count=$((count + 1))
done
if [ "x$isCmdExecFail" == "xtrue" ]; then
echo_t "Failed to exec command $command on atom " >> $RTL_LOG_FILE
fi
}
# This override doesn't happen during device bootup
if [ -f $DCMRESPONSE ]; then
Check_URL=`grep 'urn:settings:ConfigurationServiceURL' $DCMRESPONSE | cut -d '=' -f2 | head -n 1`
if [ -n "$Check_URL" ]; then
URL=`grep 'urn:settings:ConfigurationServiceURL' $DCMRESPONSE | cut -d '=' -f2 | sed 's/^"//' | sed 's/"$//' | head -n 1`
#last_char=`echo $URL | sed -e 's/\(^.*\)\(.$\)/\2/'`
last_char=`echo $URL | awk '$0=$NF' FS=`
if [ "$last_char" != "?" ]; then
URL="$URL?"
fi
fi
fi
# File to save curl response
#FILENAME="$PERSISTENT_PATH/DCMresponse.txt"
# File to save http code
# Timeout value
timeout=30
default_IP=$DEFAULT_IP
upload_protocol='TFTP'
upload_httplink=$HTTP_UPLOAD_LINK
if [ -f /tmp/DCMSettings.conf ]; then
upload_httplink=`grep 'LogUploadSettings:UploadRepository:URL' /tmp/DCMSettings.conf | cut -d '=' -f2`
if [ -z "$upload_httplink" ]; then
echo_t "upload_httplink urn:settings:LogUploadSettings:UploadRepository' is not found in DCMSettings.conf"
upload_httplink=$HTTP_UPLOAD_LINK
else
echo_t "upload_httplink is $upload_httplink in DCMSettings.conf"
fi
fi
## Get Receiver Id
getReceiverId()
{
if [ -f "$PERSISTENT_PATH/www/whitebox/wbdevice.dat" ]
then
ReceiverId=`cat $PERSISTENT_PATH/www/whitebox/wbdevice.dat`
echo "$ReceiverId"
else
echo " "
fi
}
## Get Controller Id
getControllerId()
{
echo "2504"
}
## Get ChannelMap Id
getChannelMapId()
{
echo "2345"
}
## Get VOD Id
getVODId()
{
echo "15660"
}
IsCodebigBlocked()
{
ret=0
if [ -f $CODEBIG_BLOCK_FILENAME ]; then
modtime=$(($(date +%s) - $(date +%s -r $CODEBIG_BLOCK_FILENAME)))
if [ "$modtime" -le "$CODEBIG_BLOCK_TIME" ]; then
echo "DCM: Last Codebig failed blocking is still valid, preventing Codebig" >> $DCM_LOG_FILE
ret=1
else
echo "DCM: Last Codebig failed blocking has expired, removing $CODEBIG_BLOCK_FILENAME, allowing Codebig" >> $DCM_LOG_FILE
rm -f $CODEBIG_BLOCK_FILENAME
ret=0
fi
fi
return $ret
}
# Get the configuration of codebig settings
get_Codebigconfig()
{
# If GetServiceUrl not available, then only direct connection available and no fallback mechanism
if [ -f /usr/bin/GetServiceUrl ]; then
CodebigAvailable=1
fi
if [ "$CodebigAvailable" -eq "1" ]; then
CodeBigEnable=`dmcli eRT getv Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.CodeBigFirst.Enable | grep true 2>/dev/null`
fi
if [ -f $FORCE_DIRECT_ONCE ]; then
rm -f $FORCE_DIRECT_ONCE
echo_t "Xconf dcm : Last Codebig attempt failed, forcing direct once" >> $DCM_LOG_FILE
elif [ "$CodebigAvailable" -eq "1" ] && [ "x$CodeBigEnable" != "x" ] ; then
UseCodeBig=1
conn_str="Codebig"
fi
if [ "$CodebigAvailable" -eq "1" ]; then
echo_t "Xconf dcm : Using $conn_str connection as the Primary" >> $DCM_LOG_FILE
else
echo_t "Xconf dcm : Only $conn_str connection is available" >> $DCM_LOG_FILE
fi
}
# Direct connection Download function
useDirectRequest()
{
tmpHttpResponse="/tmp/dcmResponse$$.txt"
count=0
while [ "$count" -lt "$DIRECT_MAX_ATTEMPTS" ] ; do
echo_t " DCM connection type DIRECT"
if [ -f /etc/waninfo.sh ]; then
EROUTER_INTERFACE=$(getWanInterfaceName)
fi
CURL_CMD="curl $CERT -w '%{http_code}\n' --tlsv1.2 --interface $EROUTER_INTERFACE $addr_type $CERT_STATUS --connect-timeout $timeout -m $timeout -o \"$tmpHttpResponse\" '$HTTPS_URL$JSONSTR'"
HTTP_CODE=`result= eval $CURL_CMD`
ret=$?
CURL_CMD=`echo "$CURL_CMD" | sed 's/devicecert_1.* /devicecert_1.pk12<hidden key>/' | sed 's/staticXpkiCr.* /staticXpkiCrt.pk12<hidden key>/'`
echo_t "CURL_CMD: $CURL_CMD" >> $DCM_LOG_FILE
sleep 2
http_code=$(echo "$HTTP_CODE" | awk -F\" '{print $1}' )
[ "x$http_code" != "x" ] || http_code=0
echo_t "ret = $ret http_code: $http_code" >> $DCM_LOG_FILE
# log security failure
case $ret in
35|51|53|54|58|59|60|64|66|77|80|82|83|90|91)
echo_t "DCM: HTTPS for --tlsv1.2 failed to connect to DCM XCONF server with curl error code:$ret" >> $DCM_LOG_FILE
t2ValNotify "DCMXCONFCurlFail_split" "$ret"
;;
esac
if [ $http_code -eq 200 ]; then
echo_t "Direct connection success - ret:$ret http_code:$http_code" >> $DCM_LOG_FILE
rm -f $PERSISTENT_PATH/DCMresponse.txt*
mv $tmpHttpResponse $FILENAME
return 0
elif [ $http_code -eq 404 ]; then
echo "`Timestamp` Direct connection Received HTTP $http_code Response from Xconf Server. Retry logic not needed" >> $DCM_LOG_FILE
rm -f $tmpHttpResponse
bypass_conn=1
return 0 # Do not return 1, if retry for next conn type is not to be done
else
if [ "$ret" -eq 0 ]; then
echo_t "DCM Direct Connection Failure Attempt:$count - ret:$ret http_code:$http_code" >> $DCM_LOG_FILE
fi
fi
rm -f $tmpHttpResponse
count=$((count + 1))
sleep $RETRY_DELAY
done
echo_t "DCM :Retries for Direct connection exceeded " >> $DCM_LOG_FILE
return 1
}
# Codebig connection Download function
useCodebigRequest()
{
# Do not try Codebig if CodebigAvailable != 1 (GetServiceUrl not there)
if [ "$CodebigAvailable" -eq "0" ] ; then
echo "DCM : Only direct connection Available" >> $DCM_LOG_FILE
return 1
fi
tmpHttpResponse="/tmp/dcmResponse$$.txt"
IsCodebigBlocked
if [ "$?" -eq "1" ]; then
return 1
fi
count=0
retries=0
while [ "$count" -lt "$CODEBIG_MAX_ATTEMPTS" ] ; do
if [ -f /etc/waninfo.sh ]; then
EROUTER_INTERFACE=$(getWanInterfaceName)
fi
SIGN_CMD="GetServiceUrl 3 \"$JSONSTR\""
eval $SIGN_CMD > $SIGN_FILE
CB_SIGNED_REQUEST=`cat $SIGN_FILE`
rm -f $SIGN_FILE
CURL_CMD="curl -w '%{http_code}\n' --tlsv1.2 --interface $EROUTER_INTERFACE $addr_type $CERT_STATUS --connect-timeout $timeout -m $timeout -o \"$tmpHttpResponse\" \"$CB_SIGNED_REQUEST\""
echo_t " DCM connection type CODEBIG at `echo "$CURL_CMD" | sed -ne 's#.*\(https:.*\)?.*#\1#p'`" >> $DCM_LOG_FILE
echo_t "CURL_CMD: `echo "$CURL_CMD" | sed -ne 's#oauth_consumer_key=.*#<hidden>#p'`" >> $DCM_LOG_FILE
HTTP_CODE=`result= eval $CURL_CMD`
curlret=$?
http_code=$(echo "$HTTP_CODE" | awk -F\" '{print $1}' )
[ "x$http_code" != "x" ] || http_code=0
echo_t "ret = $curlret http_code: $http_code" >> $DCM_LOG_FILE
# log security failure
case $curlret in
35|51|53|54|58|59|60|64|66|77|80|82|83|90|91)
echo_t "DCM: HTTPS --tlsv1.2 failed to connect to DCM Codebig server with curl error code:$curlret" >> $DCM_LOG_FILE
t2ValNotify "DCMCBCurlFail_split" "$curlret"
;;
esac
if [ "$http_code" -eq 200 ]; then
echo_t "Codebig connection success - ret:$curlret http_code:$http_code" >> $DCM_LOG_FILE
rm -f $PERSISTENT_PATH/DCMresponse.txt*
mv $tmpHttpResponse $FILENAME
return 0
elif [ "$http_code" -eq 404 ]; then
echo_t "DCM Codebig connection Received HTTP $http_code Response from Xconf Server. Retry logic not needed" >> $DCM_LOG_FILE
bypass_conn=1
rm -f $tmpHttpResponse
return 0 # Do not return 1, if retry for next conn type is not to be done
else
if [ "$curlret" -eq 0 ]; then
echo_t "DCM Codebig Connection Failure Attempt:$count - ret:$curlret http_code:$http_code" >> $DCM_LOG_FILE
fi
fi
rm -f $tmpHttpResponse
if [ "$retries" -lt "$CODEBIG_MAX_ATTEMPTS" ]; then
if [ "$retries" -eq "0" ]; then
sleep 10
else
sleep 30
fi
fi
count=$((count + 1))
done
echo_t "Retries for Codebig connection exceeded " >> $DCM_LOG_FILE
[ -f $CODEBIG_BLOCK_FILENAME ] || touch $CODEBIG_BLOCK_FILENAME
touch $FORCE_DIRECT_ONCE
return 1
}
# Output file from this processing is used by :
# 1] RFC module - RFCBase.sh
# 2] Firmware upgrade module - firmwareSched.sh
processJsonResponse()
{
if [ -f "$DCMRESPONSE" ]
then
# Do not use persistent locations with inline stream edit operators
tmpConfigFile="/tmp/dcm$$.txt"
cp $DCMRESPONSE $tmpConfigFile
sed -i 's/,"urn:/\n"urn:/g' $tmpConfigFile # Updating the file by replacing all ',"urn:' with '\n"urn:'
sed -i 's/^{//g' $tmpConfigFile # Delete first character from file '{'
sed -i 's/}$//g' $tmpConfigFile # Delete first character from file '}'
echo "" >> $tmpConfigFile # Adding a new line to the file
cat /dev/null > $FORMATTED_TMP_DCM_RESPONSE # empty old file
while read line
do
# Parse the settings by
# 1) Replace the '":' with '='
# 2) Updating the result in a output file
profile_Check=`echo "$line" | grep -ci 'TelemetryProfile'`
if [ $profile_Check -ne 0 ];then
echo "$line" | sed 's/"header":"/"header" : "/g' | sed 's/"content":"/"content" : "/g' | sed 's/"type":"/"type" : "/g' >> $FORMATTED_TMP_DCM_RESPONSE
else
echo "$line" | sed 's/":/=/g' | sed 's/"//g' >> $FORMATTED_TMP_DCM_RESPONSE
fi
done < $tmpConfigFile
rm -f $tmpConfigFile
else
echo "$DCMRESPONSE not found." >> $LOG_PATH/dcmscript.log
fi
}
sendHttpRequestToServer()
{
resp=0
FILENAME=$1
URL=$2
# If interface doesnt have ipv6 address then we will force the curl to go with ipv4.
# Otherwise we will not specify the ip address family in curl options
if [ "x$BOX_TYPE" = "xHUB4" ] || [ "x$BOX_TYPE" = "xSR300" ] || [ "x$BOX_TYPE" = "xSR213" ] || [ "x$BOX_TYPE" = "xSE501" ] || [ "x$BOX_TYPE" = "xWNXL11BWL" ]; then
addr_type=""
else
addr_type=""
[ "x`ifconfig $EROUTER_INTERFACE | grep inet6 | grep -i 'Global'`" != "x" ] || addr_type="-4"
fi
partnerId=$(getPartnerId)
accountId=$(getAccountId)
JSONSTR='estbMacAddress='$(getErouterMacAddress)'&firmwareVersion='$(getFWVersion)'&env='$(getBuildType)'&model='$(getModel)'&partnerId='${partnerId}'&accountId='${accountId}'&ecmMacAddress='$(getMacAddress)'&controllerId='$(getControllerId)'&channelMapId='$(getChannelMapId)'&vodId='$(getVODId)'&version=2'
last_char=`echo $URL | awk '$0=$NF' FS=`
if [ "$last_char" != "?" ]; then
URL="$URL?"
fi
get_Codebigconfig
#Retrieve protocol from current URL
PROTO=`echo $URL | cut -d ":" -f1`
#Replace the current protocol with https
HTTPS_URL=`echo $URL | sed "s/$PROTO/https/g"`
bypass_conn=0
if [ "$UseCodeBig" -eq "1" ]; then
useCodebigRequest
ret=$?
else
useDirectRequest
ret=$?
fi
if [ "$ret" -ne "0" ]; then
echo_t "Failed: Unable to do Connection" >> $DCM_LOG_FILE
return 1
fi
if [ "$bypass_conn" -eq 1 ]; then
return 1
fi
echo_t "HTTP request success. Processing response.." >> $DCM_LOG_FILE
return 0
}
dropbearRecovery()
{
DROPBEAR_PID_FILE="/var/run/dropbear_ipc.pid"
restart_dropbear=1
if [ -f $DROPBEAR_PID_FILE ];then
dropbearPid=`cat $DROPBEAR_PID_FILE`
if [ -d /proc/$dropbearPid ];then
restart_dropbear=0
fi
fi
if [ $restart_dropbear -eq 1 ]; then
echo_t "Dropbear instance is missing ... Recovering dropbear !!! " >> $DCM_LOG_FILE
DROPBEAR_PARAMS_1="/tmp/.dropbear/dropcfg1_dcmscript"
DROPBEAR_PARAMS_2="/tmp/.dropbear/dropcfg2_dcmscript"
if [ ! -d '/tmp/.dropbear' ]; then
echo_t "wan_ssh.sh: need to create dropbear dir !!! " >> $DCM_LOG_FILE
mkdir -p /tmp/.dropbear
fi
echo_t "wan_ssh.sh: need to create dropbear files !!! " >> $DCM_LOG_FILE
if [ ! -f $DROPBEAR_PARAMS_1 ]; then
getConfigFile $DROPBEAR_PARAMS_1
fi
if [ ! -f $DROPBEAR_PARAMS_2 ]; then
getConfigFile $DROPBEAR_PARAMS_2
fi
dropbear -r $DROPBEAR_PARAMS_1 -r $DROPBEAR_PARAMS_2 -E -s -p $ARM_INTERFACE_IP:22 -P $DROPBEAR_PID_FILE > /dev/null 2>&1 &
sleep 2
fi
}
T2_ENABLE=`syscfg get T2Enable`
# Safe wait for IP acquisition
if [ "$T2_enable" = "false" ]; then
loop=1
counter=0
while [ $loop -eq 1 ]
do
estbIp=`getErouterIPAddress` # This needs to be changed to wait for erouter IP address
if [ "X$estbIp" == "X" ]; then
echo_t "waiting for IP" >> $DCM_LOG_FILE
sleep 2
let counter++
else
loop=0
fi
done
fi
TELEMETRY_PATH_TEMP="$TELEMETRY_PATH/tmp"
t2Log() {
timestamp=`date +%Y-%b-%d_%H-%M-%S`
echo "$0 : $timestamp $*" >> $T2_0_LOGFILE
}
# Check for RFC Telemetry.Enable settings
# Internal syscfg database used by RFC parameter - Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.Telemetry.Enable
t2Log "RFC value for Telemetry 2.0 Enable is $T2_ENABLE ."
if [ ! -f $T2_0_BIN ]; then
t2Log "Unable to find $T2_0_BIN ... Switching T2 Enable to false !!!"
T2_ENABLE="false"
fi
if [ "x$T2_ENABLE" == "xtrue" ]; then
t2Pid=`pidof $T2_0_APP`
if [ -z "$t2Pid" ]; then
echo "${T2_BIN} is present, XCONF config fetch and parse will be handled by T2 implementation" >> $DCM_LOG_FILE
t2Log "Clearing markers from $TELEMETRY_PATH"
rm -rf $TELEMETRY_PATH
mkdir -p $TELEMETRY_PATH
mkdir -p $TELEMETRY_PATH_TEMP
mkdir -p $T2_XCONF_PERSISTENT_PATH
t2Log "Starting $T2_0_BIN daemon."
${T2_0_BIN}
MAX_RETRY_T2_REPORT=10
count=0
if [ -f $DEFAULT_REPORT_FILE ]; then
while [ ! -f /tmp/.t2ReadyToReceiveEvents ]
do
echo_t "Wait for T2 to Receive Events"
sleep 10
let count++
if [ $count -eq $MAX_RETRY_T2_REPORT ]; then
break
fi
done
ReportProfiles=`dmcli eRT getv Device.X_RDKCENTRAL-COM_T2.ReportProfiles | grep string | cut -d":" -f3- | cut -d" " -f2- | xargs`
MsgPackProfiles=`dmcli eRT getv Device.X_RDKCENTRAL-COM_T2.ReportProfilesMsgPack | grep string | cut -d":" -f3- | cut -d" " -f2- | xargs`
if [ -z "$ReportProfiles" ] && [ -z "$MsgPackProfiles" ]; then
ReportProfiles=`cat /etc/Default_T2_ReportProfile.json`
echo_t "Default Report Profile Applied to T2" >> $DCM_LOG_FILE
dmcli eRT setv Device.X_RDKCENTRAL-COM_T2.ReportProfiles string "$ReportProfiles"
fi
fi
else
mkdir -p $TELEMETRY_PATH_TEMP
t2Log "telemetry daemon is already running .. Trigger from maintenance window."
t2Log "Send signal 15 $T2_0_APP to restart for config fetch "
kill -12 $t2Pid
fi
## Clear any dca_utility.sh cron entries if present from T1.1 previous execution
tempfile="/tmp/tempfile$$.txt"
rm -rf $tempfile # Delete temp file if existing
crontab -l -c $CRON_SPOOL > $tempfile
# Check whether any cron jobs are existing or not
existing_cron_check=`cat $tempfile | tail -n 1`
if [ -n "$existing_cron_check" ]; then
rtl_cron_check=`grep -c 'dca_utility.sh' $tempfile`
if [ $rtl_cron_check -ne 0 ]; then
# delete entry
sed -i '/dca_utility/d' $tempfile
# Set new cron job from the file
crontab $tempfile -c $CRON_SPOOL
fi
fi
rm -rf $tempfile
# Refer to config downloaded from telemetry version 2.0 to avoid additional persistent storage usage
if [ ! -L $DCMRESPONSE ]; then
echo_t "Remove config from DCA $DCMRESPONSE and create symlink to $T2_RESPONSE" >> $DCM_LOG_FILE
# Clear persistent file from DCA execution
rm -f $DCMRESPONSE
touch $T2_RESPONSE
ln -s $T2_RESPONSE $DCMRESPONSE
fi
# Dependent modules should still get the parsed /tmp/DCMSettings.conf file
processJsonResponse
isPeriodicFWCheckEnabled=`syscfg get PeriodicFWCheck_Enable`
if [ "$isPeriodicFWCheckEnabled" == "true" ]; then
# bypassing firmwareSched.sh once on boot up because it is called from xconf
if [ ! -f $FWDL_FLAG ]; then
touch $FWDL_FLAG
echo_t "XCONF SCRIPT : Ignoring running firmwareSched.sh on bootup from dcm script" >> $DCM_LOG_FILE
else
echo_t "XCONF SCRIPT : Calling XCONF Client firmwareSched for the updated time" >> $DCM_LOG_FILE
sh /etc/firmwareSched.sh DCM_Trigger &
fi
fi
exit 0
fi
ret=1
if [ "$DEVICE_TYPE" != "mediaclient" ] && [ "$estbIp" == "$default_IP" ] ; then
ret=0
fi
if [ $checkon_reboot -eq 1 ]; then
# Clear response from telemetry 2.0 configs from persistent location with previous execution to avoid high persistent location usage
if [ -d "$T2_XCONF_PERSISTENT_PATH" ]; then
rm -rf $T2_XCONF_PERSISTENT_PATH
fi
if [ -d "$T2_BULK_PERSISTENT_PATH" ]; then
rm -rf $T2_BULK_PERSISTENT_PATH
fi
if [ -L "$DCMRESPONSE" ]; then
echo_t "Remove symbolic link from telemetry 2.0 execution " >> $DCM_LOG_FILE
rm -f $DCMRESPONSE
fi
sendHttpRequestToServer $DCMRESPONSE $URL
ret=$?
echo_t "sendHttpRequestToServer returned $ret" >> $DCM_LOG_FILE
else
ret=0
echo_t "sendHttpRequestToServer has not executed since the value of 'checkon_reboot' is $checkon_reboot" >> $DCM_LOG_FILE
fi
sleep 5
if [ $ret -ne 0 ]; then
echo_t "Config fetch failed." >> $DCM_LOG_FILE
echo_t "count = $count. Sleeping $RETRY_DELAY seconds ..." >> $DCM_LOG_FILE
if [ ! -f "$DCMRESPONSE" ]; then
echo "Unable to locate previous downloaded settings $DCMRESPONSE ... Exiting !!! " >> $DCM_LOG_FILE
echo_t "Processing response failed." >> $DCM_LOG_FILE
exit 1
fi
fi
# RFC and Firmware download scheduler depends on parsed DCM response file
processJsonResponse
if [ "x$DCA_MULTI_CORE_SUPPORTED" == "xyes" ]; then
dropbearRecovery
isPeriodicFWCheckEnabled=`syscfg get PeriodicFWCheck_Enable`
if [ "$isPeriodicFWCheckEnabled" == "true" ]; then
# bypassing firmwareSched.sh once on boot up because it is called from xconf
if [ ! -f $FWDL_FLAG ]; then
touch $FWDL_FLAG
echo_t "XCONF SCRIPT : Ignoring running firmwareSched.sh on bootup from dcm script" >> $DCM_LOG_FILE
else
echo_t "XCONF SCRIPT : Calling XCONF Client firmwareSched for the updated time" >> $DCM_LOG_FILE
sh /etc/firmwareSched.sh DCM_Trigger &
fi
fi
if [ ! -f $PEER_COMM_ID ]; then
GetConfigFile $PEER_COMM_ID
fi
scp -i $PEER_COMM_ID $DCMRESPONSE root@$ATOM_INTERFACE_IP:$PERSISTENT_PATH > /dev/null 2>&1
if [ $? -ne 0 ]; then
scp -i $PEER_COMM_ID $DCMRESPONSE root@$ATOM_INTERFACE_IP:$PERSISTENT_PATH > /dev/null 2>&1
fi
echo "Signal atom to pick the XCONF config data $DCMRESPONSE and schedule telemetry !!! " >> $DCM_LOG_FILE
## Trigger an inotify event on ATOM
sshCmdOnAtom 'xconf_update'
else
isPeriodicFWCheckEnabled=`syscfg get PeriodicFWCheck_Enable`
if [ "$isPeriodicFWCheckEnabled" == "true" ]; then
# bypassing firmwareSched.sh once on boot up because it is called from xconf
if [ ! -f $FWDL_FLAG ]; then
touch $FWDL_FLAG
echo_t "XCONF SCRIPT : Ignoring running firmwareSched.sh on bootup from dcm script" >> $DCM_LOG_FILE
else
echo_t "XCONF SCRIPT : Calling XCONF Client firmwareSched for the updated time" >> $DCM_LOG_FILE
sh /etc/firmwareSched.sh DCM_Trigger
fi
fi
sh /lib/rdk/dca_utility.sh 1 &
fi