sw-update: make sw-update robust
sw-update will now also accept nmsw images. It will search for a valid tar.gz archive.
This commit is contained in:
parent
77d75f8968
commit
d7ba3daf9f
|
|
@ -17,7 +17,8 @@ source /etc/default/sw_update_config
|
||||||
log() {
|
log() {
|
||||||
local level=${1?}
|
local level=${1?}
|
||||||
shift
|
shift
|
||||||
local code= line="[$(date '+%F %T')] $level: $*"
|
local code=
|
||||||
|
local line="[$(date '+%F %T')] $level: $*"
|
||||||
if [ -t 2 ]
|
if [ -t 2 ]
|
||||||
then
|
then
|
||||||
case "$level" in
|
case "$level" in
|
||||||
|
|
@ -190,18 +191,44 @@ check_file()
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get_bin()
|
||||||
|
{
|
||||||
|
echo $(dd if=$IMAGE_LOCATION bs=1 count=$2 skip=$1 2>/dev/null | hexdump -ve '1/1 "%.2x"')
|
||||||
|
}
|
||||||
|
|
||||||
update_linux()
|
update_linux()
|
||||||
{
|
{
|
||||||
log INFO "Starting linux update ..."
|
log INFO "Starting linux update ..."
|
||||||
check_file $1
|
check_file $1
|
||||||
|
|
||||||
#extract_header_infos
|
head=$(get_bin 0 2)
|
||||||
#check_image_compatibility
|
if [ "a$head" == "a1f8b" ]; then
|
||||||
# extract_image
|
log INFO "Found valid gzip archive"
|
||||||
|
# gzip header found, normal image
|
||||||
# Don't use the header stuff for now, move the file instead
|
# Don't use the header stuff for now, move the file instead
|
||||||
EXTRACTED_IMAGE=$IMAGE_LOCATION
|
EXTRACTED_IMAGE=$IMAGE_LOCATION
|
||||||
|
else
|
||||||
|
log INFO "Search gzip archive in image"
|
||||||
|
for i in $(seq 0 1024); do
|
||||||
|
head=$(get_bin $i 2)
|
||||||
|
if [ "a$head" == "a1f8b" ]; then
|
||||||
|
log INFO "Found gzip archive in image, extracting now"
|
||||||
|
EXTRACTED_IMAGE=$(mktemp)
|
||||||
|
dd if=$IMAGE_LOCATION bs=$i skip=1 of=$EXTRACTED_IMAGE 2>/dev/null
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
test $i -eq 1024 && echo "Could not find a vaild gzip archive" && exit -1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# This is not the original sw-update, we use plain tar.gz
|
||||||
|
# extract_header_infos
|
||||||
|
# check_image_compatibility
|
||||||
|
# extract_image
|
||||||
# Also don't check the md5 sum
|
# Also don't check the md5 sum
|
||||||
# check_image_md5
|
# check_image_md5
|
||||||
|
log INFO "Installing linux update ..."
|
||||||
|
|
||||||
flash_firmware
|
flash_firmware
|
||||||
cleanup
|
cleanup
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue