mirror of
https://github.com/Telecominfraproject/wlan-ap.git
synced 2025-12-17 17:31:27 +00:00
102 lines
2.8 KiB
Bash
Executable File
102 lines
2.8 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
# Copyright (c) 2015, Plume Design Inc. All rights reserved.
|
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
# modification, are permitted provided that the following conditions are met:
|
|
# 1. Redistributions of source code must retain the above copyright
|
|
# notice, this list of conditions and the following disclaimer.
|
|
# 2. Redistributions in binary form must reproduce the above copyright
|
|
# notice, this list of conditions and the following disclaimer in the
|
|
# documentation and/or other materials provided with the distribution.
|
|
# 3. Neither the name of the Plume Design Inc. nor the
|
|
# names of its contributors may be used to endorse or promote products
|
|
# derived from this software without specific prior written permission.
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
# DISCLAIMED. IN NO EVENT SHALL Plume Design Inc. BE LIABLE FOR ANY
|
|
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
if [ -z "$1" ] || [ ! -f "$1" ] ; then
|
|
echo
|
|
echo "Usage $0: Require firmware tarfile"
|
|
exit 1
|
|
fi
|
|
|
|
TARFILE=$1
|
|
TMPDIR=/tmp/tmpdir
|
|
UPGFILE1="upgrade.bin"
|
|
UPGFILE2="upgrade.tar"
|
|
|
|
if tar tf $TARFILE 2> /dev/null 1>&2; then
|
|
TARCMD="/bin/tar -xf"
|
|
TARTOC="/bin/tar -tf"
|
|
else
|
|
TARCMD="/bin/tar -xzf"
|
|
TARTOC="/bin/tar -tzf"
|
|
fi
|
|
|
|
# Extract tar.gz
|
|
cd /tmp
|
|
mkdir -p $TMPDIR
|
|
IMGFILE=$($TARTOC $TARFILE | grep sysupgrade)
|
|
echo Image file is $IMGFILE
|
|
$TARCMD $TARFILE -C $TMPDIR $IMGFILE
|
|
|
|
if [ "$?" != "0" ] ; then
|
|
rm $TARFILE
|
|
rm -fr $TMPDIR
|
|
exit 1
|
|
fi
|
|
|
|
SHAFILE=$($TARTOC $TARFILE | grep sha256sums)
|
|
echo SHA file is $SHAFILE
|
|
$TARCMD $TARFILE -C $TMPDIR $SHAFILE
|
|
if [ "$?" != "0" ] ; then
|
|
rm $TARFILE
|
|
rm -fr $TMPDIR
|
|
exit 1
|
|
fi
|
|
rm $TARFILE
|
|
|
|
cd $TMPDIR
|
|
if [ ! -f "$IMGFILE" ] && [ ! -f "$SHAFILE" ] ; then
|
|
echo "$0: Image or checksum file does not exist"
|
|
cd /tmp
|
|
rm -fr $TMPDIR
|
|
exit 1
|
|
fi
|
|
EXT=${IMGFILE##*.}
|
|
|
|
# Validate checksum
|
|
cat $SHAFILE | grep $IMGFILE>reqd_sum
|
|
sha256sum -c reqd_sum 2>/dev/null|grep OK
|
|
if [ "$?" != "0" ] ; then
|
|
echo "$0: Validation failed."
|
|
cd /tmp
|
|
rm -fr $TMPDIR
|
|
exit 1
|
|
fi
|
|
|
|
if [ "$EXT" == "bin" ] ; then
|
|
cp $IMGFILE /tmp/$UPGFILE1
|
|
elif [ "$EXT" == "tar" ] ; then
|
|
cp $IMGFILE /tmp/$UPGFILE2
|
|
else
|
|
echo "$IMGFILE type unsupported"
|
|
cd /tmp
|
|
rm -fr $TMPDIR
|
|
exit 1
|
|
fi
|
|
cd /tmp
|
|
rm -fr $TMPDIR
|
|
exit 0
|