updater.sh: Final Hotfix 3 script
[pandora-misc.git] / hotfix_updater / updater.sh
1 #!/bin/bash
2
3 # kernels we are sure we want to update
4 oldkern="\
5 3112d1782a90c2c87ae17a152a35deae \
6 b00a5d617f11366689488395b19411de \
7 aed218fe59ff93618bddd2b52b020014 \
8 "
9 newkern=53ca541a471f726eb1103f19d4306e61
10 currkern=$(md5sum /boot/uImage | cut -d" " -f1)
11
12 # u-boot versions we want to update
13 oldubootvers="\
14 U-Boot_2010.03_(May_19_2010_-_18:30:30) \
15 "
16
17 oldinterfaces=23f72750f2f7335b9c2ed3f55aaa5061
18 oldrcwl1251=7a6361e842f0f589418218436affbe07
19 newmmenu=270b2ef3aa8e92e913880fb313857b0a
20 oldmmenu="\
21 d15bf3ad29f12fa2325534b8fcd5c1f4 \
22 fa45e9bc91c48640a9ea592de5fbeb3c \
23 af66a5118a9bfef8eca5de13ee64c6a1 \
24 "
25 currmmenu=$(md5sum /usr/bin/mmenu | cut -d" " -f1)
26 currmmenuconf=$(md5sum /etc/pandora/conf/mmenu.conf | cut -d" " -f1)
27
28 rm /tmp/updater.log
29 rm /tmp/updreboot
30
31 log()
32 {
33   echo "$@" >> /tmp/updater.log
34   echo "$@" >&2
35 }
36
37 rm /tmp/updater_err.log
38
39 err()
40 {
41   echo "$@" >> /tmp/updater_err.log
42 }
43
44 if zenity --question --title="Update Package 3" --text="\
45 This PND updates your Pandora OS. You can safely delete it after it has finished.\n\
46 This pack includes all updates from previous Hotfix Packs as well.\n\n\
47 Do you want to start the upgrade now? " --ok-label="Start now" --cancel-label="Don't do it" ; then
48
49 (
50
51 # Kernel Update
52
53 echo "7"
54 echo "# Updating kernel if needed"
55
56
57 update_kernel()
58 {
59      have_error=false
60
61      rm /boot/uImage.old 
62      needfree=$(ls -lk uImage | grep uImage | cut -d" " -f5)
63      currfree=$(df /boot | grep boot | awk '{print $4}')
64      if [ $currfree -lt $needfree ]; then
65         err "There is not enough diskspace on /boot/ to update the kernel.\nKernel couldn't be updated."
66         log "Kernel not updated - not enough diskspace on /boot/"
67         have_error=true
68      else
69         cp uImage /boot/uImage.new 
70         sync
71         bad_checksum=false
72         currkern=$(md5sum /boot/uImage.new | cut -d" " -f1)
73           if [ "$currkern" = "$newkern" ]; then
74             mv /boot/uImage /boot/uImage.old 
75             mv /boot/uImage.new /boot/uImage 
76             currkern=$(md5sum /boot/uImage | cut -d" " -f1)
77             if [ "$currkern" != "$newkern" ]; then
78                rm /boot/uImage 
79                mv /boot/uImage.old /boot/uImage 
80                bad_checksum=true
81             fi
82           else
83             rm /boot/uImage.new 
84             bad_checksum=true
85           fi
86           if $bad_checksum; then
87             err "There was a checksum error while copying the kernel.\nKernel couldn't be updated. Please check your SD-Card and try to recopy the PND-File."
88             log "Kernel not updated - checksum error"
89             have_error=true
90           fi
91      fi
92
93      if ! $have_error; then
94        log "Kernel successfully updated"
95        echo "The kernel has been updated. You need to restart your system." > /tmp/updreboot
96      fi
97      sync
98 }
99
100 kernel_known=false
101 for oknl in $oldkern $newkern; do
102   if [ "$oknl" = "$currkern" ]; then
103     kernel_known=true
104     break
105   fi
106 done
107
108 if [ "$kernel_known" = "true" -o -z "$currkern" ]; then
109   if [ "$currkern" != "$newkern" ]; then
110     update_kernel
111   else
112     log "Kernel already up-to-date"
113   fi
114 else
115   if zenity --question --title="Custom kernel?" --text="\
116 You seem to have custom or newer kernel in flash.\n\n\
117 Update it anyway?\n\
118 (if unsure, select Yes)" --ok-label="Yes" --cancel-label="No" ; then
119     update_kernel
120   else
121     log "Kernel update skipped"
122   fi
123 fi
124   
125
126 # u-boot Update
127
128 echo "15"
129 echo "# U-Boot if needed"
130
131 update_uboot()
132 {
133   if flash_eraseall /dev/mtd1 && nandwrite -p /dev/mtd1 u-boot.bin; then
134     # XXX: perhaps we need to check if write went ok?
135     log "u-boot.bin flashed."
136   else
137     log "u-boot.bin flashing failed."
138   fi
139 }
140
141 if [ -f u-boot.bin ]; then
142
143   rm /tmp/u-boot.bin.nand 2> /dev/null
144   nanddump -o -b -q -f /tmp/u-boot.bin.nand /dev/mtd1
145   uboot_nand_ver=`strings /tmp/u-boot.bin.nand | grep 'U-Boot 20' | head -n 1 | sed 's/ /_/g'`
146   uboot_ver=`strings u-boot.bin | grep 'U-Boot 20' | head -n 1 | sed 's/ /_/g'`
147   uboot_size=`stat -c %s u-boot.bin`
148
149   dd if=/tmp/u-boot.bin.nand of=/tmp/u-boot.bin.nand.cmp bs=$uboot_size count=1
150   if ! cmp u-boot.bin /tmp/u-boot.bin.nand.cmp
151   then
152     uboot_need_to_ask=true
153     for oldver in $oldubootvers; do
154       if [ "$oldver" = "$uboot_nand_ver" ]; then
155         uboot_need_to_ask=false
156         break
157       fi
158     done
159
160     if $uboot_need_to_ask; then
161       if zenity --question --title="Custom u-boot?" --text="\
162       You seem to have custom or newer u-boot in flash.\n\n\
163       Update it anyway?\n\
164       (if unsure, select Yes)" --ok-label="Yes" --cancel-label="No" ; then
165         update_uboot
166       else
167         log "u-boot update skipped\n(nand has $uboot_nand_ver)"
168       fi
169     else
170       update_uboot
171     fi
172   else
173     log "u-boot already up-to-date\n($uboot_nand_ver)"
174   fi
175 fi
176
177 # Libraries and Programs
178   
179 echo "20"
180 echo "# Installing missing Python libraries"
181 if [ "`opkg list-installed | grep python-shell`" ]; then
182    log "Python libraries were already installed."
183 else 
184   opkg install 1/gnome-vfs-plugin-ftp_2.24.1-r2.5_armv7a.ipk 1/gnome-vfs-plugin-http_2.24.1-r2.5_armv7a.ipk 1/python-pycairo_1.4.0-ml3.5_armv7a.ipk 1/python-pygtk_2.16.0-r1.5_armv7a.ipk 1/python-shell_2.6.4-ml9.1.5_armv7a.ipk 
185   log "Python libraries installed"
186   sync
187 fi
188
189 # Libraries and programs
190
191 echo "35"
192 echo "# Installing Boost Library"
193 if [ "`opkg list-installed | grep boost-system`" ]; then
194   log "Boost library was already installed"
195 else  
196   opkg install 2/boost_1.41.0-r8.1.5_armv7a.ipk 2/boost-filesystem_1.41.0-r8.1.5_armv7a.ipk 2/boost-graph_1.41.0-r8.1.5_armv7a.ipk 2/boost-iostreams_1.41.0-r8.1.5_armv7a.ipk 2/boost-program-options_1.41.0-r8.1.5_armv7a.ipk 2/boost-python_1.41.0-r8.1.5_armv7a.ipk 2/boost-regex_1.41.0-r8.1.5_armv7a.ipk 2/boost-serialization_1.41.0-r8.1.5_armv7a.ipk 2/boost-signals_1.41.0-r8.1.5_armv7a.ipk 2/boost-system_1.41.0-r8.1.5_armv7a.ipk 2/boost-test_1.41.0-r8.1.5_armv7a.ipk 
197   log "Boost library installed"
198   sync
199 fi
200
201 echo "50"
202 echo "# Installing Lua5.1"
203 if [ "`opkg list-installed | grep lua5.1`" ]; then
204   log "Lua5.1 was already installed"
205 else  
206   opkg install 2/lua5.1_5.1.4-r5.5_armv7a.ipk 
207   log "Lua5.1 installed"
208   sync
209 fi
210
211 echo "65"
212 echo "# Installing Evince"
213 if [ "`opkg list-installed | grep evince`" ]; then
214   log "Evince was already installed"
215 else  
216   opkg install 2/libpoppler-glib4_0.12.3-r0.5_armv7a.ipk 2/libpoppler5_0.12.3-r0.5_armv7a.ipk 2/espgs_8.15.3-r1.5_armv7a.ipk 2/poppler-data_0.4.0-r1.5_all.ipk 2/poppler_0.12.3-r0.5_armv7a.ipk 2/libcupsimage_1.4.3-r2.5_armv7a.ipk 2/evince_2.30.0-r0.5_armv7a.ipk
217   log "Evince installed"
218   sync
219 fi
220
221 # MiniMenu Update
222
223 echo "80"
224 echo "# Installing updated MiniMenu"
225
226 update_mmenu()
227 {
228      bad_mmenu=false
229      mmenu_error=false
230      rm /usr/bin/mmenu.old 
231      cp 3/mmenu /usr/bin/mmenu.new 
232      cp 3/mmenu.conf /etc/pandora/conf/mmenu.conf.new 
233         sync
234         currmmenu=$(md5sum /usr/bin/mmenu.new | cut -d" " -f1)
235           if [ $currmmenu = $newmmenu ]; then
236             mv /usr/bin/mmenu /usr/bin/mmenu.old 
237             mv /etc/pandora/conf/mmenu.conf /etc/pandora/conf/mmenu.conf.old 
238             mv /usr/bin/mmenu.new /usr/bin/mmenu 
239             mv /etc/pandora/conf/mmenu.conf.new /etc/pandora/conf/mmenu.conf 
240             currmmenu=$(md5sum /usr/bin/mmenu | cut -d" " -f1)
241             if [ $currmmenu != $newmmenu ]; then
242                rm /usr/bin/mmenu 
243                rm /etc/pandora/conf/mmenu.conf 
244                mv /etc/pandora/conf/mmenu.conf.old /etc/pandora/conf/mmenu.conf 
245                mv /usr/bin/mmenu.old /usr/bin/mmenu 
246                bad_mmenu=true
247             fi
248           else
249             rm /usr/bin/mmenu.new 
250             rm /etc/pandora/conf/mmenu.conf.new 
251             bad_mmenu=true
252           fi
253           if $bad_mmenu; then
254             err "There was a checksum error while copying MiniMenu.\n\nMiniMenu couldn't be updated. Please check your SD-Card and try to recopy the PND-File."
255             log "MiniMenu not updated - checksum error"
256             mmenu_error=true
257           fi    
258      if ! $mmenu_error; then
259        log "MiniMenu successfully updated"
260      fi
261      sync
262 }
263
264
265 mmenu_known=false
266 for ommenu in $oldmmenu $newmmenu; do
267   if [ "$ommenu" = "$currmmenu" ]; then
268     mmenu_known=true
269     break
270   fi
271 done
272
273 if [ "$mmenu_known" = "true" -o -z "$currmmenu" ]; then
274   if [ "$currmmenu" != "$newmmenu" ]; then
275     update_mmenu
276   else
277     log "MiniMenu already up-to-date"
278   fi
279 else
280   if zenity --question --title="Custom MiniMenu?" --text="\
281 You seem to have custom or newer MiniMenu on your OS.\n\n\
282 Update it anyway?\n\
283 (if unsure, select Yes)" --ok-label="Yes" --cancel-label="No" ; then
284     update_mmenu
285   else
286     log "MiniMenu update skipped"
287   fi
288 fi
289
290 # Bugfixes in Scripts
291
292 echo "85"
293 echo "# Installing updated scripts"
294 if [ ! -f /usr/bin/stopmmenu ]; then
295   cp 2/op_calibrate.sh /usr/pandora/scripts/ 
296   cp 2/op_datetime.sh /usr/pandora/scripts/ 
297   cp 2/op_lcdsettings.sh /usr/pandora/scripts/ 
298   cp 2/op_nubmode.sh /usr/pandora/scripts/ 
299   cp 2/op_switchgui.sh /usr/pandora/scripts/ 
300   cp 2/op_usermanager.sh /usr/pandora/scripts/ 
301   cp 2/op_lcdrate.sh /usr/pandora/scripts/ 
302   chmod +x /usr/pandora/scripts/op_lcdrate.sh
303   cp 2/gui.conf /etc/pandora/conf/ 
304   cp 2/op_bluetooth.desktop /usr/share/applications/    
305   cp 2/rc.wl1251 /etc/init.d/wl1251-init 
306   cp 2/interfaces /etc/network/ 
307   cp 2/stopmmenu /usr/bin/stopmmenu 
308   mkdir /usr/pandora/mmenu
309   rm /usr/share/applications/op_wifi.desktop
310   cp 2/abiword.pnd /usr/pandora/mmenu/
311   cp 2/arora.pnd /usr/pandora/mmenu/
312   cp 2/claws-mail.pnd /usr/pandora/mmenu/
313   cp 2/evince.pnd /usr/pandora/mmenu/
314   cp 2/gigolo.pnd /usr/pandora/mmenu/
315   cp 2/gnumeric.pnd /usr/pandora/mmenu/
316   cp 2/midori.pnd /usr/pandora/mmenu/
317   cp 2/mousepad.pnd /usr/pandora/mmenu/
318   cp 2/pidgin.pnd /usr/pandora/mmenu/
319   cp 2/ristretto.pnd /usr/pandora/mmenu/
320   cp 2/squeeze.pnd /usr/pandora/mmenu/
321   cp 2/thunar.pnd /usr/pandora/mmenu/
322   cp 2/xchat.pnd /usr/pandora/mmenu/
323   
324   log "The HotFix 2 scripts have been updated"
325   sync
326   chmod 666 /etc/pointercal 
327   log "Permissions updated"
328 else
329  log "HotFix 2 scripts were already installed."
330 fi
331
332 echo "90"
333 echo "# Installing updated scripts"
334 mountmd5=$(md5sum /usr/pandora/scripts/op_storage.sh | cut -d" " -f1)
335 if [  "23c0cd2ef0197e1a1e512ce48014311e" != "$mountmd5" ]; then
336   update-rc.d -f pandora-lcd-state remove
337   rm /etc/init.d/pandora-lcd-state
338   cp 3/op_bluetooth.sh /usr/pandora/scripts/ 
339   cp 3/rc.pandora-state /etc/init.d/pandora-state
340   cp 3/50_openpandora /etc/sudoers.d/ 
341   cp 3/mount.sh /etc/udev/scripts/mount.sh
342   cp 3/op_startupmanager.sh /usr/pandora/scripts/
343   cp 3/op_storage.sh /usr/pandora/scripts/
344   cp 3/pandorascripts.pnd /usr/pandora/apps/
345   cp 3/dirty_expire_centisecs /etc/pandora/conf/
346   cp 3/service.conf /etc/pandora/conf/
347   cp 3/eventmap /etc/pandora/conf/
348   cp 3/op_runfbapp /usr/bin/
349   cp 3/pnd_run.sh /usr/pandora/scripts/
350   update-rc.d -f pandora-state start 39 S . stop 31 0 1 6 .
351   log "The HotFix 3 scripts have been updated"
352   sync
353 else
354  log "HotFix 3 scripts were already installed."
355 fi
356
357 echo "94"
358 echo "# Installing new Modules"
359 if [ ! -f /lib/modules/2.6.27.46-omap1/kernel/drivers/net/tun.ko  ]; then
360   cp 3/snd-usb-audio.ko /lib/modules/2.6.27.46-omap1/kernel/sound/usb/
361   cp 3/snd-usb-lib.ko /lib/modules/2.6.27.46-omap1/kernel/sound/usb/
362   cp 3/snd-hwdep.ko /lib/modules/2.6.27.46-omap1/kernel/sound/core/
363   cp 3/snd-rawmidi.ko /lib/modules/2.6.27.46-omap1/kernel/sound/core/
364   cp 3/tun.ko /lib/modules/2.6.27.46-omap1/kernel/drivers/net/
365   depmod
366   log "New modules installed"
367   sync
368 else
369  log "All Modules were already installed."
370 fi
371
372 echo "95"
373 echo "# Disabling unneeded services"
374 if [ -f /etc/rc5.d/S20apmd ]; then
375   update-rc.d -f samba remove
376   update-rc.d -f xinetd
377   update-rc.d -f avahi-daemon
378   update-rc.d -f apmd
379   update-rc.d -f usb-gadget
380   update-rc.d -f banner
381   update-rc.d -f portmap
382   update-rc.d -f mountnfs
383   update-rc.d -f blueprobe
384   update-rc.d -f dropbear
385   log "Unneeded services have been disabled"
386   sync
387 else
388   log "Unneeded sevices were already disabled"
389 fi
390
391 echo "100"
392 echo "# Update finished"
393
394 # Zenity Progress goes here
395 ) |
396         zenity --progress \
397           --title="Installing Updates..." \
398           --text="Updating System..." \
399           --percentage=0
400
401 err=`cat /tmp/updater_err.log`
402 if [ -z "$err" ]; then
403   err="Your system has been updated without any errors."
404 fi
405 update=$(cat /tmp/updater.log)
406 zenity --info --title="Update finished" --text "$err\n\n${update}"
407
408 fi
409
410 if [ -f /tmp/updreboot ]; then
411   reboot=`cat /tmp/updreboot`
412   zenity --info --title="You need to reboot" --text "${reboot}"
413   rm /tmp/updreboot
414 fi