diff options
Diffstat (limited to 'utils/mknwzboot/install_script.sh')
-rw-r--r-- | utils/mknwzboot/install_script.sh | 157 |
1 files changed, 157 insertions, 0 deletions
diff --git a/utils/mknwzboot/install_script.sh b/utils/mknwzboot/install_script.sh new file mode 100644 index 0000000000..76bd12c4d5 --- /dev/null +++ b/utils/mknwzboot/install_script.sh | |||
@@ -0,0 +1,157 @@ | |||
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/install_dualboot_log.txt" 2>&1 | ||
46 | |||
47 | # import constants | ||
48 | . /install_script/constant.txt | ||
49 | _UPDATE_FN_=`nvpstr ufn` | ||
50 | ROOTFS_TMP_DIR=/tmp/rootfs | ||
51 | SPIDERAPP_PATH=$ROOTFS_TMP_DIR/usr/local/bin/SpiderApp | ||
52 | |||
53 | # mount root partition | ||
54 | lcdprint 0,7 "Mount root filesystem" | ||
55 | mkdir $ROOTFS_TMP_DIR | ||
56 | if [ "$?" != 0 ]; then | ||
57 | lcdprint 0,15 "ERROR: mkdir failed" | ||
58 | sleep 3 | ||
59 | exit 0 | ||
60 | fi | ||
61 | |||
62 | # If there is an ext4 mounter, try it. Otherwise or on failure, try ext3 and | ||
63 | # then ext2. | ||
64 | # NOTE some platforms probably use an mtd and this might need some fixing | ||
65 | if [ -e /usr/local/bin/icx_mount.ext4 ]; then | ||
66 | /usr/local/bin/icx_mount.ext4 $COMMON_ROOTFS_PARTITION $ROOTFS_TMP_DIR | ||
67 | else | ||
68 | false | ||
69 | fi | ||
70 | if [ "$?" != 0 ]; then | ||
71 | mount -t ext3 $COMMON_ROOTFS_PARTITION $ROOTFS_TMP_DIR | ||
72 | fi | ||
73 | if [ "$?" != 0 ]; then | ||
74 | mount -t ext2 $COMMON_ROOTFS_PARTITION $ROOTFS_TMP_DIR | ||
75 | fi | ||
76 | if [ "$?" != 0 ]; then | ||
77 | lcdprint 0,15 "ERROR: mount failed" | ||
78 | sleep 3 | ||
79 | exit 0 | ||
80 | fi | ||
81 | |||
82 | # rename the previous main application unless there is already a copy | ||
83 | lcdprint 0,8 "Backup OF" | ||
84 | if [ ! -e $SPIDERAPP_PATH.of ]; then | ||
85 | mv $SPIDERAPP_PATH $SPIDERAPP_PATH.of | ||
86 | fi | ||
87 | |||
88 | # extract our payload: the second file in the upgrade is a tar file | ||
89 | # the files in the archive have paths of the form ./absolute/path and we extract | ||
90 | # it at the rootfs mount it, so it can create/overwrite any file | ||
91 | # | ||
92 | # we need a small trick here: we want to pipe directly the output of the decryption | ||
93 | # tool to tar, to avoid using space in /tmp/ or on the user partition | ||
94 | lcdprint 0,9 "Install rockbox" | ||
95 | FIFO_FILE=/tmp/rb.fifo | ||
96 | mkfifo $FIFO_FILE | ||
97 | if [ "$?" != 0 ]; then | ||
98 | umount "$ROOTFS_TMP_DIR" | ||
99 | lcdprint 0,15 "ERROR: cannot create fifo" | ||
100 | sleep 3 | ||
101 | exit 0 | ||
102 | fi | ||
103 | fwpchk -f /contents/$_UPDATE_FN_.UPG -c -1 $FIFO_FILE & | ||
104 | #tar -tvf $FIFO_FILE | ||
105 | tar -C $ROOTFS_TMP_DIR -xvf $FIFO_FILE | ||
106 | if [ "$?" != 0 ]; then | ||
107 | umount "$ROOTFS_TMP_DIR" | ||
108 | lcdprint 0,15 "ERROR: extraction failed" | ||
109 | sleep 3 | ||
110 | exit 0 | ||
111 | fi | ||
112 | # wait for fwpchk | ||
113 | wait | ||
114 | if [ "$?" != 0 ]; then | ||
115 | umount "$ROOTFS_TMP_DIR" | ||
116 | lcdprint 0,15 "ERROR: no file to extract" | ||
117 | sleep 3 | ||
118 | exit 0 | ||
119 | fi | ||
120 | |||
121 | # create a symlink from /.rockbox to /contents/.rockbox (see dualboot code | ||
122 | # for why) | ||
123 | lcdprint 0,10 "Create rockbox symlink" | ||
124 | rm -f "$ROOTFS_TMP_DIR/.rockbox" | ||
125 | ln -s "$CONTENTS/.rockbox" "$ROOTFS_TMP_DIR/.rockbox" | ||
126 | if [ "$?" != 0 ]; then | ||
127 | umount "$ROOTFS_TMP_DIR" | ||
128 | lcdprint 0,15 "ERROR: cannot create rockbox symlink" | ||
129 | sleep 3 | ||
130 | exit 0 | ||
131 | fi | ||
132 | |||
133 | # unmount root partition | ||
134 | lcdprint 0,11 "Unmount root filesystem" | ||
135 | sync | ||
136 | if [ "$?" != 0 ]; then | ||
137 | umount "$ROOTFS_TMP_DIR" | ||
138 | lcdprint 0,15 "ERROR: sync failed" | ||
139 | sleep 3 | ||
140 | exit 0 | ||
141 | fi | ||
142 | |||
143 | umount $ROOTFS_TMP_DIR | ||
144 | if [ "$?" != 0 ]; then | ||
145 | lcdprint 0,15 "ERROR: umount failed" | ||
146 | sleep 3 | ||
147 | exit 0 | ||
148 | fi | ||
149 | |||
150 | # Success screen | ||
151 | lcdprint 0,15 "Rebooting in 3 seconds." | ||
152 | sleep 3 | ||
153 | sync | ||
154 | |||
155 | echo "Installation successful" | ||
156 | # finish | ||
157 | exit 0 | ||