mirror of
https://dev.iopsys.eu/bbf/icwmp.git
synced 2025-12-10 07:44:41 +01:00
114 lines
2.7 KiB
Bash
114 lines
2.7 KiB
Bash
#!/bin/sh
|
|
# Copyright (C) 2011-2012 Luka Perkov <freecwmp@lukaperkov.net>
|
|
# Copyright (C) 2013-2014 Inteno Broadband Technology AB
|
|
# Author Ahmed Zribi <ahmed.zribi@pivasoftware.com>
|
|
# Author Mohamed Kallel <mohamed.kallel@pivasoftware.com>
|
|
|
|
freecwmp_fault_output() {
|
|
|
|
local MSG=""
|
|
local fault_code="$2"
|
|
|
|
case "$action" in
|
|
*download)
|
|
json_init
|
|
json_add_string "fault_code" "$fault_code"
|
|
json_close_object
|
|
MSG=`json_dump`
|
|
;;
|
|
esac
|
|
|
|
echo "$MSG"
|
|
}
|
|
|
|
|
|
freecwmp_check_image()
|
|
{
|
|
. /etc/functions.sh; include /lib/upgrade; platform_check_image /tmp/firmware_upgrade_image
|
|
return $?
|
|
}
|
|
|
|
freecwmp_check_flash_size()
|
|
{
|
|
local size=0
|
|
if [ -f /proc/mtd ];then
|
|
for line in `cat /proc/mtd`
|
|
do
|
|
if [ "`echo $line|grep "^([^[:space:]]+)[[:space:]]+([^[:space:]]+)[[:space:]]+([^[:space:]]+)[[:space:]]+\"([^[:space:]]+)\""`" != "" ]
|
|
then
|
|
b=`cat $line|cut -f1 -d " "`
|
|
n=`cat $line|cut -f3 -d " "`
|
|
if [ "$n" = "\"linux\"" -o "$n" = "\"firmware\"" ];then
|
|
size=`echo $(($s))`
|
|
break;
|
|
fi
|
|
fi
|
|
done
|
|
elif [ -f /proc/partitions ]
|
|
then
|
|
for line in `cat /proc/partitions`
|
|
do
|
|
if [ "`echo $line|grep "[[:space:]]*([[:digit:]]+)[[:space:]]+([[:digit:]]+)[[:space:]]+([^[:space:]]+)[[:space:]]+([^[:space:]]+)"`" != "" ]
|
|
then
|
|
b=`cat $line|cut -f2 -d " "`
|
|
n=`cat $line|cut -f3 -d " "`
|
|
if [ checkline "([^[:space:]]+)" $n ];then
|
|
size=`let $b*1024`;
|
|
break;
|
|
fi
|
|
fi
|
|
done
|
|
fi
|
|
echo "$size"
|
|
}
|
|
|
|
freecwmp_apply_firmware()
|
|
{
|
|
local fault_code="9000"
|
|
|
|
sync
|
|
killall dropbear uhttpd; sleep 1; /sbin/sysupgrade /tmp/firmware_upgrade_image_last_valid
|
|
if [ "$?" != "0" ];then
|
|
let fault_code=$fault_code+$FAULT_CPE_DOWNLOAD_FAIL_FILE_CORRUPTED
|
|
freecwmp_fault_output "" "$fault_code"
|
|
else
|
|
freecwmp_fault_output "" "$FAULT_CPE_NO_FAULT"
|
|
fi
|
|
}
|
|
|
|
freecwmp_apply_web_content()
|
|
{
|
|
local fault_code="9000"
|
|
|
|
/bin/opkg install /tmp/web_content.ipk
|
|
if [ "$?" != "0" ];then
|
|
rm /tmp/web_content.ipk 2> /dev/null
|
|
let fault_code=$fault_code+$FAULT_CPE_DOWNLOAD_FAIL_FILE_CORRUPTED
|
|
freecwmp_fault_output "" "$fault_code"
|
|
else
|
|
freecwmp_fault_output "" "$FAULT_CPE_NO_FAULT"
|
|
fi
|
|
}
|
|
|
|
freecwmp_apply_vendor_configuration()
|
|
{
|
|
local fault_code="9000"
|
|
|
|
/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -q import < /tmp/vendor_configuration_file.cfg
|
|
if [ "$?" = "0" ];then
|
|
/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -q commit
|
|
if [ "$?" != "0" ];then
|
|
let fault_code=$fault_code+$FAULT_CPE_INTERNAL_ERROR
|
|
freecwmp_fault_output "" "$fault_code"
|
|
else
|
|
freecwmp_fault_output "" "$FAULT_CPE_NO_FAULT"
|
|
sync
|
|
reboot
|
|
fi
|
|
else
|
|
rm /tmp/vendor_configuration_file.cfg 2> /dev/null
|
|
let fault_code=$fault_code+$FAULT_CPE_DOWNLOAD_FAIL_FILE_CORRUPTED
|
|
freecwmp_fault_output "" "$fault_code"
|
|
fi
|
|
}
|
|
|