--- /dev/null
+#!/bin/sh
+
+set -e
+export HOME=/home/root
+cd /tmp/
+
+script_path="/usr/pandora/scripts/op_osupgrade_work.sh"
+script_pkg="pandora-scripts"
+script_updated_f="/tmp/upgrade_script_updated"
+
+echo "Updating package lists..."
+opkg update
+
+echo "Checking for updated packages..."; \
+
+# check if this script was updated. If it was, update and restart it
+if opkg list-upgradable | grep -q "$script_pkg"; then
+ mtime_pre=`stat -c '%Y' $script_path`
+ opkg install $script_pkg
+ mtime_post=`stat -c '%Y' $script_path`
+ if [ "$mtime_pre" != "$mtime_post" -a ! -e "$script_updated_f" ]; then
+ # just in case..
+ touch "$script_updated_f"
+ echo "Update script was updated, restarting.."
+ exec $script_path
+ fi
+fi
+
+# check if opkg was updated.. Maybe we can fix it's breakages someday..
+for o in `opkg list-upgradable | grep opkg | awk '{print $1}'`; do
+ opkg install $o
+ opkg_updated=1
+done
+
+if [ "$opkg_updated" = "1" ]; then
+ opkg update
+fi
+
+# finally run the upgrade itself
+opkg upgrade
+
+# done
+touch /tmp/upgrade_ok
+sync
+
+# do we still need this?
+echo "Finished, press Ctrl-C to exit"
+
+exit 0