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
/
fileUploadRandom.sh
executable file
·264 lines (218 loc) · 7.08 KB
/
fileUploadRandom.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
#!/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.
##########################################################################
NVRAM2_SUPPORTED="no"
RDK_LOGGER_PATH="/rdklogger"
source $RDK_LOGGER_PATH/logfiles.sh
source $RDK_LOGGER_PATH/logUpload_default_params.sh
MAINTENANCEWINDOW="/tmp/maint_upload"
TELEMETRY_INOTIFY_FOLDER=/telemetry
TELEMETRY_INOTIFY_EVENT="$TELEMETRY_INOTIFY_FOLDER/eventType.cmd"
CRON_TAB="/var/spool/cron/crontabs/root"
DCM_PATH="/lib/rdk"
SELFHEAL_PATH="/usr/ccsp/tad"
CERT_CHECKER_PATH="/lib/rdk"
calcRandTimeandUpload()
{
rand_hr=0
rand_min=0
rand_sec=0
# Calculate random min
rand_min=`awk -v min=0 -v max=59 -v seed="$(date +%N)" 'BEGIN{srand(seed);print int(min+rand()*(max-min+1))}'`
# Calculate random second
rand_sec=`awk -v min=0 -v max=59 -v seed="$(date +%N)" 'BEGIN{srand(seed);print int(min+rand()*(max-min+1))}'`
# Calculate random hour
rand_hr=`awk -v min=0 -v max=2 -v seed="$(date +%N)" 'BEGIN{srand(seed);print int(min+rand()*(max-min+1))}'`
echo_t "RDK Logger : Random Time Generated : $rand_hr hr $rand_min min $rand_sec sec"
min_to_sleep=$(($rand_hr*60 + $rand_min))
sec_to_sleep=$(($min_to_sleep*60 + $rand_sec))
sleep $sec_to_sleep;
if [ -f "$MAINTENANCEWINDOW" ]
then
rm -rf $MAINTENANCEWINDOW
fi
# Create sys descriptor before log sync and upload
createSysDescr
touch $MAINTENANCEWINDOW
# Telemetry data should be sent before log upload
# echo_t "RDK Logger : Process Telemetry logs before log upload.."
# if [ "$DCA_MULTI_CORE_SUPPORTED" = "yes" ]
# then
# ssh root@$ATOM_INTERFACE_IP "/bin/echo 'execTelemetry' > $TELEMETRY_INOTIFY_EVENT" > /dev/null 2>&1
# This delay is to make sure that scp of all files from ARM to ATOM is done
# sleep 30
# else
# CMD=`cat $CRON_TAB | grep dca_utility | sed -e "s|.* sh|sh|g"`
# if [ "$CMD" != "" ]
# then
# echo_t "RDK Logger : Telemetry command received is #$CMD"
#"dca_utility.sh 2" is equalent to "execTelemetry" event
# sh /lib/rdk/dca_utility.sh 2 &
# We have slept enough, have a sleep of 1 more minute.
# We do not know at what time telemetry script parses the script
# let's put this 60 sec sleep
# sleep 60
# else
# echo_t "RDK Logger : DCA cron job is not configured"
# fi
# fi
# Check if nvram2 log back up is enabled
nvram2Backup="false"
backupenabled=`syscfg get logbackup_enable`
# if [ -f /etc/device.properties ]
# then
# nvram2Supported=`echo $NVRAM2_SUPPORTED`
# fi
if [ "$NVRAM2_SUPPORTED" = "yes" ] && [ "$backupenabled" = "true" ]
then
nvram2Backup="true"
else
nvram2Backup="false"
fi
echo_t "RDK Logger : Trigger Maintenance Window log upload.."
UPLOAD_LOGS=`sysevent get UPLOAD_LOGS_VAL_DCM`
if [ "$UPLOAD_LOGS" = "" ] || [ ! -f "$DCM_SETTINGS_PARSED" ]
then
echo_t "processDCMResponse to get the logUploadSettings"
UPLOAD_LOGS=`processDCMResponse`
fi
echo_t "UPLOAD_LOGS val is $UPLOAD_LOGS"
if [ "$UPLOAD_LOGS" = "true" ] || [ "$UPLOAD_LOGS" = "" ]
then
UPLOAD_LOGS="true"
if [ ! -f "/tmp/.uploadregularlogs" ]
then
echo_t "Log upload is enabled. Touching indicator in maintenance window"
touch /tmp/.uploadregularlogs
fi
else
echo_t "Log upload is disabled. Removing indicator in maintenance window"
rm -rf /tmp/.uploadregularlogs
fi
if [ "$nvram2Backup" == "true" ]; then
syncLogs_nvram2
backupnvram2logs "$TMP_UPLOAD"
else
syncLogs
backupAllLogs "$LOG_PATH" "$LOG_BACK_UP_PATH" "cp"
fi
if [ "$UPLOAD_LOGS" = "true" ]
then
$RDK_LOGGER_PATH/uploadRDKBLogs.sh $SERVER "HTTP" $URL "false"
else
echo_t "Log upload is disabled in maintenance window"
fi
upload_logfile=0
echo_t "RDKB_MEM_HEALTH : Check device memory health"
sh $SELFHEAL_PATH/check_memory_health.sh
# RDKB-6095 : DCM service should sync with XCONF daily on
# the maintenance window
if [ -f $DCM_PATH/dcm.service ];
then
echo_t "RDK Logger : Run DCM service"
if [ -f "$DCM_SETTINGS_PARSED" ]
then
rm -rf $DCM_SETTINGS_PARSED
fi
sh $DCM_PATH/dcm.service &
else
echo_t "RDK Logger : No DCM service file"
fi
# Enable RFC feature
if [ -f $DCM_PATH/rfc.service ]; then
echo_t "RDK Logger : Starting RFC service from fileUploadRandom.sh"
sh $DCM_PATH/rfc.service &
else
echo_t "RDK Logger : No RFC service file"
fi
# Log factory_programmed partnerID from XB6 platforms
if [ "$BOX_TYPE" == "XB6" ]; then
echo_t "RDK Logger : calling log_factoryPartnerId.sh"
sh $RDK_LOGGER_PATH/log_factoryPartnerId.sh &
fi
#check device certificates
if [ -x $CERT_CHECKER_PATH/rdkssacertcheck.sh ]; then
echo_t "RDK Logger : calling rdkssacertcheck.sh"
sh $CERT_CHECKER_PATH/rdkssacertcheck.sh nonotify &
fi
createSysDescr
}
## Identifies whether it is a VBN or PROD build
getBuildType()
{
IMAGENAME=$(sed -n 's/^imagename[:=]"\?\([^"]*\)"\?/\1/p' /version.txt)
TEMPDEV=`echo $IMAGENAME | grep DEV`
if [ "$TEMPDEV" != "" ]
then
echo "DEV"
fi
TEMPVBN=`echo $IMAGENAME | grep VBN`
if [ "$TEMPVBN" != "" ]
then
echo "VBN"
fi
TEMPPROD=`echo $IMAGENAME | grep PROD`
if [ "$TEMPPROD" != "" ]
then
echo "PROD"
fi
TEMPCQA=`echo $IMAGENAME | grep CQA`
if [ "$TEMPCQA" != "" ]
then
echo "CQA"
fi
}
getTFTPServer()
{
if [ "$1" != "" ]
then
logserver=`grep $1 $RDK_LOGGER_PATH/dcmlogservers.txt | cut -f2 -d"|"`
echo $logserver
fi
}
BUILD_TYPE=`getBuildType`
SERVER=`getTFTPServer $BUILD_TYPE`
loop=1
upload_logfile=1
while [ $loop -eq 1 ]
do
sleep 60
if [ "$UTC_ENABLE" == "true" ]
then
cur_hr=`LTime H | tr -dc '0-9'`
cur_min=`LTime M | tr -dc '0-9'`
else
cur_hr=`date +"%H"`
cur_min=`date +"%M"`
fi
if [ "$cur_hr" -ge "02" ] && [ "$cur_hr" -le "05" ]
then
if [ "$cur_hr" = "05" ] && [ "$cur_min" != "00" ]
then
upload_logfile=1
else
if [ "$upload_logfile" = "1" ]
then
calcRandTimeandUpload
fi
fi
else
upload_logfile=1
fi
done