#!/bin/sh # Copyright (C) 2011-2012 Luka Perkov # Copyright (C) 2013-2014 Inteno Broadband Technology AB # Author Ahmed Zribi # Author Mohamed Kallel icwmp_fault_output() { local MSG="" local fault_code="$2" if [ "$action" = "apply_du_download" ] then local package_name="$3" local package_version="$4" fi case "$action" in *download) json_init json_add_string "fault_code" "$fault_code" if [ "$#" = "4" ] then json_add_string "package_name" "$package_name" json_add_string "package_version" "$package_version" fi json_close_object MSG=`json_dump` ;; esac echo "$MSG" } icwmp_check_image() { . /lib/functions.sh; include /lib/upgrade if [ -e /lib/upgrade/platform.sh ];then platform_check_image /tmp/firmware_upgrade_image return $? else iopsys_check_image /tmp/firmware_upgrade_image return $? fi } icwmp_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" } icwmp_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 icwmp_fault_output "" "$fault_code" else icwmp_fault_output "" "$FAULT_CPE_NO_FAULT" fi } icwmp_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 icwmp_fault_output "" "$fault_code" else icwmp_fault_output "" "$FAULT_CPE_NO_FAULT" fi } icwmp_install_package() { local fault_code="9000" var=`/bin/opkg install /tmp/du_change_state.ipk` if [ "$?" != "0" ];then rm /tmp/du_change_state.ipk 2> /dev/null let fault_code=$fault_code+$FAULT_CPE_DOWNLOAD_FAIL_FILE_CORRUPTED icwmp_fault_output "" "$fault_code" else name="`expr "$var" : 'Installing \([^(]*\)'`" version="`expr "$var" : 'Installing [^(]*(\(.*\))'`" icwmp_fault_output "" "$FAULT_CPE_NO_FAULT" "$name" "$version" fi } icwmp_update_package() { local fault_code="9000" /bin/opkg install /tmp/du_change_state.ipk if [ "$?" != "0" ];then rm /tmp/du_change_state.ipk 2> /dev/null let fault_code=$fault_code+$FAULT_CPE_DOWNLOAD_FAIL_FILE_CORRUPTED icwmp_fault_output "" "$fault_code" else icwmp_fault_output "" "$FAULT_CPE_NO_FAULT" fi } icwmp_apply_vendor_configuration() { local fault_code="9000" local current_file="/tmp/vendor_configuration_file.cfg" if [ $# -eq 0 ]; then /sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -q import < /tmp/vendor_configuration_file.cfg else current_file="/etc/vendor_configuration_file_$1.cfg" /sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -q import < /etc/vendor_configuration_file_$1.cfg rm "$current_file" 2> /dev/null fi 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 icwmp_fault_output "" "$fault_code" else icwmp_fault_output "" "$FAULT_CPE_NO_FAULT" sync reboot fi else if [ -f "$current_file" ]; then rm "$current_file" 2> /dev/null; fi let fault_code=$fault_code+$FAULT_CPE_DOWNLOAD_FAIL_FILE_CORRUPTED icwmp_fault_output "" "$fault_code" fi }