973518acda50bfeb4aac96388dbc84ee35d35999
[openpandora.oe.git] / recipes / pandora-system / pandora-scripts / op_osupgrade.sh
1 #!/bin/sh
2 work_script_path="/usr/pandora/scripts/op_osupgrade_work.sh"
3 kernel_path="/boot/uImage-3"
4
5 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
6
7 # check free space
8 root_free=`df | grep '/$' | sed -e '2~1d' | awk '{print $4}'`
9 if [ "$root_free" -lt 20000 ]; then
10   zenity --error --text "There is not enough free space left in root partition
11 (at least 20MB is required).
12 This usually means your NAND is almost full.
13
14 Delete some files and try again. Alternatively you can do a full reflash."
15   exit 1
16 fi
17
18 # check for default angstrom feeds
19 if cat /etc/opkg/*.conf | awk -F# '{printf $1}' | grep -q www.angstrom-distribution.org; then
20   zenity --error --text "There seem to be Angstrom feeds in your opkg configs, \
21 upgraging from them is known to make the system unbootable.
22 Aborting."
23   exit 1
24 fi
25
26 rm -f /tmp/upgrade_ok /tmp/upgrade_script_updated
27 kernelmd5_old=`md5sum $kernel_path`
28
29 # reminder: don't use '&&' '||' ... after tee, it breaks set -e, no idea why
30 terminal -x bash -c \
31   "( $work_script_path || ( echo && echo "Retrying.." && $work_script_path ) ) 2>&1 \
32        | tee /tmp/upgrade.log; \
33    test -e /tmp/upgrade_ok || sleep 3"
34
35 kernelmd5_new=`md5sum $kernel_path`
36
37 if test -e /tmp/upgrade_ok; then
38   rm -f /tmp/upgrade_ok
39   zenity --info --title="Upgrade complete" \
40     --text "All operations have been finished.\n\nYou can find a log file at /tmp/upgrade.log"
41   if [ "$kernelmd5_old" != "$kernelmd5_new" ]; then
42     zenity --question --title="Kernel updated" \
43       --text "The kernel has been updated,\nreboot is needed to start it.\n\nReboot now?" \
44       --ok-label="Yes" --cancel-label="No, do it later" \
45       && reboot
46   fi
47 else
48   zenity --error --title="Errors detected" \
49     --text "Errors detected during update. Please check your Internet connection and try again.
50
51 If long update process was interrupted, it is recommended to run the update again before a reboot.
52
53 You can find a log file at /tmp/upgrade.log"
54 fi