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