From d4d189bd1e79e723dcfd133ee1ad625e16e721e3 Mon Sep 17 00:00:00 2001 From: Vlatko Dimic Date: Mon, 29 Feb 2016 15:37:20 +0100 Subject: [PATCH] Added handling of option 224 to udhcp --- iup/files/etc/init.d/iup | 6 ++-- iup/files/sbin/iup224 | 75 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 3 deletions(-) create mode 100644 iup/files/sbin/iup224 diff --git a/iup/files/etc/init.d/iup b/iup/files/etc/init.d/iup index 08d77120f..ca462707f 100755 --- a/iup/files/etc/init.d/iup +++ b/iup/files/etc/init.d/iup @@ -36,12 +36,12 @@ init_iup() { local baseopts= local reqopts="$(uci -q get network.wan.reqopts)" local proto="$(uci -q get network.wan.proto)" - local iupopts="66 67 128" + local iupopts="66 67 128 224" local ropt iopt config_get enabled iup enabled "off" for ropt in $reqopts; do case $ropt in - 66|67|128) ;; + 66|67|128|224) ;; *) baseopts="$baseopts $ropt" ;; esac done @@ -49,7 +49,7 @@ init_iup() { reqopts="$baseopts $iupopts" for ropt in $reqopts; do case $ropt in - 66|67|128) [ $enabled == "on" ] && newreqopts="$newreqopts $ropt" ;; + 66|67|128|224) [ $enabled == "on" ] && newreqopts="$newreqopts $ropt" ;; *) newreqopts="$newreqopts $ropt" ;; esac done diff --git a/iup/files/sbin/iup224 b/iup/files/sbin/iup224 new file mode 100644 index 000000000..587013611 --- /dev/null +++ b/iup/files/sbin/iup224 @@ -0,0 +1,75 @@ +#!/bin/sh + +. /usr/share/libubox/jshn.sh + +if [ -z $1 ] ; then + echo "No argument" + exit 1 +fi + +if [ $(echo $1|grep -o "," | wc -l) -eq 0 ] ; then + url=$1 +else + url=$(echo $1|cut -d',' -f1) + a=$(echo $1|cut -d',' -f2) + b=$(echo $1|cut -d',' -f3) + c=$(echo $1|cut -d',' -f4) +fi + +echo "url" $url +echo "a" $a +echo "b" $b +echo "c" $c + +currdate=$(date +"%Y-%m-%d") + +active=0 +if [ -z $a ] ; then + active=1 +elif [ $a ] && [ $b ] && [ $a -lt 25 ] ; then + #Time + begin=$(date +%s -d"$currdate $a") + now=$(date +%s) + end=$((begin+3600*$b)) + if [ $now -gt $begin ] && [ $now -lt $end ] ; then + active=1 + fi +elif [ $a ] && [ $b ] && [ $c ] && [ $a -gt 25 ] ; then + #Date + y=$(echo $a| cut -c1-4) + m=$(echo $a| cut -c5-6) + d=$(echo $a| cut -c7-8) + begin=$(date +%s -d"$y-$m-$d $b") + now=$(date +%s) + end=$((begin+3600*$c)) + if [ $now -gt $begin ] && [ $now -lt $end ] ; then + active=1 + fi +else + echo "Bad format" + exit 1 +fi + +sofwareminuspath=${url##*/} + +if [ $url ] && [ $active -eq 1 ]; then + echo "Software version to download $sofwareminuspath" + local sysinfo=$(ubus call router quest "{ \"info\": \"system\" }") + json_load "$sysinfo" + json_get_var firmware firmware + json_get_var filesystem filesystem + if [ "$filesystem" == "JFFS2" ] ; then + firmware=$firmware.w + else + firmware=$firmware.y + fi + if [ "$sofwareminuspath" == "${sofwareminuspath/$firmware/}" ] ; then + echo "Image found $url will start flashing" + /sbin/sysupgrade -v $url + else + echo "Will not update software, already up to date" + fi +fi + + +