op_osupgrade: rework update script
[openpandora.oe.git] / recipes / pandora-system / pandora-scripts / op_osupgrade.sh
1 #!/bin/sh
2 kernel_path="/boot/uImage-3"
3
4 zenity --question --title="Update Firmware OS" --text="This little tool helps you to keep your firmware OS up-to-date with the latest tweaks.\n\nPlease note that this is in TESTING state and\nmight break parts of your system with unstable packages!\n\nMake sure your Pandora is connected to the internet and click the Upgrade-Button.\n\n" --ok-label="Upgrade OS" --cancel-label="Quit" || exit 0
5
6 # check free space
7 root_free=`df | grep '/$' | sed -e '2~1d' | awk '{print $4}'`
8 if [ "$root_free" -lt 20000 ]; then
9   zenity --error --text "There is not enough free space left in root partition
10 (at least 20MB is required).
11 This usually means your NAND is almost full.
12
13 Delete some files and try again. Alternatively you can do a full reflash."
14   exit 1
15 fi
16
17 # check for default angstrom feeds
18 if cat /etc/opkg/*.conf | awk -F# '{printf $1}' | grep -q www.angstrom-distribution.org; then
19   zenity --error --text "There seem to be Angstrom feeds in your opkg configs, \
20 upgraging from them is known to make the system unbootable.
21 Aborting."
22   exit 1
23 fi
24
25 rm -f /tmp/upgrade_ok
26 kernelmd5_old=`md5sum $kernel_path`
27
28 # reminder: don't use '&&' '||' ... after tee, it breaks set -e, no idea why
29 terminal -x bash -c \
30   '( set -e; \
31      cd /tmp/; \
32      echo "Updating package lists..."; \
33      opkg update 2>&1; \
34      echo "Checking for updated packages..."; \
35      opkg upgrade 2>&1; \
36      touch /tmp/upgrade_ok; \
37      sync ) | tee /tmp/upgrade.log; \
38    test -e /tmp/upgrade_ok || sleep 3'
39
40 sync
41
42 kernelmd5_new=`md5sum $kernel_path`
43
44 if test -e /tmp/upgrade_ok; then
45   rm -f /tmp/upgrade_ok
46   zenity --info --title="Upgrade complete" \
47     --text "All operations have been finished.\n\nYou can find a logfile at /tmp/upgrade.log"
48   if [ "$kernelmd5_old" != "$kernelmd5_new" ]; then
49     zenity --question --title="Kernel updated" \
50       --text "The kernel has been updated,\nreboot is needed to start it.\n\nReboot now?" \
51       --ok-label="Yes" --cancel-label="No, do it later" \
52       && reboot
53   fi
54 else
55   zenity --error --title="Errors detected" \
56     --text "Errors detected during update.\n\nYou can find a logfile at /tmp/upgrade.log"
57 fi