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

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

fix

  • Property svn:executable set to *
File size: 35.9 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                                        imagefs=$(getboxbranding imagefs)
398                                        if [ "$imagefs" = "ubinfi" ];then
399                                                infobox -pos -1 75% 10065 "UPDATENFI" "            Schreibe Daten            " &
400                                                mkdir /tmp/ramfs
401                                                mount -t ramfs ramfs /tmp/ramfs                         
402                                                cp "$file" /tmp/ramfs/flash.nfi
403                                                rm "$file"
404                                                nfiwrite -l -b -r -s -f -v /tmp/ramfs/flash.nfi
405                                        else
406                                                tmp=/tmp
407                                                showtime=33
408                                                if [ "$board" = "hd51" ];then showtime=40 ;fi
409                                                infobox -pos -1 75% 100$showtime "UPDATEUSB" "            Entpacke Image            " &
410
411                                                time unzip "$file" -x $board/*.img -x usb_update.bin -d /tmp
412                                                rm -f "$file"
413
414                                                sync
415
416                                                imagedir=$(getboxbranding imagedir)
417                                                mtdrootfs=$(getboxbranding mtdrootfs)
418                                                mtdkernel=$(getboxbranding mtdkernel)
419                                                killall infobox
420                                                ofgwrite -r$mtdrootfs -k$mtdkernel $tmp/$imagedir
421                                                exit
422                                        fi
423                                elif [ "$board" = "dm520" ];then
424                                        infobox -pos -1 75% 10125 "UPDATEUSB" "            Schreibe Daten            " &
425                                        unzip "$file" -d /tmp
426                                        flash-kernel /tmp/kernel.bin
427                                        helproot=/tmp/helproot
428                                        if [ ! -d $helproot ]; then
429                                                mkdir $helproot
430                                        else
431                                                umount -l $helproot
432                                        fi
433                                        mount -t ubifs ubi0:dreambox-rootfs $helproot
434                                        erase_root $helproot
435                                        tar -xvjf /tmp/rootfs.tar.bz2 --exclude=./mnt --exclude=./var/media -C $helproot
436                                elif [ "$board" = "dm900" ] || [ "$board" = "dm920" ] || [ "$board" = "wetek" ] || [ "$board" = "hd51" ];then
437                                        showtime=33
438                                        if [ "$board" = "hd51" ];then showtime=40 ;fi
439
440                                        infobox -pos -1 75% 100$showtime "UPDATEUSB" "            Schreibe Daten            " &
441
442                                        if [ -d /tmp/$board ]; then
443                                                rm -r /tmp/$board
444                                        fi
445                                        time unzip "$file" -x $board/*.img -d /tmp
446                                        rm -f "$file"
447                                        time flash-kernel /tmp/$board/kernel.bin
448
449                                        sync
450# log to /var/swap/logs not working...
451#                                       /etc/init.d/autofs stop
452                                        umount -l /mnt
453
454                                        helproot=/tmp/helproot
455                                        if [ ! -d $helproot ]; then
456                                                mkdir $helproot
457                                        else
458                                                umount -l $helproot
459                                        fi
460                                        mount /dev/root $helproot
461
462                                        time erase_root $helproot
463#                                       time tar -xvf /tmp/$board/rootfs.tar --exclude=./mnt --exclude=./var/media -C $helproot
464                                        time tar -xvjf /tmp/$board/rootfs.tar.bz2 --exclude=./mnt --exclude=./var/media -C $helproot
465
466                                fi
467                        elif [ "$part" = "UPDATENFI" ];then
468                                infobox -pos -1 75% 10065 "UPDATENFI" "            Schreibe Daten            " &
469                                mkdir /tmp/ramfs
470                                mount -t ramfs ramfs /tmp/ramfs                         
471                                cp "$file" /tmp/ramfs/flash.nfi
472                                rm "$file"
473                                nfiwrite -l -b -r -s -f -v /tmp/ramfs/flash.nfi
474                        elif [ "$part" = "KERNEL" ];then
475                                echo /tmp/mv -f "$file" /tmp/kernel.bin
476                                /tmp/mv -f "$file" /tmp/kernel.bin
477                                killall infobox
478                                #infobox -pos -1 75% 10010 "Kernel" "            Schreibe Daten            " &
479                                if [ "$boxtype" = "vusolo2" ];then
480                                        #/sbin/fuser -k /dev/dvb/adapter0/frontend0
481                                        echo /tmp/ofgwrite --kernel=mtd2 /tmp
482                                        /tmp/ofgwrite --kernel=mtd2 /tmp
483                                elif [ "$boxtype" = "dm520" ] || [ "$boxtype" = "dm525" ];then
484                                        echo /tmp/ofgwrite -nk /tmp
485                                        /tmp/ofgwrite -nk /tmp
486                                else
487                                        echo /tmp/ofgwrite -k /tmp
488                                        /tmp/ofgwrite -k /tmp
489                                fi
490                        elif [ "$part" = "ROOT" ];then
491                                if [ "$arch" = "mipsel" ] || [ "$arch" = "arm" ];then
492                                        touch /tmp/.init3
493                                        touch /tmp/.update
494                                fi
495                                killall infobox
496                                echo /tmp/mv -f "$file" /tmp/rootfs.bin
497                                /tmp/mv -f "$file" /tmp/rootfs.bin
498                                if [ "$boxtype" = "vusolo2" ];then
499                                        #/sbin/fuser -k /dev/dvb/adapter0/frontend0
500                                        echo /tmp/ofgwrite --rootfs=mtd0 /tmp
501                                        /tmp/ofgwrite --rootfs=mtd0 /tmp
502                                elif [ "$boxtype" = "dm520" ] || [ "$boxtype" = "dm525" ];then
503                                        echo /tmp/ofgwrite_bin -r /tmp
504#                                       mount -r -o remount /
505#                                       /tmp/ubiformat /dev/mtd0 -f /tmp/rootfs.bin -D
506
507                                        echo /tmp/ofgwrite -r /tmp
508                                        /tmp/ofgwrite -r /tmp
509                                else
510                                        echo /tmp/ofgwrite -r /tmp
511                                        /tmp/ofgwrite -r /tmp
512                                fi
513#                               mount -r -o remount /
514#                               /tmp/ubiformat /dev/mtd0 -f /tmp/rootfs.bin -D
515                        fi
516                        ret=$?         
517                elif [ "$boxtype" = "ufs913" ];then
518                        if [ "$part" = "KERNEL" ];then
519                                /tmp/flashcp -v "Write: $part" "$boxtype" "$file" /tmp/"$mtd"
520                        else
521                                echo /tmp/nandwrite -p /tmp/"$mtd" "$file"
522                                /tmp/nandwrite -p /tmp/"$mtd" "$file"
523                        fi
524                        ret=$?
525                elif [ "$nandbox" = "1" ]; then
526                        echo /tmp/nandwrite -p /tmp/"$mtd" "$file"
527                        /tmp/nandwrite -p /tmp/"$mtd" "$file"
528                        ret=$?
529                else
530                        /tmp/flashcp -v "Write: $part" "$boxtype" "$file" /tmp/"$mtd"
531                        ret=$?
532                fi
533                if [ $ret -eq 0 ]; then break; fi
534                infobox -pos -1 70% 9999 "Aktualisierung" "ACHTUNG: Aktualisierung fehlgeschlagen" " " "OK = Weiter" "Blau = Aktualisierung wiederholen" &
535                if [ "$boxtype" = "atemio520" ] || [ "$boxtype" = "atemio530" ] || [ "$boxtype" = "spark" ] || [ "$boxtype" = "ipbox91" ] || [ "$boxtype" = "atemio6000" ] || [ "$boxtype" = "atemio6100" ]; then
536                        echo "Err " > /tmp/$vfd
537                else
538                        echo "Fehlgeschlagen ?" > /tmp/$vfd
539                fi
540                abfrage /tmp/$event; ret=$?
541                echo " " > /tmp/$vfd
542                killall infobox
543                if [ "$part" = "UPDATEUSB" ];then
544                        echo "sync" > /tmp/$vfd
545                        sync
546                        echo " " > /tmp/$vfd
547                fi
548                if [ $ret -eq 0 ]; then break; fi
549        done
550}
551
552killproc()
553{
554        count=0
555        lastcount=`ps | tail -n1 | sed "s/ \+/ /g;s/^ //" | cut -d" " -f1`
556        if [ "$boxtype" == "ufs910" ] || [ "$boxtype" == "ufs922" ]; then
557                excludes="^ini inetd automount evremote2 telnetd update.sh infobox lircd"
558        else
559                excludes="^ini inetd automount evremote2 telnetd update.sh infobox lircd enigma2.sh dvb_server init_client oscam gbox cccam $swtype"
560        fi
561        while true; do
562                count=$((count + 1))
563                if [ -e "/proc/$count/cmdline" ]; then
564                        cmd=`cat "/proc/$count/cmdline"`
565                        if [ ! -z "$cmd" ]; then
566                                treffer=0
567                                for exclude in $excludes; do
568                                        if echo "$cmd" | grep -q "$exclude"; then treffer=1; fi
569                                done
570                                if [ $treffer -eq 0 ]; then
571                                        echo "[update.sh] killing pid=$count cmd=$cmd"
572                                        kill -9 "$count"
573                                fi
574                        fi
575                fi
576                if [ $count -ge $lastcount ]; then break; fi
577        done
578}
579
580kill_and_show()
581{
582        if [ -z "$killandshow" ]; then
583                killall infobox
584                infobox -pos -1 75% 9999 "Info" "            Laufende Prozesse beenden            " "            Bitte warten            " &
585       
586                killandshow="1"
587                emu.sh stop
588                killall -9 rcS
589                killproc
590                echo "3" > /proc/sys/vm/drop_caches
591#       FIXME: kills update.sh why???
592#               /sbin/fuser -k /dev/dvb/adapter0/frontend0
593#               /sbin/fuser -k /dev/dvb/adapter0/frontend1
594#               echo "0" > /proc/progress
595
596                if [ "$boxtype" == "ufs910" ] || [ "$boxtype" == "ufs922" ]; then
597                        echo "[workaround] killall -9 $swtype"
598                        killall -9 $swtype
599                        infobox 1 "nobox#/var/etc/boot/start.jpg"
600                else
601                        skip1=1
602                fi
603                killall infobox
604        fi
605}
606
607error()
608{
609        killall infobox
610        infobox -pos -1 70% 10010 "Aktualisierungsfehler!" "$1" "" "Neustart in 10 Sekunden" &
611        echo "[update.sh] $1"
612        for i in 9 8 7 6 5 4 3 2 1 0; do
613                if [ "$boxtype" = "atemio520" ] || [ "$boxtype" = "atemio530" ] || [ "$boxtype" = "spark" ] || [ "$boxtype" = "ipbox91" ] || [ "$boxtype" = "atemio6000" ] || [ "$boxtype" = "atemio6100" ]; then
614                        echo "Rb $i" > /dev/$vfd
615                else
616                        echo "$2 ($i)" > /dev/$vfd
617                fi
618                sleep 1
619        done
620        if [ "$boxtype" = "atemio520" ] || [ "$boxtype" = "atemio530" ] || [ "$boxtype" = "spark" ] || [ "$boxtype" = "ipbox91" ] || [ "$boxtype" = "atemio6000" ] || [ "$boxtype" = "atemio6100" ]; then
621                echo "Ende" > /dev/$vfd
622        else
623                echo "Neustart" > /dev/$vfd
624        fi
625        echo "[update.sh] reboot"
626#       init 6
627        /tmp/reboot -f
628        reboot -f
629        exit
630}
631
632got_mtd_part()
633{
634        if [ "$part" == "UPDATENFI" ] || [ "$part" == "UPDATEUSB" ];then
635                mtd=mtddisabled
636        else
637                mtd=`cat /proc/mtd | grep -i "$part" | cut -d":" -f1 | tail -n1`
638                echo "[update.sh] Part $part: mtd=$mtd"
639                ### check mtd part ###
640                if [ -z "$mtd" ] || [ `echo -e "$mtd" | wc -l` -ne 1 ] || [ "${mtd:0:3}" != "mtd" ] || ([ "$mtd" == "mtd0" ] && [ "$arch" = "sh4" ]); then
641                        error "Uncorrect MTD Partition: $mtd" "MTD err"
642                fi
643        fi
644}
645
646md5_check()
647{
648        if [ "$source" == "online" ];then
649                md5=`md5sum "$file" | cut -d"/" -f1 | tr -d " "`
650                echo "[update.sh] md5=$md5"
651                md5file=`cat "$file_md5" | tr -d " "`
652                echo "[update.sh] md5file=$md5file"
653                if [ "$md5" != "$md5file" ]; then
654                        error "MD5 check failed" "MD5 err"
655                fi
656        fi
657}
658
659got_online_img()
660{
661        if [ "$source" == "online" ];then
662                killall infobox
663                infobox -pos -1 75% 3 Aktualisierung "  Lade Image und MD5  " &
664                if [ "$boxtype" = "atemio520" ] || [ "$boxtype" = "atemio530" ] || [ "$boxtype" = "spark" ] || [ "$boxtype" = "ipbox91" ] || [ "$boxtype" = "atemio6000" ] || [ "$boxtype" = "atemio6100" ]; then
665                        echo "Lade" > /tmp/$vfd
666                else
667                        echo "Lade Image" > /tmp/$vfd
668                fi
669                cd "$tmp"
670                rm -f "$base"
671                rm -f "$base_md5"
672                sleep 3
673                killall infobox
674
675                wget.info -T15 "$url/$urldir/$folder/$base"
676                wget.info -T15 "$url/$urldir/$folder/$base_md5"
677
678                killall infobox
679                infobox -pos -1 75% 20 Aktualisierung "    Laden abgeschlossen    " &
680                if [ "$boxtype" = "atemio520" ] || [ "$boxtype" = "atemio530" ] || [ "$boxtype" = "spark" ] || [ "$boxtype" = "ipbox91" ]; then
681                        echo "Ok" > /tmp/$vfd
682                elif [ "$boxtype" = "atemio6000" ] || [ "$boxtype" = "atemio6100" ];then
683                        echo "Done" > /tmp/$vfd
684                else
685                        echo "Laden fertig" > /tmp/$vfd
686                fi
687        fi
688}
689
690copy_to_tmp()
691{
692        if [ ! -e "$tmp/$base" ]; then
693                killall infobox
694                infobox -pos -1 75% 100 Aktualisierung "  Kopiere Image nach $tmp  " &
695                if [ "$boxtype" = "atemio520" ] || [ "$boxtype" = "atemio530" ] || [ "$boxtype" = "spark" ] || [ "$boxtype" = "ipbox91" ]; then
696                        echo "Kopi" > /tmp/$vfd
697                elif [ "$boxtype" = "atemio6000" ] || [ "$boxtype" = "atemio6100" ];then
698                        echo "Copy" > /tmp/$vfd
699                else
700                        echo "Kopiere" > /tmp/$vfd
701                fi
702                cp "$file" "$tmp/$base"
703        fi
704        if [ ! -e "$tmp/$base_md5" ]; then
705                cp "$file_md5" "$tmp/$base_md5"
706        fi
707        file="$tmp/$base"
708        file_md5="$tmp/$base_md5"
709}
710
711file_check()
712{
713        if [ ! -e "$file" ]; then
714                error "Missing: File" "no file"
715        fi
716        if [ ! -e "$file_md5" ] && [ "$source" == "online" ]; then
717                error "Missing: MD5 File" "no MD5"
718        fi
719}
720
721got_basename()
722{
723        if [ "$targetfull" != "fullbackup" ];then
724                file=`echo "$origfile" | sed "s/_FULL_/_${part}_/"`
725        fi
726#       file_md5="${file%.*}"; file_md5="${file_md5%.*}"; file_md5="$file_md5.md5"
727        file_md5="${file%.*}".md5;
728#       file_md5=`echo $file | sed 's/.img/.md5/' | sed 's/.tar.gz/.md5/'`
729        base=`basename "$file"`
730        base_md5=`basename "$file_md5"`
731}
732
733make_tmp()
734{
735        mkdir /tmp/mktmp
736        mkdir /tmp/lib
737        cp /bin/busybox /tmp
738        cp /bin/infobox /tmp
739        cp /bin/flashcp /tmp
740        if [ "$arch" == "mipsel" ] || [ "$arch" = "arm" ];then
741                cp /sbin/wget /tmp
742        fi
743        if [ -e /bin/cubefpctl ]; then cp /bin/cubefpctl /tmp; fi
744        cp /sbin/halt /tmp
745        cp /mnt/network/resolv.conf /tmp
746        cp /bin/flash_eraseall /tmp
747        cp /bin/grep /tmp
748
749#       cp /lib/ld.so.1 /tmp/lib                #for busybox
750#       cp -a /lib/ld-linux.so.* /tmp/lib               #for busybox
751#       cp -a /lib/libc.so.* /tmp/lib                           #for busybox
752#       cp -a /lib/libcrypt.so.* /tmp/lib               #for busybox
753#       cp -a /lib/libfreetype.so.* /tmp/lib    #for infobox
754#       cp -a /lib/libz.so.* /tmp/lib                           #for infobox
755#       cp -a /lib/libm.so.* /tmp/lib                           #for infobox
756#       cp -a /lib/libgcc_s.so.* /tmp/lib               #for infobox
757#       cp -a /lib/libjpeg.so.* /tmp/lib                #for infobox
758#       cp -a /lib/libpng* /tmp/lib             #for infobox   
759#       cp -a /lib/libbz2.so.* /tmp/lib         #for infobox
760
761#p217 github duckbox
762        cp -a /lib/ld.so.1 /tmp/lib
763        cp -a /lib/ld-* /tmp/lib
764        cp -a /lib/libc.* /tmp/lib
765        cp -a /lib/libc-* /tmp/lib
766        cp -a /lib/libcrypt.* /tmp/lib
767        cp -a /lib/libcrypt-* /tmp/lib
768        cp -a /lib/libfreetype.so.* /tmp/lib
769        cp -a /lib/libz-* /tmp/lib
770        cp -a /lib/libz.* /tmp/lib
771        cp -a /lib/libm.* /tmp/lib
772        cp -a /lib/libm-* /tmp/lib
773        cp -a /lib/libgcc_s* /tmp/lib
774        cp -a /lib/libjpeg.so.* /tmp/lib
775        cp -a /lib/libpng* /tmp/lib
776        cp -a /lib/libbz2.so.* /tmp/lib
777
778        if [ "$arch" == "sh4" ];then
779                cp /lib/libcrypto.so.* /tmp/lib         #for wget
780                cp /lib/libssl.so.* /tmp/lib            #for wget
781        fi
782
783        if [ "$target" = "UPDATEUSB" ]; then
784                cp /lib/ld* /tmp/lib            #for busybox
785                cp /lib/libc.so.6 /tmp/lib                              #for busybox
786                cp /lib/libcrypt.so.1 /tmp/lib          #for busybox
787                cp /usr/lib/libfreetype.so.6 /tmp/lib   #for infobox
788                cp /lib/libz.so.1 /tmp/lib                              #for infobox
789                cp /lib/libm.so.6 /tmp/lib                              #for infobox
790                cp /lib/libgcc_s.so.1 /tmp/lib          #for infobox
791                cp /usr/lib/libjpeg.so.62 /tmp/lib              #for infobox
792                cp /usr/lib/libjpeg.so.8 /tmp/lib               #for infobox
793                cp /usr/lib/libpng15.so.15 /tmp/lib             #for infobox
794                cp /lib/libbz2* /tmp/lib                #for infobox
795                cp /usr/lib/libcrypto* /tmp/lib         #for wget
796                cp /lib/libssl* /tmp/lib                #for wget
797                cp /usr/share/fonts/default.ttf /tmp    # for infobox
798
799                cp /lib/libresolv.so* /tmp/lib          #for gzip
800                cp /lib/librt* /tmp/lib         #for automount
801                cp /usr/lib/libcrypt.* /tmp/lib         #for sleep
802
803                cp /lib/libpam.so* /tmp/lib             #for login
804                cp /lib/libpam_misc.so* /tmp/lib                #for login
805
806                cp -a /lib/libtinfo.so.* /tmp/lib
807                cp /usr/sbin/flash-kernel /tmp
808                cp /usr/sbin/librecovery /tmp
809                cp /usr/bin/unzip /tmp
810                cp /bin/rm /tmp
811        fi
812
813        cp /usr/share/fonts/default.ttf /tmp    # for infobox
814        cp /sbin/sleepms /tmp
815
816        cat /sbin/abfrage | sed "s#/usr/bin/awk#/tmp/awk#" > /tmp/abfrage
817        chmod 777 /tmp/abfrage
818        cat /sbin/emu.sh | sed "s#/bin/sh#/tmp/sh#" > /tmp/emu.sh
819        chmod 777 /tmp/emu.sh
820        cat /sbin/wget.info | sed "s#/bin/sh#/tmp/sh#" > /tmp/wget.info
821        chmod 777 /tmp/wget.info
822        cat /sbin/start_sec.sh | sed "s#/bin/sh#/tmp/sh#" > /tmp/start_sec.sh
823        chmod 777 /tmp/start_sec.sh
824
825        if [ "$boxtype" = "ipbox91" ] || [ "$boxtype" = "ipbox910" ] || [ "$boxtype" = "ipbox900" ] || [ "$boxtype" = "ipbox9000" ]; then
826                ln -s /tmp/halt /tmp/reboot
827        elif [ "$arch" = "mipsel" ] || [ "$arch" = "arm" ];then
828                cp /sbin/reboot.sysvinit /tmp/reboot
829                cp /usr/bin/ofgwrite /tmp
830                cp /usr/sbin/ubiformat /tmp
831        else
832                ln -s /tmp/busybox /tmp/reboot
833        fi
834        if [ "$arch" = "sh4" ];then
835                ln -s /tmp/busybox /tmp/wget
836        fi
837        ln -s /tmp/busybox /tmp/killall
838        ln -s /tmp/busybox /tmp/sleep
839        ln -s /tmp/busybox /tmp/awk
840        ln -s /tmp/busybox /tmp/dd
841        ln -s /tmp/busybox /tmp/time
842        ln -s /tmp/busybox /tmp/sync
843        ln -s /tmp/busybox /tmp/mount
844        ln -s /tmp/busybox /tmp/umount
845        ln -s /tmp/busybox /tmp/mkdir
846        ln -s /tmp/busybox /tmp/echo
847        ln -s /tmp/busybox /tmp/sed
848        ln -s /tmp/busybox /tmp/cut
849        ln -s /tmp/busybox /tmp/tail
850        ln -s /tmp/busybox /tmp/tr
851        ln -s /tmp/busybox /tmp/date
852        ln -s /tmp/busybox /tmp/basename
853        ln -s /tmp/busybox /tmp/tar
854        ln -s /tmp/busybox /tmp/cat
855        ln -s /tmp/busybox /tmp/wc
856        ln -s /tmp/busybox /tmp/rm
857        ln -s /tmp/busybox /tmp/touch
858        ln -s /tmp/busybox /tmp/ash
859        ln -s /tmp/busybox /tmp/mv
860        ln -s /tmp/ash /tmp/sh
861
862        if [ "$arch" = "mipsel" ];then
863                ln -s /proc/vfd /tmp/vfd
864                cp -aL /dev/mtd0 /tmp/mtd0
865                cp -aL /dev/dbox/oled0 /tmp
866        elif [ "$arch" = "arm" ];then
867                cp -aL /dev/mtd0 /tmp/mtd0
868                cp -aL /dev/dbox/oled0 /tmp
869                ln -s /tmp/oled0 /tmp/vfd
870        else
871                cp -aL /dev/vfd /tmp/vfd
872        fi
873        cp -aL /dev/mtd1 /tmp/mtd1
874        cp -aL /dev/mtd2 /tmp/mtd2
875        cp -aL /dev/mtd3 /tmp/mtd3
876        cp -aL /dev/mtd4 /tmp/mtd4
877        cp -aL /dev/mtd5 /tmp/mtd5
878        cp -aL /dev/mtd6 /tmp/mtd6
879        cp -aL /dev/mtd7 /tmp/mtd7
880        cp -aL /dev/mtd8 /tmp/mtd8
881        cp -aL /dev/mtd9 /tmp/mtd9
882        cp -aL /dev/input/$event /tmp/$event
883        cp -aL /dev/mtdblock2 /tmp/mtdblock2
884        cp -aL /dev/mtdblock3 /tmp/mtdblock3
885        cp -aL /dev/mtdblock4 /tmp/mtdblock4
886        cp -aL /dev/mtdblock5 /tmp/mtdblock5
887        cp -aL /dev/mtdblock6 /tmp/mtdblock6
888
889        if [ "$nandbox" = "1" ] || [ "$boxtype" = "ufs913" ]; then
890                cp /bin/nandwrite /tmp
891                cp /lib/libpthread.so.0 /tmp/lib
892                cp /lib/libdl.so.2 /tmp/lib
893        fi
894
895        if [ "$arch" = "mipsel" ] || [ "$arch" = "arm" ]; then
896                echo copy nandwrite flash_erase
897                cp /usr/sbin/nandwrite /tmp
898                cp /usr/sbin/flash_erase  /tmp
899                touch /tmp/.update
900        fi
901
902        if [ "$update_to" == "usb" ] || [ "$update_to" == "ba" ]; then
903                cat /sbin/tar.info | sed "s#/bin/sh#/tmp/sh#" > /tmp/tar.info
904                chmod 777 /tmp/tar.info
905                cp /sbin/mke2fs /tmp/mktmp
906                cp /sbin/fw_setenv /tmp
907                cp /sbin/fw_printenv /tmp
908                cp /mnt/network/resolv.conf /tmp
909                ln -s /tmp/mktmp/mke2fs /tmp/mktmp/mkfs.ext2
910        fi
911
912        PATH="/tmp:$PATH"
913        PATH="/tmp/mktmp:$PATH"
914        export PATH
915        LD_LIBRARY_PATH="/lib;/usr/lib;/tmp/lib"
916        export LD_LIBRARY_PATH
917}
918
919erase_root()
920{
921        echo "erase root"
922        rm -rf $1/var/bin
923        rm -rf $1/var/lib
924        rm -rf $1/var/usr
925        rm -rf $1/var/etc
926        rm -rf $1/usr/bin
927        rm -rf $1/usr/lib
928        rm -rf $1/usr/sbin
929        #rm -rf $1/lib
930        rm -rf $1/etc
931        rm -rf $1/sbin
932        rm -rf $1/boot
933        #rm -f $1/ba
934        rm -f $1/.swfinfo
935        #rm -f $1/.smb
936        #rm -f $1/.cache
937        rm -rf $1/bin
938}
939
940### stop E2 (not TV) ###
941killall -stop $swtype
942
943### change tmp if image is to big for /tmp ###
944if [ "$bigimage" == "1" ]; then
945        tmp=`dirname "$file"`
946fi
947
948### show beginning of update ###
949infobox -pos -1 75% 20 "Aktualisierung" "  Start: bitte warten  " &
950if [ "$boxtype" = "atemio520" ] || [ "$boxtype" = "atemio530" ] || [ "$boxtype" = "spark" ] || [ "$boxtype" = "ipbox91" ] || [ "$boxtype" = "atemio6000" ] || [ "$boxtype" = "atemio6100" ]; then
951        echo "Star" > /dev/$vfd
952else
953        echo "Aktualisierung gestartet" > /dev/$vfd
954fi
955sleep 3
956
957### save orig filename ###
958origfile="$file"
959got_basename
960
961### kill unneedet prozess and showiframe ###
962if [ "$boxtype" = "ufs910" ] || [ "$boxtype" = "ufs922" ]; then
963        kill_and_show
964fi
965
966if [ "$update_to" == "flash" ]; then swap.sh swapalloff; fi
967
968### remove tmp, exclude img and md5 ###
969targetlist="FULL $target"
970for part in $targetlist; do
971        got_basename
972        skipliste="$skipliste $file"
973done
974
975TEXT="| grep -v"
976for ROUND in $skipliste; do
977        SKIP="$SKIP $TEXT \"$ROUND\""
978done
979
980echo "find $tmp -xdev | "grep -v "^$tmp$" "$SKIP" > /tmp/tmp.cmd
981chmod 755 /tmp/tmp.cmd
982/tmp/tmp.cmd > /tmp/tmp.list
983
984tlist=`cat /tmp/tmp.list`
985rm -f /tmp/tmp.list
986for t in $tlist; do
987        mountpoint -q "$t"
988        if [ $? -ne 0 ]; then
989                echo "$t" >> /tmp/tmp.list
990        fi
991done
992
993rm -rf `cat /tmp/tmp.list`
994got_basename
995# not working if image directly in /tmp
996#rm -rf `find $tmp | grep -v "^$tmp$" | grep -v "$base" | grep -v "$base_md5"`
997
998
999### copy all needet files to tmp ###
1000make_tmp
1001
1002for part in $target; do
1003        ### make filename ###
1004        got_basename
1005
1006        ### if source=online, got online image and .md5 file ###
1007        got_online_img
1008
1009        ### copy img and md5 to tmp if not in tmp ###
1010        if [ "$source" = "online" ];then
1011                copy_to_tmp
1012        fi
1013
1014        ### check ###
1015        killall infobox
1016        infobox -pos -1 75% 20 Aktualisierung "    Überprüfe Image    " &
1017        if [ "$boxtype" = "atemio520" ] || [ "$boxtype" = "atemio530" ] || [ "$boxtype" = "spark" ] || [ "$boxtype" = "ipbox91" ] || [ "$boxtype" = "atemio6000" ] || [ "$boxtype" = "atemio6100" ]; then
1018                echo "Uery" > /tmp/$vfd
1019        else
1020                echo "Verify" > /tmp/$vfd
1021        fi
1022        sleep 3
1023
1024        ### check if img and md5 is in tmp ###
1025        file_check
1026
1027        ### check md5 ###
1028        md5_check
1029
1030        killall infobox
1031        infobox -pos -1 75% 20 Aktualisierung "    Überprüfung OK    " &
1032
1033        if [ "$boxtype" = "atemio520" ] || [ "$boxtype" = "atemio530" ] || [ "$boxtype" = "spark" ] || [ "$boxtype" = "ipbox91" ] || [ "$boxtype" = "atemio6000" ] || [ "$boxtype" = "atemio6100" ]; then
1034                echo "Done" > /tmp/$vfd
1035        else
1036                echo "OK" > /tmp/$vfd
1037        fi
1038
1039        sleep 3
1040done
1041
1042for part in $target; do
1043        got_basename
1044        file="$tmp/$base"
1045
1046        ### kill unneedet prozess and showiframe ###
1047        echo "[update.sh] check box: $boxtype part: $part"
1048        if [ ! -e /etc/.oebuild ] && ([ "$arch" = "mipsel" ]  || [ "$arch" = "arm" ]) && ([ "$part" = "ROOT" ] || [ "$part" = "UPDATENFI" ] || [ "$part" = "UPDATEUSB" ]); then
1049                kill_and_show
1050        elif [ "$boxtype" = "ufs910" ]; then
1051                kill_and_show   
1052        else
1053                echo "[update.sh] skip kill_and_show"
1054        fi
1055
1056        ### update to flash ###
1057        if [ "$update_to" == "flash" ]; then
1058                killall infobox
1059                if [ "$boxtype" = "atemio520" ] || [ "$boxtype" = "atemio530" ] || [ "$boxtype" = "spark" ] || [ "$boxtype" = "ipbox91" ] || [ "$boxtype" = "atemio6000" ] || [ "$boxtype" = "atemio6100" ]; then
1060                        echo "Upda" > /tmp/$vfd
1061                else
1062                        echo "Update !!!" > /tmp/$vfd
1063                fi
1064
1065                ### got and check mtd part ###
1066                got_mtd_part
1067
1068                ### flash the image ###
1069                if [ "$target" == "FULL" ] || [ "$target" == "ROOT" ] || [ "$target" = "UPDATENFI" ] || [ "$target" = "UPDATEUSB" ]; then mount /tmp/lib /lib; fi
1070                flash_img
1071
1072                if [ "$targetfull" != "fullbackup" ];then
1073                        rm -f "$file"
1074                fi
1075        fi
1076done
1077
1078### update to usb ###
1079if [ "$update_to" == "usb" ]; then
1080        ### got label or device ###
1081        blkid=`blkid -w /dev/null -c /dev/null`
1082        if echo "$target" | grep -q sd[a-z][1-9]; then
1083                label=`echo -e "$blkid" | grep "^/dev/$target:" | grep LABEL= | sed 's/^.*LABEL="//;s/".*$//' | tr -d " " | tr -d "-"`
1084        else
1085                label="$target"
1086                target=`echo -e "$blkid" | grep "LABEL=\"$label\"" | head -n1 | cut -d":" -f1 | cut -d"/" -f3`
1087        fi
1088
1089        ### sync ###
1090        echo "[update.sh] sync"
1091        killall infobox
1092        infobox -pos -1 75% 20 Aktualisierung "     synchronisieren     " &
1093        if [ "$boxtype" = "atemio520" ] || [ "$boxtype" = "atemio530" ] || [ "$boxtype" = "spark" ] || [ "$boxtype" = "ipbox91" ]; then
1094                echo "Sync" > /dev/$vfd
1095        else
1096                echo "Sync" > /dev/$vfd
1097        fi
1098        sync
1099        sleep 2
1100
1101        ### umount ###
1102        echo "[update.sh] umount /dev/$target"
1103        killall infobox
1104        infobox -pos -1 75% 20 Aktualisierung "   umount /dev/$target   " &
1105        if [ "$boxtype" = "atemio520" ] || [ "$boxtype" = "atemio530" ] || [ "$boxtype" = "spark" ] || [ "$boxtype" = "ipbox91" ]; then
1106                echo "umnt" > /dev/$vfd
1107        else
1108                echo "umount" > /dev/$vfd
1109        fi
1110        umount -fl "/dev/$target"
1111        umount -fl "/dev/$target"
1112        umount -fl "/dev/$target"
1113        sleep 2
1114
1115        ### format ###
1116        echo "[update.sh] mkfs.ext2 -L $label -b 4096 /dev/$target"
1117        killall infobox
1118        infobox -pos -1 75% 20 Aktualisierung " mkfs.ext2 -L $label -b 4096 /dev/$target " &
1119        if [ "$boxtype" = "atemio520" ] || [ "$boxtype" = "atemio530" ] || [ "$boxtype" = "spark" ] || [ "$boxtype" = "ipbox91" ]; then
1120                echo "mkfs" > /dev/$vfd
1121        else
1122                echo "mkfs.ext2" > /dev/$vfd
1123        fi
1124        mkfs.ext2 -L "$label" -b 4096 -I128 "/dev/$target"
1125        ret=$?
1126        sleep 2
1127
1128        ### mount ###
1129        echo "[update.sh] mount /dev/$target /tmp/mnt"
1130        killall infobox
1131        infobox -pos -1 75% 20 Aktualisierung "  mount /dev/$target /tmp/mnt  " &
1132        if [ "$boxtype" = "atemio520" ] || [ "$boxtype" = "atemio530" ] || [ "$boxtype" = "spark" ] || [ "$boxtype" = "ipbox91" ]; then
1133                echo "mnt" > /dev/$vfd
1134        else
1135                echo "mount" > /dev/$vfd
1136        fi
1137        mkdir /tmp/mnt
1138        mount "/dev/$target" /tmp/mnt
1139        sleep 2
1140
1141        ### remove if mkfs fail ###
1142        if [ $ret -ne 0 ]; then
1143                echo "[update.sh] mkfs fail, use rm -rf /tmp/mnt"
1144                infobox -pos -1 75% 20 Aktualisierung "  mkfs Fehler, rm -rf /tmp/mnt  " &
1145                if [ "$boxtype" = "atemio520" ] || [ "$boxtype" = "atemio530" ] || [ "$boxtype" = "spark" ] || [ "$boxtype" = "ipbox91" ]; then
1146                        echo "rem" > /dev/$vfd
1147                else
1148                        echo "remove" > /dev/$vfd
1149                fi
1150                mount /tmp/lib /lib
1151                rm -rf /tmp/mnt
1152                sleep 2
1153        fi
1154
1155        ### copy image ###
1156        echo "[update.sh] tar -zxvf $file -C /tmp/mnt"
1157        killall infobox
1158        tar.info -zxvf "$file" -C /tmp/mnt
1159        sleep 2
1160
1161        ### sync ###
1162        echo "[update.sh] sync"
1163        killall infobox
1164        infobox -pos -1 75% 20 Aktualisierung "     synchronisieren     " &
1165        if [ "$boxtype" = "atemio520" ] || [ "$boxtype" = "atemio530" ] || [ "$boxtype" = "spark" ] || [ "$boxtype" = "ipbox91" ]; then
1166                echo "Sync" > /tmp/$vfd
1167        else
1168                echo "Sync" > /tmp/$vfd
1169        fi
1170        sync
1171        sleep 2
1172
1173        ### umount ###
1174        echo "[update.sh] umount /dev/$target"
1175        killall infobox
1176        infobox -pos -1 75% 20 Aktualisierung "   umount /dev/$target   " &
1177        if [ "$boxtype" = "atemio520" ] || [ "$boxtype" = "atemio530" ] || [ "$boxtype" = "spark" ] || [ "$boxtype" = "ipbox91" ]; then
1178                echo "umnt" > /tmp/$vfd
1179        else
1180                echo "umount" > /tmp/$vfd
1181        fi
1182        umount "/dev/$target"
1183fi
1184
1185### make all clean and reboot ###
1186sleep 2
1187killall infobox
1188infobox -pos -1 70% 10010 Aktualisierung "Aktualisierung abgeschlossen!" "Neustart in 10 Sekunden" &
1189for i in 9 8 7 6 5 4 3 2 1 0; do
1190        if [ "$boxtype" = "atemio520" ] || [ "$boxtype" = "atemio530" ] || [ "$boxtype" = "spark" ] || [ "$boxtype" = "ipbox91" ] || [ "$boxtype" = "atemio6000" ] || [ "$boxtype" = "atemio6100" ]; then
1191                echo "Re $i" > /dev/$vfd
1192        else
1193                echo "Neustart ($i)" > /dev/$vfd
1194        fi
1195        sleep 1
1196done
1197
1198echo "[update.sh] reboot"
1199
1200start_sec.sh 2 /tmp/umount -ttmpfs -a -r
1201start_sec.sh 2 /tmp/umount -tnoproc,noprocfs,nodevfs,nosysfs,nousbfs,nousbdevfs,nodevpts -d -a -r
1202start_sec.sh 2 /tmp/mount -n -o remount,ro /
1203if [ "$boxtype" = "ipbox91" ] || [ "$boxtype" = "ipbox910" ] || [ "$boxtype" = "ipbox900" ] || [ "$boxtype" = "ipbox9000" ]; then
1204        /tmp/cubefpctl --reboot
1205fi
1206
1207#echo "update.sh init 6"
1208#init 6 &
1209echo "update.sh sleep 10"
1210sleep 10
1211echo "update.sh reboot"
1212/tmp/reboot -f
1213reboot -f
Note: See TracBrowser for help on using the repository browser.