blob: 387caaf2ff6d735b0609656888a7c7e5f61d704e [file] [log] [blame]
developer15a43312022-04-12 11:23:23 +08001#!/bin/bash
2. /etc/include.properties
3. /etc/device.properties
4
5#Utility Functions
6#=================
7
8check ()
9{
10 if [ $? != 0 ]; then
11 echo "FATAL: $*"
12 sleep 10
13 continue
14 fi
15}
16
17jsonparse() {
18 if [ -d $1 ]; then
19 printf "Usage 'jsonparse <parameter-name>'\n"
20 exit 1
21 fi
22 value=`cat /tmp/cloudurl.txt | json_reformat | grep -w $1 | cut -d':' -f2 | tr -d "\",\ "`
23 if [ -d $value ];then
24 echo "FATAL: JSON value not present, check /tmp/cloudurl.txt file"
25 exit 1
26 fi
27 echo $value
28}
29
30tftpDownload () {
31 mkdir -p /tmp/tftpimage
32 cd /tmp/tftpimage
33 echo "set IPtable rules for tftp !!"
34 iptables -t raw -I OUTPUT -j CT -p udp -m udp --dport 69 --helper tftp
35 echo "CloudFile: "$firmwareFilename
36 echo "CloudLocation: "$firmwareLocation
37
38 check_sum_file="${firmwareVersion}.txt"
39 echo "Checksum file to download from tftp server: $check_sum_file"
40 tftp -g -r $check_sum_file $firmwareLocation
41 if [ ! -f $PWD/$check_sum_file ]; then
42 echo "Cloud checksum file not downloaded from TFTP: verify tftp connection($firmwareLocation)"
43 sleep 2
44 continue
45 fi
46
47 echo "Downloading $firmwareFilename..."
48 tftp -g -r $firmwareFilename $firmwareLocation
49 if [ ! -f $PWD/$firmwareFilename ]; then
50 echo "Image itself not downloaded from TFTP: verify tftp connection($firmwareLocation)"
51 sleep 2
52 continue
53 fi
54 echo "Doing additional check: comparing checksum ..."
55 cloudcsfile_path="/tmp/tftpimage/$check_sum_file"
56 echo "checksum file to download with actual path: $cloudcsfile_path"
57 cloudcs=`cat $cloudcsfile_path | cut -f 1 -d ' '`
58 echo "cloudcs:cloud download md5sum file version: $cloudcs"
59 devcs=`md5sum /tmp/tftpimage/rdk*.tar | cut -f 1 -d " "`
60 echo "devcs:image download checksum md5sum file version: $devcs"
61
62 if [ "$devcs" != "$cloudcs" ]; then
63 echo "Mismatch in md5sum: tftp file not downloaded properly"
64 continue
65 fi
66 echo "checksum verification done: md5sum matches !!"
67 tar -xf /tmp/tftpimage/$firmwareVersion.tar -C /tmp/
68 check "Failed to untar $firmwareFilename"
69}
70
71httpDownload () {
72 mkdir -p /tmp/httpimage
73 cd /tmp/httpimage
74 echo "CloudFile: "$firmwareFilename
75 echo "CloudLocation: "$firmwareLocation
76
77 check_sum_file="${firmwareVersion}.txt"
78 echo "Checksum file to download from webserver: $check_sum_file"
79 wget http://$firmwareLocation/$check_sum_file -O $check_sum_file
80 if [ ! -f $PWD/$check_sum_file ]; then
81 echo "Cloud checksum file not downloaded from Webserver: verify connection to $firmwareLocation"
82 sleep 2
83 continue
84 fi
85
86 echo "Downloading $firmwareFilename..."
87 wget http://$firmwareLocation/$firmwareFilename -O $firmwareFilename
88 if [ ! -f $PWD/$firmwareFilename ]; then
89 echo "Image itself not downloaded from Webserver: verify connection to $firmwareLocation"
90 sleep 2
91 continue
92 fi
93 echo "Doing additional check: comparing checksum ..."
94 cloudcsfile_path="/tmp/httpimage/$check_sum_file"
95 echo "checksum file to download with actual path: $cloudcsfile_path"
96 cloudcs=`cat $cloudcsfile_path | cut -f 1 -d ' '`
97 echo "cloudcs:cloud download md5sum file version: $cloudcs"
98 devcs=`md5sum /tmp/httpimage/rdk*.tar | cut -f 1 -d " "`
99 echo "devcs:image download checksum md5sum file version: $devcs"
100
101 if [ "$devcs" != "$cloudcs" ]; then
102 echo "Mismatch in md5sum: http file not downloaded properly"
103 continue
104 fi
105 echo "checksum verification done: md5sum matches !!"
106 tar -xf /tmp/httpimage/$firmwareVersion.tar -C /tmp/
107 check "Failed to untar $firmwareFilename"
108}
109
110download_image() {
111 if [ $firmwareDownloadProtocol == "tftp" ]; then
112 tftpDownload
113 elif [ $firmwareDownloadProtocol == "http" ]; then
114 httpDownload
115 else
116 echo "Unknown protocol"
117 fi
118}
119
120echo "***Start of swupdate_utility.sh***"
121
122rebootRequired=false
123while [ 1 ]
124do
125if [ $rebootRequired == true ];then
126 echo "Reboot Pending: reboot is required before possible firmware upgrade"
127 sleep 10
128 continue
129fi
130#Getting update from cloud
131#=========================
132
133CLOUDURL=http://35.155.171.121:9092/xconf/swu/stb?eStbMac=
134erouterMac=`ifconfig $EROUTER_INTERFACE | grep HWaddr | cut -c39-55`
135CLOUD_URL=$CLOUDURL$erouterMac
136
137echo "CLOUD_URL: $CLOUD_URL"
138curl $CLOUD_URL -o /tmp/cloudurl.txt
139if [ $? != 0 ];then
140 echo "curl failed to fetch firmware details: check internet connection"
141 sleep 10
142 continue
143fi
144
145#version check
146#=============
147
148#Comparing image versions and will upgrade if there is a mismatch
149currentVersion=`grep "^imagename" /version.txt | cut -d ':' -f2`
150
151#eg. firmwareVersion=rdkb-generic-broadband-image_default_20200608060354
152firmwareVersion=`jsonparse firmwareVersion`
153cloudfirmwareversion=$firmwareVersion
154if [ "$currentVersion" == "$cloudfirmwareversion" ]; then
155 echo "Image versions remains same !!"
156 sleep 10
157 continue
158fi
159
160echo "cloud Image version: "$cloudfirmwareversion
161echo "Current Image version: "$currentVersion
162echo "Image versions mismatches !! start upgrade"
163
164#Environment setting
165#===================
166#eg. firmwareDownloadProtocol=tftp
167firmwareDownloadProtocol=`jsonparse firmwareDownloadProtocol`
168
169#eg. firmwareFilename=rdkb-generic-broadband-image_default_20200608060354.tar
170firmwareFilename=`jsonparse firmwareFilename`
171
172#eg. firmwareLocation=192.168.1.9
173firmwareLocation=`jsonparse firmwareLocation`
174
175#eg. rebootImmediately=false
176rebootImmediately=`jsonparse rebootImmediately`
177
178download_image
developercc441a02022-05-09 19:04:26 +0800179/lib/rdk/FilogicFwUpgrade.sh
180check "FilogicFwUpgrade.sh failed to flash new Image"
developer15a43312022-04-12 11:23:23 +0800181
182if [ $rebootImmediately == true ]; then
183 reboot
184fi
185rebootRequired=true
186done