source: titan/oealliance/sbin/update.sh @ 43227

Last change on this file since 43227 was 43227, checked in by obi, 5 years ago

fix

  • Property svn:executable set to *
File size: 35.6 KB
Line 
1#!/bin/sh
2# update by obi
3
4#echo "[update.sh] $*"
5
6startconfig=/mnt/config/start-config
7if [ ! -e "$startconfig" ]; then startconfig="/etc/titan.restore/mnt/config/start-config"; fi
8
9. $startconfig
10cd /tmp
11boxtype=`cat /etc/model`
12buildgroup=`cat /etc/.buildgroup`
13arch=`cat /etc/.arch`
14event=`cat /mnt/config/titan.cfg | grep rcdev= | tr '/' '\n' | tail -n1`
15swtype="titan"
16board=`cat /etc/.board`
17bootversion=`cat /etc/version-svn`
18echo "[update.sh] booted version $bootversion"
19
20source=$1                       # getfilelist|tmp|online
21target=$2                       # kernel|var|root|full|backup or label or device or empty
22file=$3                         # file to flash/update or empty
23user=$4
24pass=$5
25imgtype=$6              # release|dev
26url=$7
27targetfull=$target
28
29vfd=vfd
30
31if [ "$source" = "getfilelist" ];then
32        user=$2
33        pass=$3
34        imgtype=$4
35        url=$5
36fi
37### got parameters for online ###
38#url=`cat /var/etc/ipkg/official-feed.conf | cut -d '/' -f4 | head -n1`
39#urldir=`cat /var/etc/ipkg/official-feed.conf | cut -d '/' -f5 | head -n1`
40urldir="svn"
41
42url="http://$user:$pass@$url"
43folder="image"
44
45if [ "$imgtype" == "dev" ]; then
46        folder="image-beta"
47fi
48
49tversion=`cat /etc/version-svn | tr '_' '\n' | tail -n1`
50
51getboxbranding()
52{
53        cat /etc/image-version | sed -nr "s/.*$1=([^*]+)*/\1/p"
54}
55
56if [ -e /etc/.oebuild ];then
57        boxtype=$(getboxbranding box_type)
58fi
59
60### get online filelist if source=getfilelist ###
61if [ "$source" == "getfilelist" ]; then
62        umount -fl /tmp/mnt > /dev/null 2>&1
63        umount -fl /tmp/mnt > /dev/null 2>&1
64        cd /tmp
65        mkdir -p online
66        rm -f online/*
67        rm -f list."$boxtype"
68
69        if [ -e /etc/.homecastpro-sat ];then boxtype="homecastpro-sat"; fi
70        if [ -e /etc/.homecastpro-cable ];then boxtype="homecastpro-cable"; fi
71
72        if [ -e /etc/.beta ] && [ "$imgtype" == "release" ]; then
73                wget -T15 "$url/$urldir/$folder/list.auto.$boxtype" -O /tmp/list.$boxtype
74        elif [ -e /etc/.beta ] || [ "$imgtype" == "dev" ]; then
75                wget -T15 "$url/$urldir/$folder/list.$boxtype" -O /tmp/list.$boxtype
76        else
77# disable ab v1.78
78#               wget -T15 "$url/$urldir/$folder/list.$boxtype.$tversion" -O /tmp/list.$boxtype
79                wget -T15 "$url/$urldir/$folder/list.auto.$boxtype" -O /tmp/list.$boxtype
80        fi
81
82        sync
83        if [ -e "/etc/.stable" ] && [ ! -e /etc/.beta ] && [ "$imgtype" == "release" ] && ([ "$boxtype" == "atemio6000" ] || [ "$boxtype" == "atemio6100" ] || [ "$boxtype" == "atemio6200" ]); then
84                filelist=`cat /tmp/list."$boxtype" | grep "_stable"`
85        elif [ ! -e /etc/.beta ] && [ "$imgtype" == "release" ] && ([ "$boxtype" == "atemio6000" ] || [ "$boxtype" == "atemio6100" ] || [ "$boxtype" == "atemio6200" ]); then
86                filelist=`cat /tmp/list."$boxtype" | grep "_nightly"`
87        else
88                filelist=`cat /tmp/list."$boxtype"`
89        fi
90
91        imgversion=`cat /etc/version-svn | cut -d "_" -f2 | sed 's/M//'`
92        if [ -z "$imgversion" ]; then
93                echo "[update.sh] imgversion not found, use 0"
94                imgversion=0;
95        elif [ -e /etc/.beta ]; then
96                imgversion=0
97        elif [ "$imgtype" == "dev" ]; then
98                imgversion=0
99        else
100#               imgversion=`expr $imgversion - 1`
101#               imgversion=$imgversion
102                imgversion=0
103        fi
104        if [ -z "$imgversion" ]; then
105                echo "[update.sh] imgversion not found, use 0"
106                imgversion=0;
107        fi
108
109        if [ -z "$updatelist" ]; then updatelist=10; fi
110        showfromversion=`expr $imgversion - $updatelist`
111
112        error="1"
113        uptodate="1"
114
115        for line in $filelist; do
116                error="0"
117#               version=`echo "$line" | cut -d "_" -f2 | sed 's/M//'`
118
119                if [ `echo "$line" | grep ^M | wc -l` -eq 1 ];then
120                        version=`echo "$line" | cut -d "_" -f1 | sed 's/M//'`
121                else
122                        version=${line#*_}
123                        version=${version%%_*}
124                        version=${version/M/}
125                fi
126#               if [ $showfromversion -lt $version ]; then
127                if [ $version -gt $imgversion ]; then
128                        echo "[update.sh] newerfile: $line"
129                        uptodate="0"
130                        > "/tmp/online/$line";
131                fi
132        done
133        sync
134        ### don't change this echo message, is used in panel ###
135        if [ "$error" == "1" ];then
136                rm -f online/*
137                rm -f list."$boxtype"
138                echo "[update.sh] error"
139        elif [ "$uptodate" == "1" ];then
140                echo "[update.sh] uptodate"
141        fi
142
143        exit 0
144fi
145
146### check input ###
147if [ -z "$source" ] || [ -z "$target" ] || [ -z "$file" ]; then
148        usage="1"
149fi
150if [ "$source" != "online" ] && [ "$source" != "tmp" ]; then
151        usage="1"
152fi
153
154### print usage ###
155if [ "$usage" == "1" ]; then
156#       echo "GetOnlineFilelist         :  update.sh  getfilelist"
157#       echo "FlashOnlineUpdate         :  update.sh  online kernel|var|root|full filename"
158#       echo "FlashTmpUpdate                    :  update.sh  tmp kernel|var|root|full filename"
159#       echo "UsbOnlineUpdate                   :  update.sh  online label|dev filename"
160#       echo "UsbTmpUpdate                              :  update.sh  tmp label|dev filename"
161        exit 1
162fi
163
164### got update to ###
165if [ "$target" == "kernel" ] || [ "$target" == "var" ] || [ "$target" == "root" ] || [ "$target" = "updatenfi" ] || [ "$target" = "updateusb" ] || [ "$target" == "full" ] || [ "$target" == "fullbackup" ]; then
166        update_to="flash"
167        target=`echo "$target" | tr "a-z" "A-Z"`
168else
169        update_to="usb"
170fi
171
172### make filenames ###
173tmp="/tmp"
174
175### other update handling for some boxes if full image is to big for /tmp (flash) ###
176if [ "$target" == "FULL" ] && [ "$boxtype" == "ufs912" ]; then target="KERNEL VAR ROOT"; fi
177if [ "$target" == "FULL" ] && [ "$boxtype" == "ufs913" ]; then target="KERNEL VAR ROOT"; fi
178if [ "$target" == "FULL" ] && [ "$boxtype" == "atemio510" ]; then target="KERNEL VAR ROOT"; fi
179if [ "$target" == "FULL" ] && [ "$boxtype" == "atemio7600" ]; then target="KERNEL VAR ROOT"; fi
180if [ "$target" == "FULL" ] && [ "$boxtype" == "atevio700" ]; then target="KERNEL VAR ROOT"; fi
181if [ "$target" == "FULL" ] && [ "$boxtype" == "atevio7000" ]; then target="KERNEL VAR ROOT"; fi
182if [ "$target" == "FULL" ] && [ "$boxtype" == "atemio520" ]; then target="KERNEL VAR ROOT"; fi
183if [ "$target" == "FULL" ] && [ "$boxtype" == "atemio530" ]; then target="KERNEL VAR ROOT"; fi
184if [ "$target" == "FULL" ] && [ "$boxtype" == "ufs910" ]; then target="KERNEL VAR ROOT"; fi
185if [ "$target" == "FULL" ] && [ "$boxtype" == "ufs922" ]; then target="KERNEL VAR ROOT"; fi
186if [ "$target" == "FULL" ] && [ "$boxtype" == "ipbox91" ]; then target="KERNEL VAR ROOT"; fi
187if [ "$target" == "FULL" ] && [ "$boxtype" == "ipbox900" ]; then target="KERNEL VAR ROOT"; fi
188if [ "$target" == "FULL" ] && [ "$boxtype" == "ipbox910" ]; then target="KERNEL VAR ROOT"; fi
189if [ "$target" == "FULL" ] && [ "$boxtype" == "ipbox9000" ]; then target="KERNEL VAR ROOT"; fi
190if [ "$target" == "FULL" ] && [ "$boxtype" == "spark" ]; then target="KERNEL ROOT"; fi
191if [ "$target" == "FULL" ] && [ "$boxtype" == "spark7162" ]; then target="KERNEL ROOT"; fi
192if [ "$target" == "FULL" ] && [ "$board" == "inihdp" ]; then target="KERNEL ROOT"; fi
193if [ "$target" == "FULL" ] && [ "$board" == "inihde" ]; then target="KERNEL ROOT"; fi
194if [ "$target" == "FULL" ] && [ "$board" == "inihde2" ]; then target="KERNEL ROOT"; fi
195if [ "$target" == "FULL" ] && [ "$board" == "inihde2am" ]; then target="KERNEL ROOT"; fi
196if [ "$target" == "FULL" ] && [ "$board" == "vusolo2" ]; then target="KERNEL ROOT"; fi
197if [ "$target" == "UPDATENFI" ] && [ "$board" == "dm7020hd" ]; then target="UPDATENFI"; fi
198if [ "$target" == "UPDATEUSB" ] && [ "$board" == "dm520" ]; then target="UPDATEUSB"; fi
199if [ "$target" == "UPDATEUSB" ] && [ "$board" == "dm900" ]; then target="UPDATEUSB"; fi
200if [ "$target" == "UPDATEUSB" ] && [ "$board" == "dm920" ]; then target="UPDATEUSB"; fi
201if [ "$target" == "UPDATEUSB" ] && [ "$board" == "wetek" ]; then target="UPDATEUSB"; fi
202if [ "$target" == "UPDATEUSB" ] && [ "$board" == "hd51" ]; then target="UPDATEUSB"; fi
203if [ "$target" == "FULLBACKUP" ]; then target="FULL"; fi
204if [ -e /etc/.oebuild ];then
205        if [ "$target" == "UPDATEUSB" ]; then target="UPDATEUSB"; fi
206fi
207
208### other update handling for some boxes if full image is to big for /tmp (usb) ###
209#if [ "USBFULL" == `basename "$file" | cut -d "_" -f9` ]; then bigimage=1; fi
210
211### flash is nand ###
212if [ "$boxtype" == "ufs912" ] || [ "$boxtype" == "spark" ] || [ "$boxtype" == "spark7162" ] || [ "$arch" = "mipsel" ] || [ "$arch" = "arm" ];then
213        nandbox="1"
214fi
215
216### functions ###
217
218killproc_oe()
219{
220        killall nmbd
221        killall smbd
222        killall rpc.mountd
223        killall rpc.statd
224        /etc/init.d/softcam stop
225        killall CCcam
226        pkill -9 -f '[Oo][Ss][Cc][Aa][Mm]'
227        ps w | grep -i oscam | grep -v grep | awk '{print $1}' | xargs kill -9
228        pkill -9 -f '[Ww][Ii][Cc][Aa][Rr][Dd][Dd]'
229        ps w | grep -i wicardd | grep -v grep | awk '{print $1}' | xargs kill -9
230        killall kodi.bin
231        killall hddtemp
232        killall transmission-daemon
233        killall openvpn
234        /etc/init.d/sabnzbd stop
235        pkill -9 -f cihelper
236        pkill -9 -f ciplus_helper
237        pkill -9 -f ciplushelper
238        # kill VMC
239        pkill -f vmc.sh
240        pkill -f DBServer.py
241        # stop autofs
242        /etc/init.d/autofs stop
243
244        # sync filesystem
245        echo "Syncing filesystem"
246        sync
247        sleep 1
248
249        init 2
250}
251
252umount_rootfs()
253{
254        multilib=0
255        if [ -e /lib64 ];then multilib=1; fi
256        echo multilib=$multilib
257
258        echo "start umount_rootfs"
259        # the start script creates /newroot dir and mount tmpfs on it
260        # create directories
261
262#       rm -rf /newroot
263        mkdir /newroot
264        cd /newroot
265        mkdir -p /newroot/{bin,dev/pts,etc,lib,media,oldroot,oldroot_bind,proc,run,sbin,sys,usr/lib/autofs,var,var/volatile}
266
267        if [ "$multilib" == 1 ];then
268                mkdir -p /newroot/{lib64,usr/lib64/autofs}
269        fi
270
271        # we need init and libs to be able to exec init u later
272        if [ "$multilib" == 1 ];then
273                cp -arf /bin/busybox*     /newroot/bin
274                cp -arf /bin/sh*          /newroot/bin
275                cp -arf /bin/bash*        /newroot/bin
276                cp -arf /sbin/init*       /newroot/sbin
277                cp -arf /lib64/libc*        /newroot/lib64
278                cp -arf /lib64/ld*          /newroot/lib64
279                cp -arf /lib64/libtinfo*    /newroot/lib64
280                cp -arf /lib64/libdl*       /newroot/lib64
281        else
282                cp -arf /bin/busybox*     /newroot/bin
283                cp -arf /bin/sh*          /newroot/bin
284                cp -arf /bin/bash*        /newroot/bin
285                cp -arf /sbin/init*       /newroot/sbin
286                cp -arf /lib/libc*        /newroot/lib
287                cp -arf /lib/ld*          /newroot/lib
288                cp -arf /lib/libtinfo*    /newroot/lib
289                cp -arf /lib/libdl*       /newroot/lib
290        fi
291
292        # libcrypt is moved from /lib to /usr/libX in new OE versions
293        if [ "$multilib" == 1 ];then
294                cp -arf /lib64/libcrypt*    /newroot/lib64
295                cp -arf /usr/lib64/libcrypt*    /newroot/usr/lib64
296        else
297                cp -arf /lib/libcrypt*    /newroot/lib
298                cp -arf /usr/lib/libcrypt*    /newroot/usr/lib
299        fi
300
301        # copy for automount ignore errors as autofs is maybe not installed
302        if [ "$multilib" == 1 ];then
303                cp -arf /usr/sbin/autom*  /newroot/bin
304                cp -arf /etc/auto*        /newroot/etc
305                cp -arf /lib64/libpthread*  /newroot/lib64
306                cp -arf /lib64/libnss*      /newroot/lib64
307                cp -arf /lib64/libnsl*      /newroot/lib64
308                cp -arf /lib64/libresolv*   /newroot/lib64
309                cp -arf /usr/lib64/libtirp* /newroot/usr/lib64
310                cp -arf /usr/lib64/autofs/* /newroot/usr/lib64/autofs
311                cp -arf /etc/nsswitch*    /newroot/etc
312                cp -arf /etc/resolv*      /newroot/etc
313        else
314                cp -arf /usr/sbin/autom*  /newroot/bin
315                cp -arf /etc/auto*        /newroot/etc
316                cp -arf /lib/libpthread*  /newroot/lib
317                cp -arf /lib/libnss*      /newroot/lib
318                cp -arf /lib/libnsl*      /newroot/lib
319                cp -arf /lib/libresolv*   /newroot/lib
320                cp -arf /usr/lib/libtirp* /newroot/usr/lib
321                cp -arf /usr/lib/autofs/* /newroot/usr/lib/autofs
322                cp -arf /etc/nsswitch*    /newroot/etc
323                cp -arf /etc/resolv*      /newroot/etc
324        fi
325
326        echo "Switching to user mode 2"
327        init 2
328        killall -9 start.sh
329        killall -9 titan
330        sleep 2
331
332        pivot_root /newroot oldroot
333
334        cd /
335        # move mounts to new root
336        mount --move /oldroot/dev/ dev/
337        mount --move /oldroot/proc/ proc/
338        mount --move /oldroot/sys/ sys/
339        mount --move /oldroot/var/volatile var/volatile/
340
341        # create link for tmp
342        ln -s /var/volatile/tmp /tmp
343
344        mount --move /oldroot/media/ media/
345
346        # /media is no tmpfs -> move every mount
347        echo "/media is not tmpfs"
348
349        # create link for mount/umount for autofs
350        ln -s /bin/busybox /bin/mount
351        ln -s /bin/busybox /bin/umount
352
353        exec init u
354        sleep 2
355
356        // kill all remaining open processes which prevent umounting rootfs
357        fuser -k -m /oldroot/
358        sleep 3
359
360        umount /oldroot/newroot
361        umount /oldroot
362
363        ret=$?         
364        if [ $ret -eq 0 ]; then
365                echo "umount successful"
366        else
367                echo "umount not successful"
368        fi
369}
370
371flash_img()
372{
373        if [ "$targetfull" = "fullbackup" ];then
374                file="$origfile"
375        fi
376
377        while true; do
378                if [ "$arch" = "mipsel" ] || [ "$arch" = "arm" ];then
379                        echo skip flash_erase
380#                       echo /tmp/flash_erase /tmp/"$mtd" 0 0
381#                       /tmp/flash_erase /tmp/"$mtd" 0 0
382                else
383                        /tmp/flash_eraseall -l "Erase: $part" -x "$boxtype" /tmp/"$mtd"
384                fi
385                sleep 1
386
387                echo "[update.sh] boxtype=$boxtype part=$part mtd=$mtd file=$file"
388                if [ "$arch" = "mipsel" ] || [ "$arch" = "arm" ];then
389                        if [ "$boxtype" = "atemio6000" ] || [ "$boxtype" = "atemio6100" ];then
390                                echo "EAas" > /tmp/$vfd
391                        else
392                                echo "Write: $part" > /tmp/$vfd
393                        fi
394
395                        if [ "$part" = "UPDATEUSB" ];then
396                                if [ -e /etc/.oebuild ];then
397                                        tmp=/tmp
398                                        showtime=33
399                                        if [ "$board" = "hd51" ];then showtime=40 ;fi
400                                        infobox -pos -1 75% 100$showtime "UPDATEUSB" "            Entpacke Image            " &
401
402                                        time unzip "$file" -x $board/*.img -x usb_update.bin -d /tmp
403                                        rm -f "$file"
404
405                                        sync
406
407                                        imagedir=$(getboxbranding imagedir)
408                                        mtdrootfs=$(getboxbranding mtdrootfs)
409                                        mtdkernel=$(getboxbranding mtdkernel)
410                                        killall infobox
411                                        ofgwrite -r$mtdrootfs -k$mtdkernel $tmp/$imagedir
412                                        exit
413                                elif [ "$board" = "dm520" ];then
414                                        infobox -pos -1 75% 10125 "UPDATEUSB" "            Schreibe Daten            " &
415                                        unzip "$file" -d /tmp
416                                        flash-kernel /tmp/kernel.bin
417                                        helproot=/tmp/helproot
418                                        if [ ! -d $helproot ]; then
419                                                mkdir $helproot
420                                        else
421                                                umount -l $helproot
422                                        fi
423                                        mount -t ubifs ubi0:dreambox-rootfs $helproot
424                                        erase_root $helproot
425                                        tar -xvjf /tmp/rootfs.tar.bz2 --exclude=./mnt --exclude=./var/media -C $helproot
426                                elif [ "$board" = "dm900" ] || [ "$board" = "dm920" ] || [ "$board" = "wetek" ] || [ "$board" = "hd51" ];then
427                                        showtime=33
428                                        if [ "$board" = "hd51" ];then showtime=40 ;fi
429
430                                        infobox -pos -1 75% 100$showtime "UPDATEUSB" "            Schreibe Daten            " &
431
432                                        if [ -d /tmp/$board ]; then
433                                                rm -r /tmp/$board
434                                        fi
435                                        time unzip "$file" -x $board/*.img -d /tmp
436                                        rm -f "$file"
437                                        time flash-kernel /tmp/$board/kernel.bin
438
439                                        sync
440# log to /var/swap/logs not working...
441#                                       /etc/init.d/autofs stop
442                                        umount -l /mnt
443
444                                        helproot=/tmp/helproot
445                                        if [ ! -d $helproot ]; then
446                                                mkdir $helproot
447                                        else
448                                                umount -l $helproot
449                                        fi
450                                        mount /dev/root $helproot
451
452                                        time erase_root $helproot
453#                                       time tar -xvf /tmp/$board/rootfs.tar --exclude=./mnt --exclude=./var/media -C $helproot
454                                        time tar -xvjf /tmp/$board/rootfs.tar.bz2 --exclude=./mnt --exclude=./var/media -C $helproot
455
456                                fi
457                        elif [ "$part" = "UPDATENFI" ];then
458                                infobox -pos -1 75% 10065 "UPDATENFI" "            Schreibe Daten            " &
459                                mkdir /tmp/ramfs
460                                mount -t ramfs ramfs /tmp/ramfs                         
461                                cp "$file" /tmp/ramfs/flash.nfi
462                                rm "$file"
463                                nfiwrite -l -b -r -s -f -v /tmp/ramfs/flash.nfi
464                        elif [ "$part" = "KERNEL" ];then
465                                echo /tmp/mv -f "$file" /tmp/kernel.bin
466                                /tmp/mv -f "$file" /tmp/kernel.bin
467                                killall infobox
468                                #infobox -pos -1 75% 10010 "Kernel" "            Schreibe Daten            " &
469                                if [ "$boxtype" = "vusolo2" ];then
470                                        #/sbin/fuser -k /dev/dvb/adapter0/frontend0
471                                        echo /tmp/ofgwrite --kernel=mtd2 /tmp
472                                        /tmp/ofgwrite --kernel=mtd2 /tmp
473                                elif [ "$boxtype" = "dm520" ] || [ "$boxtype" = "dm525" ];then
474                                        echo /tmp/ofgwrite -nk /tmp
475                                        /tmp/ofgwrite -nk /tmp
476                                else
477                                        echo /tmp/ofgwrite -k /tmp
478                                        /tmp/ofgwrite -k /tmp
479                                fi
480                        elif [ "$part" = "ROOT" ];then
481                                if [ "$arch" = "mipsel" ] || [ "$arch" = "arm" ];then
482                                        touch /tmp/.init3
483                                        touch /tmp/.update
484                                fi
485                                killall infobox
486                                echo /tmp/mv -f "$file" /tmp/rootfs.bin
487                                /tmp/mv -f "$file" /tmp/rootfs.bin
488                                if [ "$boxtype" = "vusolo2" ];then
489                                        #/sbin/fuser -k /dev/dvb/adapter0/frontend0
490                                        echo /tmp/ofgwrite --rootfs=mtd0 /tmp
491                                        /tmp/ofgwrite --rootfs=mtd0 /tmp
492                                elif [ "$boxtype" = "dm520" ] || [ "$boxtype" = "dm525" ];then
493                                        echo /tmp/ofgwrite_bin -r /tmp
494#                                       mount -r -o remount /
495#                                       /tmp/ubiformat /dev/mtd0 -f /tmp/rootfs.bin -D
496
497                                        echo /tmp/ofgwrite -r /tmp
498                                        /tmp/ofgwrite -r /tmp
499                                else
500                                        echo /tmp/ofgwrite -r /tmp
501                                        /tmp/ofgwrite -r /tmp
502                                fi
503#                               mount -r -o remount /
504#                               /tmp/ubiformat /dev/mtd0 -f /tmp/rootfs.bin -D
505                        fi
506                        ret=$?         
507                elif [ "$boxtype" = "ufs913" ];then
508                        if [ "$part" = "KERNEL" ];then
509                                /tmp/flashcp -v "Write: $part" "$boxtype" "$file" /tmp/"$mtd"
510                        else
511                                echo /tmp/nandwrite -p /tmp/"$mtd" "$file"
512                                /tmp/nandwrite -p /tmp/"$mtd" "$file"
513                        fi
514                        ret=$?
515                elif [ "$nandbox" = "1" ]; then
516                        echo /tmp/nandwrite -p /tmp/"$mtd" "$file"
517                        /tmp/nandwrite -p /tmp/"$mtd" "$file"
518                        ret=$?
519                else
520                        /tmp/flashcp -v "Write: $part" "$boxtype" "$file" /tmp/"$mtd"
521                        ret=$?
522                fi
523                if [ $ret -eq 0 ]; then break; fi
524                infobox -pos -1 70% 9999 "Aktualisierung" "ACHTUNG: Aktualisierung fehlgeschlagen" " " "OK = Weiter" "Blau = Aktualisierung wiederholen" &
525                if [ "$boxtype" = "atemio520" ] || [ "$boxtype" = "atemio530" ] || [ "$boxtype" = "spark" ] || [ "$boxtype" = "ipbox91" ] || [ "$boxtype" = "atemio6000" ] || [ "$boxtype" = "atemio6100" ]; then
526                        echo "Err " > /tmp/$vfd
527                else
528                        echo "Fehlgeschlagen ?" > /tmp/$vfd
529                fi
530                abfrage /tmp/$event; ret=$?
531                echo " " > /tmp/$vfd
532                killall infobox
533                if [ "$part" = "UPDATEUSB" ];then
534                        echo "sync" > /tmp/$vfd
535                        sync
536                        echo " " > /tmp/$vfd
537                fi
538                if [ $ret -eq 0 ]; then break; fi
539        done
540}
541
542killproc()
543{
544        count=0
545        lastcount=`ps | tail -n1 | sed "s/ \+/ /g;s/^ //" | cut -d" " -f1`
546        if [ "$boxtype" == "ufs910" ] || [ "$boxtype" == "ufs922" ]; then
547                excludes="^ini inetd automount evremote2 telnetd update.sh infobox lircd"
548        else
549                excludes="^ini inetd automount evremote2 telnetd update.sh infobox lircd enigma2.sh dvb_server init_client oscam gbox cccam $swtype"
550        fi
551        while true; do
552                count=$((count + 1))
553                if [ -e "/proc/$count/cmdline" ]; then
554                        cmd=`cat "/proc/$count/cmdline"`
555                        if [ ! -z "$cmd" ]; then
556                                treffer=0
557                                for exclude in $excludes; do
558                                        if echo "$cmd" | grep -q "$exclude"; then treffer=1; fi
559                                done
560                                if [ $treffer -eq 0 ]; then
561                                        echo "[update.sh] killing pid=$count cmd=$cmd"
562                                        kill -9 "$count"
563                                fi
564                        fi
565                fi
566                if [ $count -ge $lastcount ]; then break; fi
567        done
568}
569
570kill_and_show()
571{
572        if [ -z "$killandshow" ]; then
573                killall infobox
574                infobox -pos -1 75% 9999 "Info" "            Laufende Prozesse beenden            " "            Bitte warten            " &
575       
576                killandshow="1"
577                emu.sh stop
578                killall -9 rcS
579                killproc
580                echo "3" > /proc/sys/vm/drop_caches
581#       FIXME: kills update.sh why???
582#               /sbin/fuser -k /dev/dvb/adapter0/frontend0
583#               /sbin/fuser -k /dev/dvb/adapter0/frontend1
584#               echo "0" > /proc/progress
585
586                if [ "$boxtype" == "ufs910" ] || [ "$boxtype" == "ufs922" ]; then
587                        echo "[workaround] killall -9 $swtype"
588                        killall -9 $swtype
589                        infobox 1 "nobox#/var/etc/boot/start.jpg"
590                else
591                        skip1=1
592                fi
593                killall infobox
594        fi
595}
596
597error()
598{
599        killall infobox
600        infobox -pos -1 70% 10010 "Aktualisierungsfehler!" "$1" "" "Neustart in 10 Sekunden" &
601        echo "[update.sh] $1"
602        for i in 9 8 7 6 5 4 3 2 1 0; do
603                if [ "$boxtype" = "atemio520" ] || [ "$boxtype" = "atemio530" ] || [ "$boxtype" = "spark" ] || [ "$boxtype" = "ipbox91" ] || [ "$boxtype" = "atemio6000" ] || [ "$boxtype" = "atemio6100" ]; then
604                        echo "Rb $i" > /dev/$vfd
605                else
606                        echo "$2 ($i)" > /dev/$vfd
607                fi
608                sleep 1
609        done
610        if [ "$boxtype" = "atemio520" ] || [ "$boxtype" = "atemio530" ] || [ "$boxtype" = "spark" ] || [ "$boxtype" = "ipbox91" ] || [ "$boxtype" = "atemio6000" ] || [ "$boxtype" = "atemio6100" ]; then
611                echo "Ende" > /dev/$vfd
612        else
613                echo "Neustart" > /dev/$vfd
614        fi
615        echo "[update.sh] reboot"
616#       init 6
617        /tmp/reboot -f
618        reboot -f
619        exit
620}
621
622got_mtd_part()
623{
624        if [ "$part" == "UPDATENFI" ] || [ "$part" == "UPDATEUSB" ];then
625                mtd=mtddisabled
626        else
627                mtd=`cat /proc/mtd | grep -i "$part" | cut -d":" -f1 | tail -n1`
628                echo "[update.sh] Part $part: mtd=$mtd"
629                ### check mtd part ###
630                if [ -z "$mtd" ] || [ `echo -e "$mtd" | wc -l` -ne 1 ] || [ "${mtd:0:3}" != "mtd" ] || ([ "$mtd" == "mtd0" ] && [ "$arch" = "sh4" ]); then
631                        error "Uncorrect MTD Partition: $mtd" "MTD err"
632                fi
633        fi
634}
635
636md5_check()
637{
638        if [ "$source" == "online" ];then
639                md5=`md5sum "$file" | cut -d"/" -f1 | tr -d " "`
640                echo "[update.sh] md5=$md5"
641                md5file=`cat "$file_md5" | tr -d " "`
642                echo "[update.sh] md5file=$md5file"
643                if [ "$md5" != "$md5file" ]; then
644                        error "MD5 check failed" "MD5 err"
645                fi
646        fi
647}
648
649got_online_img()
650{
651        if [ "$source" == "online" ];then
652                killall infobox
653                infobox -pos -1 75% 3 Aktualisierung "  Lade Image und MD5  " &
654                if [ "$boxtype" = "atemio520" ] || [ "$boxtype" = "atemio530" ] || [ "$boxtype" = "spark" ] || [ "$boxtype" = "ipbox91" ] || [ "$boxtype" = "atemio6000" ] || [ "$boxtype" = "atemio6100" ]; then
655                        echo "Lade" > /tmp/$vfd
656                else
657                        echo "Lade Image" > /tmp/$vfd
658                fi
659                cd "$tmp"
660                rm -f "$base"
661                rm -f "$base_md5"
662                sleep 3
663                killall infobox
664
665                wget.info -T15 "$url/$urldir/$folder/$base"
666                wget.info -T15 "$url/$urldir/$folder/$base_md5"
667
668                killall infobox
669                infobox -pos -1 75% 20 Aktualisierung "    Laden abgeschlossen    " &
670                if [ "$boxtype" = "atemio520" ] || [ "$boxtype" = "atemio530" ] || [ "$boxtype" = "spark" ] || [ "$boxtype" = "ipbox91" ]; then
671                        echo "Ok" > /tmp/$vfd
672                elif [ "$boxtype" = "atemio6000" ] || [ "$boxtype" = "atemio6100" ];then
673                        echo "Done" > /tmp/$vfd
674                else
675                        echo "Laden fertig" > /tmp/$vfd
676                fi
677        fi
678}
679
680copy_to_tmp()
681{
682        if [ ! -e "$tmp/$base" ]; then
683                killall infobox
684                infobox -pos -1 75% 100 Aktualisierung "  Kopiere Image nach $tmp  " &
685                if [ "$boxtype" = "atemio520" ] || [ "$boxtype" = "atemio530" ] || [ "$boxtype" = "spark" ] || [ "$boxtype" = "ipbox91" ]; then
686                        echo "Kopi" > /tmp/$vfd
687                elif [ "$boxtype" = "atemio6000" ] || [ "$boxtype" = "atemio6100" ];then
688                        echo "Copy" > /tmp/$vfd
689                else
690                        echo "Kopiere" > /tmp/$vfd
691                fi
692                cp "$file" "$tmp/$base"
693        fi
694        if [ ! -e "$tmp/$base_md5" ]; then
695                cp "$file_md5" "$tmp/$base_md5"
696        fi
697        file="$tmp/$base"
698        file_md5="$tmp/$base_md5"
699}
700
701file_check()
702{
703        if [ ! -e "$file" ]; then
704                error "Missing: File" "no file"
705        fi
706        if [ ! -e "$file_md5" ] && [ "$source" == "online" ]; then
707                error "Missing: MD5 File" "no MD5"
708        fi
709}
710
711got_basename()
712{
713        if [ "$targetfull" != "fullbackup" ];then
714                file=`echo "$origfile" | sed "s/_FULL_/_${part}_/"`
715        fi
716#       file_md5="${file%.*}"; file_md5="${file_md5%.*}"; file_md5="$file_md5.md5"
717        file_md5="${file%.*}".md5;
718#       file_md5=`echo $file | sed 's/.img/.md5/' | sed 's/.tar.gz/.md5/'`
719        base=`basename "$file"`
720        base_md5=`basename "$file_md5"`
721}
722
723make_tmp()
724{
725        mkdir /tmp/mktmp
726        mkdir /tmp/lib
727        cp /bin/busybox /tmp
728        cp /bin/infobox /tmp
729        cp /bin/flashcp /tmp
730        if [ "$arch" == "mipsel" ] || [ "$arch" = "arm" ];then
731                cp /sbin/wget /tmp
732        fi
733        if [ -e /bin/cubefpctl ]; then cp /bin/cubefpctl /tmp; fi
734        cp /sbin/halt /tmp
735        cp /mnt/network/resolv.conf /tmp
736        cp /bin/flash_eraseall /tmp
737        cp /bin/grep /tmp
738
739#       cp /lib/ld.so.1 /tmp/lib                #for busybox
740#       cp -a /lib/ld-linux.so.* /tmp/lib               #for busybox
741#       cp -a /lib/libc.so.* /tmp/lib                           #for busybox
742#       cp -a /lib/libcrypt.so.* /tmp/lib               #for busybox
743#       cp -a /lib/libfreetype.so.* /tmp/lib    #for infobox
744#       cp -a /lib/libz.so.* /tmp/lib                           #for infobox
745#       cp -a /lib/libm.so.* /tmp/lib                           #for infobox
746#       cp -a /lib/libgcc_s.so.* /tmp/lib               #for infobox
747#       cp -a /lib/libjpeg.so.* /tmp/lib                #for infobox
748#       cp -a /lib/libpng* /tmp/lib             #for infobox   
749#       cp -a /lib/libbz2.so.* /tmp/lib         #for infobox
750
751#p217 github duckbox
752        cp -a /lib/ld.so.1 /tmp/lib
753        cp -a /lib/ld-* /tmp/lib
754        cp -a /lib/libc.* /tmp/lib
755        cp -a /lib/libc-* /tmp/lib
756        cp -a /lib/libcrypt.* /tmp/lib
757        cp -a /lib/libcrypt-* /tmp/lib
758        cp -a /lib/libfreetype.so.* /tmp/lib
759        cp -a /lib/libz-* /tmp/lib
760        cp -a /lib/libz.* /tmp/lib
761        cp -a /lib/libm.* /tmp/lib
762        cp -a /lib/libm-* /tmp/lib
763        cp -a /lib/libgcc_s* /tmp/lib
764        cp -a /lib/libjpeg.so.* /tmp/lib
765        cp -a /lib/libpng* /tmp/lib
766        cp -a /lib/libbz2.so.* /tmp/lib
767
768        if [ "$arch" == "sh4" ];then
769                cp /lib/libcrypto.so.* /tmp/lib         #for wget
770                cp /lib/libssl.so.* /tmp/lib            #for wget
771        fi
772
773        if [ "$target" = "UPDATEUSB" ]; then
774                cp /lib/ld* /tmp/lib            #for busybox
775                cp /lib/libc.so.6 /tmp/lib                              #for busybox
776                cp /lib/libcrypt.so.1 /tmp/lib          #for busybox
777                cp /usr/lib/libfreetype.so.6 /tmp/lib   #for infobox
778                cp /lib/libz.so.1 /tmp/lib                              #for infobox
779                cp /lib/libm.so.6 /tmp/lib                              #for infobox
780                cp /lib/libgcc_s.so.1 /tmp/lib          #for infobox
781                cp /usr/lib/libjpeg.so.62 /tmp/lib              #for infobox
782                cp /usr/lib/libjpeg.so.8 /tmp/lib               #for infobox
783                cp /usr/lib/libpng15.so.15 /tmp/lib             #for infobox
784                cp /lib/libbz2* /tmp/lib                #for infobox
785                cp /usr/lib/libcrypto* /tmp/lib         #for wget
786                cp /lib/libssl* /tmp/lib                #for wget
787                cp /usr/share/fonts/default.ttf /tmp    # for infobox
788
789                cp /lib/libresolv.so* /tmp/lib          #for gzip
790                cp /lib/librt* /tmp/lib         #for automount
791                cp /usr/lib/libcrypt.* /tmp/lib         #for sleep
792
793                cp /lib/libpam.so* /tmp/lib             #for login
794                cp /lib/libpam_misc.so* /tmp/lib                #for login
795
796                cp -a /lib/libtinfo.so.* /tmp/lib
797                cp /usr/sbin/flash-kernel /tmp
798                cp /usr/sbin/librecovery /tmp
799                cp /usr/bin/unzip /tmp
800                cp /bin/rm /tmp
801        fi
802
803        cp /usr/share/fonts/default.ttf /tmp    # for infobox
804        cp /sbin/sleepms /tmp
805
806        cat /sbin/abfrage | sed "s#/usr/bin/awk#/tmp/awk#" > /tmp/abfrage
807        chmod 777 /tmp/abfrage
808        cat /sbin/emu.sh | sed "s#/bin/sh#/tmp/sh#" > /tmp/emu.sh
809        chmod 777 /tmp/emu.sh
810        cat /sbin/wget.info | sed "s#/bin/sh#/tmp/sh#" > /tmp/wget.info
811        chmod 777 /tmp/wget.info
812        cat /sbin/start_sec.sh | sed "s#/bin/sh#/tmp/sh#" > /tmp/start_sec.sh
813        chmod 777 /tmp/start_sec.sh
814
815        if [ "$boxtype" = "ipbox91" ] || [ "$boxtype" = "ipbox910" ] || [ "$boxtype" = "ipbox900" ] || [ "$boxtype" = "ipbox9000" ]; then
816                ln -s /tmp/halt /tmp/reboot
817        elif [ "$arch" = "mipsel" ] || [ "$arch" = "arm" ];then
818                cp /sbin/reboot.sysvinit /tmp/reboot
819                cp /usr/bin/ofgwrite /tmp
820                cp /usr/sbin/ubiformat /tmp
821        else
822                ln -s /tmp/busybox /tmp/reboot
823        fi
824        if [ "$arch" = "sh4" ];then
825                ln -s /tmp/busybox /tmp/wget
826        fi
827        ln -s /tmp/busybox /tmp/killall
828        ln -s /tmp/busybox /tmp/sleep
829        ln -s /tmp/busybox /tmp/awk
830        ln -s /tmp/busybox /tmp/dd
831        ln -s /tmp/busybox /tmp/time
832        ln -s /tmp/busybox /tmp/sync
833        ln -s /tmp/busybox /tmp/mount
834        ln -s /tmp/busybox /tmp/umount
835        ln -s /tmp/busybox /tmp/mkdir
836        ln -s /tmp/busybox /tmp/echo
837        ln -s /tmp/busybox /tmp/sed
838        ln -s /tmp/busybox /tmp/cut
839        ln -s /tmp/busybox /tmp/tail
840        ln -s /tmp/busybox /tmp/tr
841        ln -s /tmp/busybox /tmp/date
842        ln -s /tmp/busybox /tmp/basename
843        ln -s /tmp/busybox /tmp/tar
844        ln -s /tmp/busybox /tmp/cat
845        ln -s /tmp/busybox /tmp/wc
846        ln -s /tmp/busybox /tmp/rm
847        ln -s /tmp/busybox /tmp/touch
848        ln -s /tmp/busybox /tmp/ash
849        ln -s /tmp/busybox /tmp/mv
850        ln -s /tmp/ash /tmp/sh
851
852        if [ "$arch" = "mipsel" ];then
853                ln -s /proc/vfd /tmp/vfd
854                cp -aL /dev/mtd0 /tmp/mtd0
855                cp -aL /dev/dbox/oled0 /tmp
856        elif [ "$arch" = "arm" ];then
857                cp -aL /dev/mtd0 /tmp/mtd0
858                cp -aL /dev/dbox/oled0 /tmp
859                ln -s /tmp/oled0 /tmp/vfd
860        else
861                cp -aL /dev/vfd /tmp/vfd
862        fi
863        cp -aL /dev/mtd1 /tmp/mtd1
864        cp -aL /dev/mtd2 /tmp/mtd2
865        cp -aL /dev/mtd3 /tmp/mtd3
866        cp -aL /dev/mtd4 /tmp/mtd4
867        cp -aL /dev/mtd5 /tmp/mtd5
868        cp -aL /dev/mtd6 /tmp/mtd6
869        cp -aL /dev/mtd7 /tmp/mtd7
870        cp -aL /dev/mtd8 /tmp/mtd8
871        cp -aL /dev/mtd9 /tmp/mtd9
872        cp -aL /dev/input/$event /tmp/$event
873        cp -aL /dev/mtdblock2 /tmp/mtdblock2
874        cp -aL /dev/mtdblock3 /tmp/mtdblock3
875        cp -aL /dev/mtdblock4 /tmp/mtdblock4
876        cp -aL /dev/mtdblock5 /tmp/mtdblock5
877        cp -aL /dev/mtdblock6 /tmp/mtdblock6
878
879        if [ "$nandbox" = "1" ] || [ "$boxtype" = "ufs913" ]; then
880                cp /bin/nandwrite /tmp
881                cp /lib/libpthread.so.0 /tmp/lib
882                cp /lib/libdl.so.2 /tmp/lib
883        fi
884
885        if [ "$arch" = "mipsel" ] || [ "$arch" = "arm" ]; then
886                echo copy nandwrite flash_erase
887                cp /usr/sbin/nandwrite /tmp
888                cp /usr/sbin/flash_erase  /tmp
889                touch /tmp/.update
890        fi
891
892        if [ "$update_to" == "usb" ] || [ "$update_to" == "ba" ]; then
893                cat /sbin/tar.info | sed "s#/bin/sh#/tmp/sh#" > /tmp/tar.info
894                chmod 777 /tmp/tar.info
895                cp /sbin/mke2fs /tmp/mktmp
896                cp /sbin/fw_setenv /tmp
897                cp /sbin/fw_printenv /tmp
898                cp /mnt/network/resolv.conf /tmp
899                ln -s /tmp/mktmp/mke2fs /tmp/mktmp/mkfs.ext2
900        fi
901
902        PATH="/tmp:$PATH"
903        PATH="/tmp/mktmp:$PATH"
904        export PATH
905        LD_LIBRARY_PATH="/lib;/usr/lib;/tmp/lib"
906        export LD_LIBRARY_PATH
907}
908
909erase_root()
910{
911        echo "erase root"
912        rm -rf $1/var/bin
913        rm -rf $1/var/lib
914        rm -rf $1/var/usr
915        rm -rf $1/var/etc
916        rm -rf $1/usr/bin
917        rm -rf $1/usr/lib
918        rm -rf $1/usr/sbin
919        #rm -rf $1/lib
920        rm -rf $1/etc
921        rm -rf $1/sbin
922        rm -rf $1/boot
923        #rm -f $1/ba
924        rm -f $1/.swfinfo
925        #rm -f $1/.smb
926        #rm -f $1/.cache
927        rm -rf $1/bin
928}
929
930### stop E2 (not TV) ###
931killall -stop $swtype
932
933### change tmp if image is to big for /tmp ###
934if [ "$bigimage" == "1" ]; then
935        tmp=`dirname "$file"`
936fi
937
938### show beginning of update ###
939infobox -pos -1 75% 20 "Aktualisierung" "  Start: bitte warten  " &
940if [ "$boxtype" = "atemio520" ] || [ "$boxtype" = "atemio530" ] || [ "$boxtype" = "spark" ] || [ "$boxtype" = "ipbox91" ] || [ "$boxtype" = "atemio6000" ] || [ "$boxtype" = "atemio6100" ]; then
941        echo "Star" > /dev/$vfd
942else
943        echo "Aktualisierung gestartet" > /dev/$vfd
944fi
945sleep 3
946
947### save orig filename ###
948origfile="$file"
949got_basename
950
951### kill unneedet prozess and showiframe ###
952if [ "$boxtype" = "ufs910" ] || [ "$boxtype" = "ufs922" ]; then
953        kill_and_show
954fi
955
956if [ "$update_to" == "flash" ]; then swap.sh swapalloff; fi
957
958### remove tmp, exclude img and md5 ###
959targetlist="FULL $target"
960for part in $targetlist; do
961        got_basename
962        skipliste="$skipliste $file"
963done
964
965TEXT="| grep -v"
966for ROUND in $skipliste; do
967        SKIP="$SKIP $TEXT \"$ROUND\""
968done
969
970echo "find $tmp -xdev | "grep -v "^$tmp$" "$SKIP" > /tmp/tmp.cmd
971chmod 755 /tmp/tmp.cmd
972/tmp/tmp.cmd > /tmp/tmp.list
973
974tlist=`cat /tmp/tmp.list`
975rm -f /tmp/tmp.list
976for t in $tlist; do
977        mountpoint -q "$t"
978        if [ $? -ne 0 ]; then
979                echo "$t" >> /tmp/tmp.list
980        fi
981done
982
983rm -rf `cat /tmp/tmp.list`
984got_basename
985# not working if image directly in /tmp
986#rm -rf `find $tmp | grep -v "^$tmp$" | grep -v "$base" | grep -v "$base_md5"`
987
988
989### copy all needet files to tmp ###
990make_tmp
991
992for part in $target; do
993        ### make filename ###
994        got_basename
995
996        ### if source=online, got online image and .md5 file ###
997        got_online_img
998
999        ### copy img and md5 to tmp if not in tmp ###
1000        if [ "$source" = "online" ];then
1001                copy_to_tmp
1002        fi
1003
1004        ### check ###
1005        killall infobox
1006        infobox -pos -1 75% 20 Aktualisierung "    Überprüfe Image    " &
1007        if [ "$boxtype" = "atemio520" ] || [ "$boxtype" = "atemio530" ] || [ "$boxtype" = "spark" ] || [ "$boxtype" = "ipbox91" ] || [ "$boxtype" = "atemio6000" ] || [ "$boxtype" = "atemio6100" ]; then
1008                echo "Uery" > /tmp/$vfd
1009        else
1010                echo "Verify" > /tmp/$vfd
1011        fi
1012        sleep 3
1013
1014        ### check if img and md5 is in tmp ###
1015        file_check
1016
1017        ### check md5 ###
1018        md5_check
1019
1020        killall infobox
1021        infobox -pos -1 75% 20 Aktualisierung "    Überprüfung OK    " &
1022
1023        if [ "$boxtype" = "atemio520" ] || [ "$boxtype" = "atemio530" ] || [ "$boxtype" = "spark" ] || [ "$boxtype" = "ipbox91" ] || [ "$boxtype" = "atemio6000" ] || [ "$boxtype" = "atemio6100" ]; then
1024                echo "Done" > /tmp/$vfd
1025        else
1026                echo "OK" > /tmp/$vfd
1027        fi
1028
1029        sleep 3
1030done
1031
1032for part in $target; do
1033        got_basename
1034        file="$tmp/$base"
1035
1036        ### kill unneedet prozess and showiframe ###
1037        echo "[update.sh] check box: $boxtype part: $part"
1038        if [ ! -e /etc/.oebuild ] && ([ "$arch" = "mipsel" ]  || [ "$arch" = "arm" ]) && ([ "$part" = "ROOT" ] || [ "$part" = "UPDATENFI" ] || [ "$part" = "UPDATEUSB" ]); then
1039                kill_and_show
1040        elif [ "$boxtype" = "ufs910" ]; then
1041                kill_and_show   
1042        else
1043                echo "[update.sh] skip kill_and_show"
1044        fi
1045
1046        ### update to flash ###
1047        if [ "$update_to" == "flash" ]; then
1048                killall infobox
1049                if [ "$boxtype" = "atemio520" ] || [ "$boxtype" = "atemio530" ] || [ "$boxtype" = "spark" ] || [ "$boxtype" = "ipbox91" ] || [ "$boxtype" = "atemio6000" ] || [ "$boxtype" = "atemio6100" ]; then
1050                        echo "Upda" > /tmp/$vfd
1051                else
1052                        echo "Update !!!" > /tmp/$vfd
1053                fi
1054
1055                ### got and check mtd part ###
1056                got_mtd_part
1057
1058                ### flash the image ###
1059                if [ "$target" == "FULL" ] || [ "$target" == "ROOT" ] || [ "$target" = "UPDATENFI" ] || [ "$target" = "UPDATEUSB" ]; then mount /tmp/lib /lib; fi
1060                flash_img
1061
1062                if [ "$targetfull" != "fullbackup" ];then
1063                        rm -f "$file"
1064                fi
1065        fi
1066done
1067
1068### update to usb ###
1069if [ "$update_to" == "usb" ]; then
1070        ### got label or device ###
1071        blkid=`blkid -w /dev/null -c /dev/null`
1072        if echo "$target" | grep -q sd[a-z][1-9]; then
1073                label=`echo -e "$blkid" | grep "^/dev/$target:" | grep LABEL= | sed 's/^.*LABEL="//;s/".*$//' | tr -d " " | tr -d "-"`
1074        else
1075                label="$target"
1076                target=`echo -e "$blkid" | grep "LABEL=\"$label\"" | head -n1 | cut -d":" -f1 | cut -d"/" -f3`
1077        fi
1078
1079        ### sync ###
1080        echo "[update.sh] sync"
1081        killall infobox
1082        infobox -pos -1 75% 20 Aktualisierung "     synchronisieren     " &
1083        if [ "$boxtype" = "atemio520" ] || [ "$boxtype" = "atemio530" ] || [ "$boxtype" = "spark" ] || [ "$boxtype" = "ipbox91" ]; then
1084                echo "Sync" > /dev/$vfd
1085        else
1086                echo "Sync" > /dev/$vfd
1087        fi
1088        sync
1089        sleep 2
1090
1091        ### umount ###
1092        echo "[update.sh] umount /dev/$target"
1093        killall infobox
1094        infobox -pos -1 75% 20 Aktualisierung "   umount /dev/$target   " &
1095        if [ "$boxtype" = "atemio520" ] || [ "$boxtype" = "atemio530" ] || [ "$boxtype" = "spark" ] || [ "$boxtype" = "ipbox91" ]; then
1096                echo "umnt" > /dev/$vfd
1097        else
1098                echo "umount" > /dev/$vfd
1099        fi
1100        umount -fl "/dev/$target"
1101        umount -fl "/dev/$target"
1102        umount -fl "/dev/$target"
1103        sleep 2
1104
1105        ### format ###
1106        echo "[update.sh] mkfs.ext2 -L $label -b 4096 /dev/$target"
1107        killall infobox
1108        infobox -pos -1 75% 20 Aktualisierung " mkfs.ext2 -L $label -b 4096 /dev/$target " &
1109        if [ "$boxtype" = "atemio520" ] || [ "$boxtype" = "atemio530" ] || [ "$boxtype" = "spark" ] || [ "$boxtype" = "ipbox91" ]; then
1110                echo "mkfs" > /dev/$vfd
1111        else
1112                echo "mkfs.ext2" > /dev/$vfd
1113        fi
1114        mkfs.ext2 -L "$label" -b 4096 -I128 "/dev/$target"
1115        ret=$?
1116        sleep 2
1117
1118        ### mount ###
1119        echo "[update.sh] mount /dev/$target /tmp/mnt"
1120        killall infobox
1121        infobox -pos -1 75% 20 Aktualisierung "  mount /dev/$target /tmp/mnt  " &
1122        if [ "$boxtype" = "atemio520" ] || [ "$boxtype" = "atemio530" ] || [ "$boxtype" = "spark" ] || [ "$boxtype" = "ipbox91" ]; then
1123                echo "mnt" > /dev/$vfd
1124        else
1125                echo "mount" > /dev/$vfd
1126        fi
1127        mkdir /tmp/mnt
1128        mount "/dev/$target" /tmp/mnt
1129        sleep 2
1130
1131        ### remove if mkfs fail ###
1132        if [ $ret -ne 0 ]; then
1133                echo "[update.sh] mkfs fail, use rm -rf /tmp/mnt"
1134                infobox -pos -1 75% 20 Aktualisierung "  mkfs Fehler, rm -rf /tmp/mnt  " &
1135                if [ "$boxtype" = "atemio520" ] || [ "$boxtype" = "atemio530" ] || [ "$boxtype" = "spark" ] || [ "$boxtype" = "ipbox91" ]; then
1136                        echo "rem" > /dev/$vfd
1137                else
1138                        echo "remove" > /dev/$vfd
1139                fi
1140                mount /tmp/lib /lib
1141                rm -rf /tmp/mnt
1142                sleep 2
1143        fi
1144
1145        ### copy image ###
1146        echo "[update.sh] tar -zxvf $file -C /tmp/mnt"
1147        killall infobox
1148        tar.info -zxvf "$file" -C /tmp/mnt
1149        sleep 2
1150
1151        ### sync ###
1152        echo "[update.sh] sync"
1153        killall infobox
1154        infobox -pos -1 75% 20 Aktualisierung "     synchronisieren     " &
1155        if [ "$boxtype" = "atemio520" ] || [ "$boxtype" = "atemio530" ] || [ "$boxtype" = "spark" ] || [ "$boxtype" = "ipbox91" ]; then
1156                echo "Sync" > /tmp/$vfd
1157        else
1158                echo "Sync" > /tmp/$vfd
1159        fi
1160        sync
1161        sleep 2
1162
1163        ### umount ###
1164        echo "[update.sh] umount /dev/$target"
1165        killall infobox
1166        infobox -pos -1 75% 20 Aktualisierung "   umount /dev/$target   " &
1167        if [ "$boxtype" = "atemio520" ] || [ "$boxtype" = "atemio530" ] || [ "$boxtype" = "spark" ] || [ "$boxtype" = "ipbox91" ]; then
1168                echo "umnt" > /tmp/$vfd
1169        else
1170                echo "umount" > /tmp/$vfd
1171        fi
1172        umount "/dev/$target"
1173fi
1174
1175### make all clean and reboot ###
1176sleep 2
1177killall infobox
1178infobox -pos -1 70% 10010 Aktualisierung "Aktualisierung abgeschlossen!" "Neustart in 10 Sekunden" &
1179for i in 9 8 7 6 5 4 3 2 1 0; do
1180        if [ "$boxtype" = "atemio520" ] || [ "$boxtype" = "atemio530" ] || [ "$boxtype" = "spark" ] || [ "$boxtype" = "ipbox91" ] || [ "$boxtype" = "atemio6000" ] || [ "$boxtype" = "atemio6100" ]; then
1181                echo "Re $i" > /dev/$vfd
1182        else
1183                echo "Neustart ($i)" > /dev/$vfd
1184        fi
1185        sleep 1
1186done
1187
1188echo "[update.sh] reboot"
1189
1190start_sec.sh 2 /tmp/umount -ttmpfs -a -r
1191start_sec.sh 2 /tmp/umount -tnoproc,noprocfs,nodevfs,nosysfs,nousbfs,nousbdevfs,nodevpts -d -a -r
1192start_sec.sh 2 /tmp/mount -n -o remount,ro /
1193if [ "$boxtype" = "ipbox91" ] || [ "$boxtype" = "ipbox910" ] || [ "$boxtype" = "ipbox900" ] || [ "$boxtype" = "ipbox9000" ]; then
1194        /tmp/cubefpctl --reboot
1195fi
1196
1197#echo "update.sh init 6"
1198#init 6 &
1199echo "update.sh sleep 10"
1200sleep 10
1201echo "update.sh reboot"
1202/tmp/reboot -f
1203reboot -f
Note: See TracBrowser for help on using the repository browser.