premier commit (version 105)
[ipphone-tools.git] / ipphone5-auto-upgrade
1 #!/bin/sh
2 DIR="/usr/share/ipphone-tools/firmware"
3 FIRMWARE="ipphone5-stable.bin"
4
5 if ! cd "$DIR" 2>/dev/null
6 then
7   echo "Error: unable to enter into the firmware directory!"
8   echo "Try this first: aptitude install ipphone5-tools-firmware"
9   exit 1
10 fi
11
12 OPTIONS="$(readlink "$FIRMWARE" | sed 's/^.*-\([0-9]*\)-auf\([0-9]*\).*$/-v V1=\1 -v V2=\2/p;d')"
13
14 ipphone5-report |
15 awk -F: $OPTIONS '
16 !/^#/ {
17   ip = $1;
18   telnum = $4;
19   match($3,"[0-9]+-[0-9]+");
20   v = substr($3,RSTART,RLENGTH);
21   i = index(v,"-");
22   v1 = substr(v,1,i-1);
23   v2 = substr(v,i+1);
24   if ((v1 < V1) || (v2 < V2)) print ip,telnum,v1"-"v2,V1"-"V2;
25 }
26 ' |
27 while read IP TELNUM CURRENT STABLE
28 do
29   echo -n "Upgrading $IP ($TELNUM) from $CURRENT to $STABLE... "
30   if ipphone5-upload "$FIRMWARE" $IP >&/dev/null
31   then
32     echo 'Done.'
33   else
34     echo 'Failed!'
35   fi
36 done
37 exit 0