diff options
Diffstat (limited to 'utils/mknwzboot/uninstall_script.sh')
-rw-r--r-- | utils/mknwzboot/uninstall_script.sh | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/utils/mknwzboot/uninstall_script.sh b/utils/mknwzboot/uninstall_script.sh new file mode 100644 index 0000000000..0e409c63cd --- /dev/null +++ b/utils/mknwzboot/uninstall_script.sh | |||
@@ -0,0 +1,122 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | # NOTE: busybox is using ash, a very posix and very pedantic shell, make sure | ||
4 | # you test your scripts with | ||
5 | # busybox sh -n <script> | ||
6 | # and if you really, really don't want to download busybox to try it, then go | ||
7 | # ahead and brick your device | ||
8 | |||
9 | # The updater script on the NWZ has a major bug/feature: | ||
10 | # it does NOT clear the update flag if the update scrit fails | ||
11 | # thus causing a update/reboot loop and a bricked device | ||
12 | # always clear to make sure we don't end up being screwed | ||
13 | nvpflag fup 0xFFFFFFFF | ||
14 | |||
15 | # go to /tmp | ||
16 | cd /tmp | ||
17 | |||
18 | # get content partition path | ||
19 | CONTENTS="/contents" | ||
20 | CONTENTS_PART=`mount | grep contents | awk '{ print $1 }'` | ||
21 | |||
22 | # print a message to the screen and also on the standard output | ||
23 | # lcdprint x,y msg | ||
24 | lcdprint () | ||
25 | { | ||
26 | echo $2 | ||
27 | lcdmsg -f /usr/local/bin/font_08x12.bmp -l $1 "$2" | ||
28 | } | ||
29 | |||
30 | # clear screen | ||
31 | lcdmsg -c "" | ||
32 | lcdprint 0,3 "Contents partition:\n$CONTENTS_PART" | ||
33 | |||
34 | # We need to remount the contents partition in read-write mode be able to | ||
35 | # write something on it | ||
36 | lcdprint 0,6 "Remount $CONTENTS rw" | ||
37 | mount -o remount,rw $CONTENTS_PART $CONTENTS | ||
38 | if [ "$?" != 0 ]; then | ||
39 | lcdprint 0,15 "ERROR: remount failed" | ||
40 | sleep 3 | ||
41 | exit 0 | ||
42 | fi | ||
43 | |||
44 | # redirect all output to a log file | ||
45 | exec > "$CONTENTS/uninstall_dualboot_log.txt" 2>&1 | ||
46 | |||
47 | # import constants | ||
48 | . /install_script/constant.txt | ||
49 | ROOTFS_TMP_DIR=/tmp/rootfs | ||
50 | SPIDERAPP_PATH=$ROOTFS_TMP_DIR/usr/local/bin/SpiderApp | ||
51 | |||
52 | # mount root partition | ||
53 | lcdprint 0,7 "Mount root filesystem" | ||
54 | mkdir $ROOTFS_TMP_DIR | ||
55 | if [ "$?" != 0 ]; then | ||
56 | lcdprint 0,15 "ERROR: mkdir failed" | ||
57 | sleep 3 | ||
58 | exit 0 | ||
59 | fi | ||
60 | |||
61 | # If there is an ext4 mounter, try it. Otherwise or on failure, try ext3 and | ||
62 | # then ext2. | ||
63 | # NOTE some platforms probably use an mtd and this might need some fixing | ||
64 | if [ -e /usr/local/bin/icx_mount.ext4 ]; then | ||
65 | /usr/local/bin/icx_mount.ext4 $COMMON_ROOTFS_PARTITION $ROOTFS_TMP_DIR | ||
66 | else | ||
67 | false | ||
68 | fi | ||
69 | if [ "$?" != 0 ]; then | ||
70 | mount -t ext3 $COMMON_ROOTFS_PARTITION $ROOTFS_TMP_DIR | ||
71 | fi | ||
72 | if [ "$?" != 0 ]; then | ||
73 | mount -t ext2 $COMMON_ROOTFS_PARTITION $ROOTFS_TMP_DIR | ||
74 | fi | ||
75 | if [ "$?" != 0 ]; then | ||
76 | lcdprint 0,15 "ERROR: mount failed" | ||
77 | sleep 3 | ||
78 | exit 0 | ||
79 | fi | ||
80 | |||
81 | # the installer renames the OF to $SPIDERAPP_PATH.of so if it does not exists | ||
82 | # print an error | ||
83 | lcdprint 0,8 "Restore OF" | ||
84 | if [ ! -e $SPIDERAPP_PATH.of ]; then | ||
85 | lcdprint 0,15 "ERROR: cannot find OF" | ||
86 | lcdprint 0,16 "ERROR: is Rockbox installed?" | ||
87 | sleep 3 | ||
88 | exit 0 | ||
89 | fi | ||
90 | # restore the OF | ||
91 | mv $SPIDERAPP_PATH.of $SPIDERAPP_PATH | ||
92 | if [ "$?" != 0 ]; then | ||
93 | lcdprint 0,15 "ERROR: restore failed" | ||
94 | sleep 3 | ||
95 | exit 0 | ||
96 | fi | ||
97 | |||
98 | # unmount root partition | ||
99 | lcdprint 0,11 "Unmount root filesystem" | ||
100 | sync | ||
101 | if [ "$?" != 0 ]; then | ||
102 | umount "$ROOTFS_TMP_DIR" | ||
103 | lcdprint 0,15 "ERROR: sync failed" | ||
104 | sleep 3 | ||
105 | exit 0 | ||
106 | fi | ||
107 | |||
108 | umount $ROOTFS_TMP_DIR | ||
109 | if [ "$?" != 0 ]; then | ||
110 | lcdprint 0,15 "ERROR: umount failed" | ||
111 | sleep 3 | ||
112 | exit 0 | ||
113 | fi | ||
114 | |||
115 | # Success screen | ||
116 | lcdprint 0,15 "Rebooting in 3 seconds." | ||
117 | sleep 3 | ||
118 | sync | ||
119 | |||
120 | echo "Uninstallation successful" | ||
121 | # finish | ||
122 | exit 0 | ||