developer | 15a4331 | 2022-04-12 11:23:23 +0800 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | . /etc/include.properties |
| 3 | . /etc/device.properties |
| 4 | |
| 5 | #Utility Functions |
| 6 | #================= |
| 7 | |
| 8 | check () |
| 9 | { |
| 10 | if [ $? != 0 ]; then |
| 11 | echo "FATAL: $*" |
| 12 | sleep 10 |
| 13 | continue |
| 14 | fi |
| 15 | } |
| 16 | |
| 17 | jsonparse() { |
| 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 | |
| 30 | tftpDownload () { |
| 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 | |
| 71 | httpDownload () { |
| 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 | |
| 110 | download_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 | |
| 120 | echo "***Start of swupdate_utility.sh***" |
| 121 | |
| 122 | rebootRequired=false |
| 123 | while [ 1 ] |
| 124 | do |
| 125 | if [ $rebootRequired == true ];then |
| 126 | echo "Reboot Pending: reboot is required before possible firmware upgrade" |
| 127 | sleep 10 |
| 128 | continue |
| 129 | fi |
| 130 | #Getting update from cloud |
| 131 | #========================= |
| 132 | |
| 133 | CLOUDURL=http://35.155.171.121:9092/xconf/swu/stb?eStbMac= |
| 134 | erouterMac=`ifconfig $EROUTER_INTERFACE | grep HWaddr | cut -c39-55` |
| 135 | CLOUD_URL=$CLOUDURL$erouterMac |
| 136 | |
| 137 | echo "CLOUD_URL: $CLOUD_URL" |
| 138 | curl $CLOUD_URL -o /tmp/cloudurl.txt |
| 139 | if [ $? != 0 ];then |
| 140 | echo "curl failed to fetch firmware details: check internet connection" |
| 141 | sleep 10 |
| 142 | continue |
| 143 | fi |
| 144 | |
| 145 | #version check |
| 146 | #============= |
| 147 | |
| 148 | #Comparing image versions and will upgrade if there is a mismatch |
| 149 | currentVersion=`grep "^imagename" /version.txt | cut -d ':' -f2` |
| 150 | |
| 151 | #eg. firmwareVersion=rdkb-generic-broadband-image_default_20200608060354 |
| 152 | firmwareVersion=`jsonparse firmwareVersion` |
| 153 | cloudfirmwareversion=$firmwareVersion |
| 154 | if [ "$currentVersion" == "$cloudfirmwareversion" ]; then |
| 155 | echo "Image versions remains same !!" |
| 156 | sleep 10 |
| 157 | continue |
| 158 | fi |
| 159 | |
| 160 | echo "cloud Image version: "$cloudfirmwareversion |
| 161 | echo "Current Image version: "$currentVersion |
| 162 | echo "Image versions mismatches !! start upgrade" |
| 163 | |
| 164 | #Environment setting |
| 165 | #=================== |
| 166 | #eg. firmwareDownloadProtocol=tftp |
| 167 | firmwareDownloadProtocol=`jsonparse firmwareDownloadProtocol` |
| 168 | |
| 169 | #eg. firmwareFilename=rdkb-generic-broadband-image_default_20200608060354.tar |
| 170 | firmwareFilename=`jsonparse firmwareFilename` |
| 171 | |
| 172 | #eg. firmwareLocation=192.168.1.9 |
| 173 | firmwareLocation=`jsonparse firmwareLocation` |
| 174 | |
| 175 | #eg. rebootImmediately=false |
| 176 | rebootImmediately=`jsonparse rebootImmediately` |
| 177 | |
| 178 | download_image |
developer | cc441a0 | 2022-05-09 19:04:26 +0800 | [diff] [blame] | 179 | /lib/rdk/FilogicFwUpgrade.sh |
| 180 | check "FilogicFwUpgrade.sh failed to flash new Image" |
developer | 15a4331 | 2022-04-12 11:23:23 +0800 | [diff] [blame] | 181 | |
| 182 | if [ $rebootImmediately == true ]; then |
| 183 | reboot |
| 184 | fi |
| 185 | rebootRequired=true |
| 186 | done |