pandora-scripts: improve op_osupgrade
[openpandora.oe.git] / recipes / pandora-system / pandora-scripts / op_osupgrade_work.sh
1 #!/bin/sh
2
3 set -e
4 export HOME=/home/root
5 cd /tmp/
6
7 script_path="/usr/pandora/scripts/op_osupgrade_work.sh"
8 script_pkg="pandora-scripts"
9 script_updated_f="/tmp/upgrade_script_updated"
10
11 echo "Updating package lists..."
12 opkg update
13
14 echo "Checking for updated packages..."; \
15
16 # check if this script was updated. If it was, update and restart it
17 if opkg list-upgradable | grep -q "$script_pkg"; then
18   mtime_pre=`stat -c '%Y' $script_path`
19   opkg install $script_pkg
20   mtime_post=`stat -c '%Y' $script_path`
21   if [ "$mtime_pre" != "$mtime_post" -a ! -e "$script_updated_f" ]; then
22     # just in case..
23     touch "$script_updated_f"
24     echo "Update script was updated, restarting.."
25     exec $script_path
26   fi
27 fi
28
29 # check if opkg was updated.. Maybe we can fix it's breakages someday..
30 for o in `opkg list-upgradable | grep opkg | awk '{print $1}'`; do
31   opkg install $o
32   opkg_updated=1
33 done
34
35 if [ "$opkg_updated" = "1" ]; then
36   opkg update
37 fi
38
39 # finally run the upgrade itself
40 opkg upgrade
41
42 # done
43 touch /tmp/upgrade_ok
44 sync
45
46 # do we still need this?
47 echo "Finished, press Ctrl-C to exit"
48
49 exit 0